# Path: Experimenter/SpikeData/TimeHistogram.py
# class PSTHTuning(PlexSpikeData):
# class PSTHAverage(PlexSpikeData):
#     ORI_MASK = 0xF<<0
#     SPF_MASK = 0xF<<4
#     PHA_MASK = 0xF<<8
#     ONSET_MASK = 1<<12
#     MONO_MASK = 3<<12
#     MONO_LEFT_MASK = 3<<12 | ORI_MASK
#     MONO_RIGHT_MASK = 3<<12 | SPF_MASK
#     ONSET_MASK = 1<<12
#     def __init__(self, *args,**kwargs):
#     def renew_data(self):
#     def get_data(self,callback=None):
#     def _update_data(self,callback=None):
#     def _get_psth_data(self):
#     def _process_psth_data(self,begin,end,param_index):
#     def __init__(self, *args,**kwargs):
#     def renew_data(self):
#     def get_data(self,callback=None):
#     def _update_data(self,callback=None):
#     def _get_psth_data(self):
#     def _process_unit(self,channel,unit):


import wx
import threading
import Pyro.core
import numpy as np
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
from ..SpikeData import TimeHistogram
from Base import UpdateDataThread,UpdateFileDataThread
from Base import MainFrame,DataPanel,RCPanel,adjust_spines
            #self.curve_axes.set_ylim(0,100)
            self.curve_axes.relim()
            self.curve_axes.autoscale_view(scalex=False, scaley=True)
            
        self.fig.canvas.draw()
    
    def on_update_data_timer(self, _event):
        if self.collecting_data and self.connected_to_server:
            self.update_data_thread = UpdateDataThread(self, self.psth_data)
            self.update_data_thread.start()
        
    def start_data(self):
        if self.psth_data is None:
            self.psth_data = TimeHistogram.PSTHAverage()
        self.collecting_data = True
        self.connected_to_server = True
    
    def stop_data(self):
        self.collecting_data = False
        self.clear_data()
        self.psth_data = None
        
    def restart_data(self):
        self.stop_data()
        self.start_data()
    
    def smooth_curve(self, checked):
        pass
    
    def open_file(self, path, callback=None):

# Path: Experimenter/SpikeData/TimeHistogram.py
# class PSTHTuning(PlexSpikeData):
# class PSTHAverage(PlexSpikeData):
#     ORI_MASK = 0xF<<0
#     SPF_MASK = 0xF<<4
#     PHA_MASK = 0xF<<8
#     ONSET_MASK = 1<<12
#     MONO_MASK = 3<<12
#     MONO_LEFT_MASK = 3<<12 | ORI_MASK
#     MONO_RIGHT_MASK = 3<<12 | SPF_MASK
#     ONSET_MASK = 1<<12
#     def __init__(self, *args,**kwargs):
#     def renew_data(self):
#     def get_data(self,callback=None):
#     def _update_data(self,callback=None):
#     def _get_psth_data(self):
#     def _process_psth_data(self,begin,end,param_index):
#     def __init__(self, *args,**kwargs):
#     def renew_data(self):
#     def get_data(self,callback=None):
#     def _update_data(self,callback=None):
#     def _get_psth_data(self):
#     def _process_unit(self,channel,unit):


# Path: Experimenter/GUI/PSTHAverage.py
import wx
import threading
import Pyro.core
import numpy as np
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
from ..SpikeData import TimeHistogram
from Base import UpdateDataThread,UpdateFileDataThread
from Base import MainFrame,DataPanel,RCPanel,adjust_spines

            #self.curve_axes.set_ylim(0,100)
            self.curve_axes.relim()
            self.curve_axes.autoscale_view(scalex=False, scaley=True)
            
        self.fig.canvas.draw()
    
    def on_update_data_timer(self, _event):
        if self.collecting_data and self.connected_to_server:
            self.update_data_thread = UpdateDataThread(self, self.psth_data)
            self.update_data_thread.start()
        
    def start_data(self):
        if self.psth_data is None:
            self.psth_data = TimeHistogram.PSTHAverage()
        self.collecting_data = True
        self.connected_to_server = True
    
    def stop_data(self):
        self.collecting_data = False
        self.clear_data()
        self.psth_data = None
        
    def restart_data(self):
        self.stop_data()
        self.start_data()
    
    def smooth_curve(self, checked):
        pass
    
    def open_file(self, path, callback=None):

        self.psth_data = TimeHistogram.PSTHAverage(path)