def onTimer(self, event): ''' Main timer for processing messages from modules and updating running time on the main window ''' if DEBUG: print('CATOSFrame.onTimer()') ### processing message msg_src, msg_body, msg_details = chk_msg_q(self.msg_q) ### update log file path, if necessary lfd = path.basename(self.log_file_path)[-6:-4] # date of the current # log file name _d = '%.2i' % (datetime.now().day) # current date if lfd != _d: # reset the log file path self.log_file_path = get_log_file_path(self.output_folder) ### update several running time e_time = time() - self.program_start_time self.sTxt_pr_time.SetLabel( str(timedelta(seconds=e_time)).split('.')[0]) if self.session_start_time != -1: e_time = time() - self.session_start_time self.sTxt_s_time.SetLabel( str(timedelta(seconds=e_time)).split('.')[0]) if self.last_play_time != -1: e_time = time() - self.last_play_time self.sTxt_time.SetLabel( str(timedelta(seconds=e_time)).split('.')[0])
def onTimer(self, event): ''' Main timer for processing messages from modules and updating running time on the main window ''' ### processing message msg_src, msg_body, msg_details = chk_msg_q(self.msg_q) ### update log file path, if necessary lfd = path.basename(self.log_file_path)[-6:-4] # date of the current log file name _d = '%.2i'%(datetime.now().day) # current date if lfd != _d: self.log_file_path = get_log_file_path(self.output_folder) # reset the log file path ### update several running time e_time = time() - self.program_start_time self.sTxt_pr_time.SetLabel( str(timedelta(seconds=e_time)).split('.')[0] ) if self.session_start_time != -1: e_time = time() - self.session_start_time self.sTxt_s_time.SetLabel( str(timedelta(seconds=e_time)).split('.')[0] ) if self.last_play_time != -1: e_time = time() - self.last_play_time self.sTxt_time.SetLabel( str(timedelta(seconds=e_time)).split('.')[0] )
def __init__(self): ### output folder check output_folder = path.join(CWD, 'output') if path.isdir(output_folder) == False: mkdir(output_folder) self.output_folder = output_folder ### opening log file self.log = "" self.log_file_path = get_log_file_path(output_folder) writeFile(self.log_file_path, '%s, [CATOS], Begining of the program\n'%(get_time_stamp())) ### init variables self.mods = dict(arduino=None, videoIn=[], feeder_videoIn=[], videoOut=None, audioOut=None, session_mngr=None) self.program_start_time = time() self.session_start_time = -1 self.last_play_time = -1 # last stimulus play time self.cam_idx = [0] # webcam indices self.cam_idx_feeder = [] # webcam index for the feeder self.cam_view_pos = [wx.GetDisplaySize()[0]-1200, 30] # position of webcam view checking windows print self.cam_view_pos self.msg_q = Queue.Queue() #self.feeder_phase = -1 # 0 : running two conveyors, 1: running the bottom conveyors, 2: sweep of servor motor, 3: ready to dispense self.w_size = (400, 300) wx.Frame.__init__(self, None, -1, 'CATOS', size=self.w_size) # init frame self.SetPosition( (wx.GetDisplaySize()[0]-self.w_size[0]-1200, 30) ) self.Show(True) self.panel = wx.Panel(self, pos=(0,0), size=self.w_size) self.panel.SetBackgroundColour('#000000') ### user interface setup posX = 5 posY = 10 btn_width = 150 b_space = 30 self.btn_cam = wx.Button(self.panel, -1, label='Check webcam views', pos=(posX,posY), size=(btn_width, -1)) self.btn_cam.Bind(wx.EVT_LEFT_UP, self.onChkWebcamView) posY += b_space self.btn_session = wx.Button(self.panel, -1, label='Start session', pos=(posX,posY), size=(btn_width, -1)) self.btn_session.Bind(wx.EVT_LEFT_UP, self.onStartStopSession) posY += b_space self.btn_trial = wx.Button(self.panel, -1, label='Start trial', pos=(posX,posY), size=(btn_width, -1)) self.btn_trial.Bind(wx.EVT_LEFT_UP, self.onStartTrial) posY += b_space + 10 _stxt = wx.StaticText(self.panel, -1, label="Leave a note in LOG file", pos=(posX+5,posY)) _stxt.SetForegroundColour('#CCCCCC') posY += 20 self.txt_notes = wx.TextCtrl(self.panel, -1, name='txt_notes', pos=(posX+5,posY), size=(btn_width,-1), style=wx.TE_PROCESS_ENTER) self.txt_notes.Bind(wx.EVT_TEXT_ENTER, self.onEnterInTextCtrl) posY += b_space + 10 _stxt = wx.StaticText(self.panel, -1, label="Send a direct command to Arduino", pos=(posX+5,posY)) _stxt.SetForegroundColour('#CCCCCC') posY += 20 self.txt_arduino = wx.TextCtrl(self.panel, -1, name='txt_arduino', pos=(posX+5,posY), size=(btn_width,-1), style=wx.TE_PROCESS_ENTER) self.txt_arduino.Bind(wx.EVT_TEXT_ENTER, self.onEnterInTextCtrl) posY += b_space + 10 self.btn_quit = wx.Button(self.panel, -1, label='QUIT', pos=(posX,posY), size=(btn_width, -1)) self.btn_quit.Bind(wx.EVT_LEFT_UP, self.onClose) posX = 170 posY = 15 self.sTxt_pr_time = wx.StaticText(self.panel, -1, label='0:00:00', pos=(posX, posY)) # time since program starts _x = self.sTxt_pr_time.GetPosition()[0] + self.sTxt_pr_time.GetSize()[0] + 15 _stxt = wx.StaticText(self.panel, -1, label='since program started', pos=(_x, posY)) _stxt.SetForegroundColour('#CCCCCC') self.font = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.NORMAL) self.sTxt_pr_time.SetFont(self.font) self.sTxt_pr_time.SetBackgroundColour('#000000') self.sTxt_pr_time.SetForegroundColour('#00FF00') posY += b_space self.sTxt_s_time = wx.StaticText(self.panel, -1, label='0:00:00', pos=(posX, posY)) # time since session starts _x = self.sTxt_s_time.GetPosition()[0] + self.sTxt_s_time.GetSize()[0] + 15 _stxt = wx.StaticText(self.panel, -1, label='since session started', pos=(_x, posY)) _stxt.SetForegroundColour('#CCCCCC') self.sTxt_s_time.SetFont(self.font) self.sTxt_s_time.SetBackgroundColour('#000000') self.sTxt_s_time.SetForegroundColour('#CCCCFF') posY += b_space self.sTxt_time = wx.StaticText(self.panel, -1, label='0:00:00', pos=(posX, posY)) _x = self.sTxt_time.GetPosition()[0] + self.sTxt_time.GetSize()[0] + 15 _stxt = wx.StaticText(self.panel, -1, label='since last stimulus', pos=(_x, posY)) _stxt.SetForegroundColour('#CCCCCC') self.sTxt_time.SetFont(self.font) self.sTxt_time.SetBackgroundColour('#000000') self.sTxt_time.SetForegroundColour('#FFFF00') statbar = wx.StatusBar(self, -1) self.SetStatusBar(statbar) ### keyboard binding quit_btnId = wx.NewId() playStim_btnId = wx.NewId() self.Bind(wx.EVT_MENU, self.onClose, id=quit_btnId) accel_tbl = wx.AcceleratorTable([ (wx.ACCEL_CTRL, ord('Q'), quit_btnId) ]) self.SetAcceleratorTable(accel_tbl) ### set timer for processing message and updating the current running time self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.onTimer, self.timer) self.timer.Start(100) #wx.FutureCall(100, self.init_timers) # init other timers self.Bind( wx.EVT_CLOSE, self.onClose ) if flag_arduino == True: self.start_arduino()
def __init__(self): if DEBUG: print('CATOSFrame.__init__()') ##### [begin] setting up attributes ----- ### output folder check output_folder = path.join(CWD, 'output') if path.isdir(output_folder) == False: mkdir(output_folder) self.output_folder = output_folder # output folder # determine log file path self.log_file_path = get_log_file_path(output_folder) # audio file to load self.audio_files = ['input/snd_fly.wav', 'input/pos_fb.wav'] self.w_size = (400, 300) # window size self.font = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.NORMAL) # init dict to contain necessary modules self.mods = dict( arduino=None, videoIn=[], feeder_videoIn=[], # when feeder uses a cam videoOut=None, audioOut=None, session_mngr=None) self.program_start_time = time() self.session_start_time = -1 self.last_play_time = -1 # last stimulus play time self.cam_idx = [0] #[0,1,2] # webcam indices # [[TEMP]] using one # webcam for testing self.cam_idx_feeder = [] # webcam index for the feeder self.cam_view_pos = [ 50 + self.w_size[0], wx.GetDisplaySize()[1] - 350 ] # position of # webcam view checking windows self.msg_q = Queue() ##### [end] setting up attributes ----- # init frame wx.Frame.__init__(self, None, -1, 'CATOS', size=self.w_size) self.SetPosition((50, wx.GetDisplaySize()[1] - self.w_size[1])) self.Show(True) self.panel = wx.Panel(self, pos=(0, 0), size=self.w_size) self.panel.SetBackgroundColour('#000000') ##### [begin] user interface setup ----- posX = 5 posY = 10 btn_width = 150 b_space = 30 self.btn_cam = wx.Button(self.panel, -1, label='Check webcam views', pos=(posX, posY), size=(btn_width, -1)) self.btn_cam.Bind(wx.EVT_LEFT_UP, self.onChkWebcamView) posY += b_space self.btn_session = wx.Button(self.panel, -1, label='Start session', pos=(posX, posY), size=(btn_width, -1)) self.btn_session.Bind(wx.EVT_LEFT_UP, self.onStartStopSession) posY += b_space self.btn_trial = wx.Button(self.panel, -1, label='Start trial', pos=(posX, posY), size=(btn_width, -1)) self.btn_trial.Bind(wx.EVT_LEFT_UP, self.onStartTrial) posY += b_space + 10 _stxt = wx.StaticText(self.panel, -1, label="Leave a note in LOG file", pos=(posX + 5, posY)) _stxt.SetForegroundColour('#CCCCCC') posY += 20 self.txt_notes = wx.TextCtrl(self.panel, -1, name='txt_notes', pos=(posX + 5, posY), size=(btn_width, -1), style=wx.TE_PROCESS_ENTER) self.txt_notes.Bind(wx.EVT_TEXT_ENTER, self.onEnterInTextCtrl) posY += b_space + 10 _stxt = wx.StaticText(self.panel, -1, label="Send a direct command to Arduino", pos=(posX + 5, posY)) _stxt.SetForegroundColour('#CCCCCC') posY += 20 self.txt_arduino = wx.TextCtrl(self.panel, -1, name='txt_arduino', pos=(posX + 5, posY), size=(btn_width, -1), style=wx.TE_PROCESS_ENTER) self.txt_arduino.Bind(wx.EVT_TEXT_ENTER, self.onEnterInTextCtrl) posY += b_space + 10 self.btn_quit = wx.Button(self.panel, -1, label='QUIT', pos=(posX, posY), size=(btn_width, -1)) self.btn_quit.Bind(wx.EVT_LEFT_UP, self.onClose) posX = 170 posY = 15 # time since program-start self.sTxt_pr_time = wx.StaticText(self.panel, -1, label='0:00:00', pos=(posX, posY)) _x = self.sTxt_pr_time.GetPosition()[0] + \ self.sTxt_pr_time.GetSize()[0] + 15 _stxt = wx.StaticText(self.panel, -1, label='since program started', pos=(_x, posY)) _stxt.SetForegroundColour('#CCCCCC') self.sTxt_pr_time.SetFont(self.font) self.sTxt_pr_time.SetBackgroundColour('#000000') self.sTxt_pr_time.SetForegroundColour('#00FF00') posY += b_space # time since session-start self.sTxt_s_time = wx.StaticText(self.panel, -1, label='0:00:00', pos=(posX, posY)) _x = self.sTxt_s_time.GetPosition()[0] + \ self.sTxt_s_time.GetSize()[0] + 15 _stxt = wx.StaticText(self.panel, -1, label='since session started', pos=(_x, posY)) _stxt.SetForegroundColour('#CCCCCC') self.sTxt_s_time.SetFont(self.font) self.sTxt_s_time.SetBackgroundColour('#000000') self.sTxt_s_time.SetForegroundColour('#CCCCFF') posY += b_space self.sTxt_time = wx.StaticText(self.panel, -1, label='0:00:00', pos=(posX, posY)) _x = self.sTxt_time.GetPosition()[0] + \ self.sTxt_time.GetSize()[0] + 15 _stxt = wx.StaticText(self.panel, -1, label='since last stimulus', pos=(_x, posY)) _stxt.SetForegroundColour('#CCCCCC') self.sTxt_time.SetFont(self.font) self.sTxt_time.SetBackgroundColour('#000000') self.sTxt_time.SetForegroundColour('#FFFF00') statbar = wx.StatusBar(self, -1) self.SetStatusBar(statbar) ##### [end] user interface setup ----- ### keyboard binding quit_btnId = wx.NewIdRef(count=1) session_btnId = wx.NewIdRef(count=1) note_btnId = wx.NewIdRef(count=1) self.Bind(wx.EVT_MENU, self.onClose, id=quit_btnId) self.Bind(wx.EVT_MENU, self.onStartStopSession, id=session_btnId) self.Bind(wx.EVT_MENU, self.onEnterNote, id=note_btnId) accel_tbl = wx.AcceleratorTable([ (wx.ACCEL_CTRL, ord('S'), session_btnId), (wx.ACCEL_CTRL, ord('N'), note_btnId), (wx.ACCEL_CTRL, ord('Q'), quit_btnId) ]) self.SetAcceleratorTable(accel_tbl) ### set timer for processing message and ### updating the current running time self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.onTimer, self.timer) self.timer.Start(100) if flagMods["arduino"]: self.start_arduino() self.txt_notes.SetFocus() self.Bind(wx.EVT_CLOSE, self.onClose) writeFile( self.log_file_path, "%s, [CATOS], Begining of the program\n" % (get_time_stamp()))