def refreshThumbGrid(self): # -------------------------------------- Make array of thumbnails to populate the grid oldMonID = gbl.mon_ID try: # ------ don't know if thumbnails or consoles are showing self.clearThumbGrid() except: pass try: # ------ don't know if thumbnails or consoles are showing self.clearConsoleGrid() except: pass # --------------------------------------------- go through each monitor configuration and make a thumbnail panel for gbl.mon_ID in range(1, gbl.monitors + 1): cfg.mon_dict_to_nicknames() # create thread with thumbnail panel and add to grid self.thumbPanels.append(videoThread(VM.monitorPanel(self, mon_ID=gbl.mon_ID, panelType='thumb', loop=True), ###### checks out 1, 2, 3 gbl.mon_name)) interval = self.thumbPanels[gbl.mon_ID].monitorPanel.interval self.thumbPanels[gbl.mon_ID].start() self.thumbPanels[gbl.mon_ID].monitorPanel.playTimer.Start(interval) self.thumbGridSizer.Add(self.thumbPanels[gbl.mon_ID].monitorPanel, 1, wx.ALIGN_CENTER_HORIZONTAL, 5) gbl.timersStarted.append([gbl.mon_ID, 'thumb panel']) ###### debug self.SetSizerAndFit(self.thumbGridSizer) self.Layout() # rearranges thumbnails into grid # setscrollbars has no effect here gbl.mon_ID = oldMonID # go back to same page we came from if gbl.mon_ID != 0: cfg.mon_dict_to_nicknames()
def refreshGrid(self, panelType='thumb'): oldMonID = gbl.mon_ID if panelType == 'thumb': self.Parent.thumbFPSTxt.Show() self.Parent.thumbFPS.Show( ) # restore these if they were hidden (not used for viewing consoles) self.thumbPanels = ['thumb panels' ] # fill element 0 so monitors are 1-indexed # --------------------------------------------- go through each monitor configuration and make a thumbnail panel for gbl.mon_ID in range(1, gbl.monitors + 1): cfg.mon_dict_to_nicknames() if panelType == 'thumb': # 'preview' will never be used in the grid # create thread with thumbnail panel and add to grid self.thumbPanels.append( videoThread( VM.monitorPanel(self, mon_ID=gbl.mon_ID, panelType='thumb', loop=True), (gbl.mon_name))) self.thumbGridSizer.Add( self.thumbPanels[gbl.mon_ID].monitorPanel, 1, wx.ALIGN_CENTER_HORIZONTAL, 5) self.thumbPanels[gbl.mon_ID].start( ) # start the thread (before starting timer) interval = self.thumbPanels[gbl.mon_ID].monitorPanel.interval if not self.thumbPanels[ gbl.mon_ID].monitorPanel.playTimer.IsRunning(): self.thumbPanels[gbl.mon_ID].monitorPanel.playTimer.Start( interval) # start the timer elif panelType == 'console': self.thumbPanels.append( trackingThread( track.monitorPanel(self, mon_ID=gbl.mon_ID, videoOn=False), (gbl.mon_name))) self.thumbGridSizer.Add( self.thumbPanels[gbl.mon_ID].monitorPanel.console, 1, wx.ALIGN_CENTER_HORIZONTAL, 5) self.thumbPanels[ gbl.mon_ID].start() # start the thread; no timer needed self.SetSizerAndFit(self.thumbGridSizer) self.Parent.Layout() # rearranges thumbnails into grid # must use Parent to get display numbers in the right place gbl.mon_ID = oldMonID # go back to same page we came from if gbl.mon_ID != 0: cfg.mon_dict_to_nicknames( ) # restore nicknames to current monitor values
def refreshVideo(self): self.clearVideo() self.previewPanel = VM.monitorPanel( self, mon_ID=self.mon_ID, panelType='preview', loop=True) # make new monitor panel self.previewPanel.PlayMonitor() self.videoSizer.Add(self.previewPanel, 1, wx.ALL | wx.ALIGN_CENTER, 5) self.previewPanel.playTimer.Start(1000 / float(self.previewFPS.GetValue())) gbl.numberOfTimers = gbl.numberOfTimers + 1 self.videoSizer.SetMinSize(self.previewPanel.size) self.SetSizer(self.mainSizer) self.Layout() gbl.timersStarted.append([self.mon_ID, 'preview panel']) ###### debug
def widgets(self): # TODO: get coordinate values by clicking the mouse # TODO: add PySolo single ROI drawing # ------------------------------------------------------------------------------------------------------------ Title self.title = wx.StaticText(self, -1, "\n %s" % self.mon_name) # title font = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD) self.title.SetFont(font) # -------------------------------------------------------------------------------------------- video display options self.previewPanel = VM.monitorPanel(self, mon_ID=self.mon_ID, panelType='preview', loop=True) self.previewSizeLabel = wx.StaticText( self, wx.ID_ANY, 'frame size =') # ------ preview frame size self.previewSize = wx.TextCtrl(self, wx.ID_ANY, str(self.preview_size), style=wx.TE_PROCESS_ENTER, name='previewSize') self.previewFPSLabel = wx.StaticText( self, wx.ID_ANY, 'preview fps =') # --------- preview video fps self.previewFPS = wx.TextCtrl(self, wx.ID_ANY, str(self.preview_fps), style=wx.TE_PROCESS_ENTER, name='previewFPS') self.lineThicknessLabel = wx.StaticText( self, wx.ID_ANY, 'ROI line thickness =') # --------- preview ROI line thickness self.lineThickness = wx.TextCtrl(self, wx.ID_ANY, str(self.line_thickness), style=wx.TE_PROCESS_ENTER, name='lineThickness') # --------------------------------------------------------------------------------------- Save Configuration Button self.btnSaveCfg = wx.Button(self, wx.ID_ANY, label='Save Configuration', size=(130, 25)) if self.source != '': self.btnSaveCfg.Enable( True) # don't allow save if no source is selected else: self.btnSaveCfg.Enable(False) # --------------------------------------------------------------------------------------- Delete Monitor Button self.btnRemoveMonitor = wx.Button(self, wx.ID_ANY, label='Delete Monitor', size=(130, 25)) if self.monitors == 1: # don't allow last monitor to be deleted self.btnRemoveMonitor.Enable(False) else: self.btnRemoveMonitor.Enable(True) # -------------------------------------------------------------------------------------------------------- source self.txt_source = wx.StaticText(self, wx.ID_ANY, "Source: ") if self.source is not None: self.currentSource = wx.TextCtrl( self, wx.ID_ANY, self.source, style=wx.TE_READONLY) # get current source else: self.currentSource = wx.TextCtrl( self, wx.ID_ANY, 'None Selected', style=wx.TE_READONLY) # get current source # ------------------------------------------------------------------------------- Webcam selection combobox # if len(gbl.webcams_inuse) >= gbl.webcams: # only one webcam implemented at this time # self.WebcamsList = ['No more webcams available.'] # else: # self.WebcamsList = ['Webcam %s' % (int(w) + 1) for w in range(gbl.webcams)] # self.WebcamsList = ['Webcam 1'] # ------------------------------------------------------------------------------------------- source options self.source_IDs = [wx.ID_ANY, wx.ID_ANY, wx.ID_ANY] self.sources = [ 'placeholder for webcams', # (wx.ComboBox(self, id=self.source_IDs[0], choices=self.WebcamsList, name='sources0', # webcam # style=wx.EXPAND | wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SORT)), ( FileBrowseButton( self, id=self.source_IDs[1], # video file name='sources1', buttonText='Browse', toolTip= 'Type filename or click browse to choose video file', dialogTitle='Choose a video file', startDirectory=self.data_folder, wildcard='*.*', style=wx.ALL, changeCallback=self.onChangeSource1)), ( DirBrowseButton( self, id=self.source_IDs[2], name='sources2', # folder of images style=wx.DD_DIR_MUST_EXIST, startDirectory=self.data_folder, changeCallback=self.onChangeSource2)) ] # -------------------------------------------------------------------------------- source type radio buttons # self.rbs = [(wx.RadioButton(self, wx.ID_ANY, 'Camera', style=wx.RB_GROUP)), self.rbs = [ 'placeholder for camera radiobutton', (wx.RadioButton(self, wx.ID_ANY, 'File')), (wx.RadioButton(self, wx.ID_ANY, 'Folder')) ] # ------------------------------------------------------------------------------------------------ mask file browser wildcard = 'PySolo Video mask file (*.msk)|*.msk|' \ 'All files (*.*)|*.*' # adding space in here will mess it up! if self.mask_file is None: startDirectory = self.data_folder # Default directory for file dialog startup initialValue = 'None Selected' elif os.path.isfile(self.mask_file): startDirectory = os.path.split( self.mask_file)[0] # Default directory for file dialog startup initialValue = self.mask_file else: startDirectory = self.data_folder # Default directory for file dialog startup initialValue = 'None Selected' self.pickMaskBrowser = FileBrowseButton( self, id=wx.ID_ANY, labelText='Mask File: ', buttonText='Browse', toolTip='Type filename or click browse to choose mask file', dialogTitle='Choose a mask file', startDirectory=startDirectory, initialValue=initialValue, wildcard=wildcard, style=wx.ALL, changeCallback=self.onMaskBrowse, name='pickMaskBrowser') # -------------------------------------------------------------------------------------------- output folder browser if self.data_folder is None: startDirectory = self.data_folder = gbl.cfg_path # Default directory is config directory elif os.path.isdir(self.data_folder): startDirectory = self.data_folder # Default directory from config file else: startDirectory = self.data_folder = gbl.cfg_path # Default directory is config directory self.pickOutputBrowser = DirBrowseButton( self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL, labelText='Output Folder: ', dialogTitle='Choose an output folder', startDirectory=self.data_folder, value=gbl.data_folder, changeCallback=self.onChangeOutput, name='pickOutputBrowser') # ------------------------------------------------------------------------------------------------- video attributes self.sourceFPSLabel = wx.StaticText( self, wx.ID_ANY, 'Speed (fps) =') # ---------------- source fps self.sourceFPS = wx.TextCtrl(self, wx.ID_ANY, str(self.source_fps), style=wx.TE_PROCESS_ENTER, name='sourceFPS') self.txtDate = wx.StaticText(self, wx.ID_ANY, "Date: ") # ---------------- start date self.startDate = wx.DatePickerCtrl( self, wx.ID_ANY, dt=self.start_datetime, style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY | wx.TE_PROCESS_ENTER, name='start_date') self.txtTime = wx.StaticText( self, wx.ID_ANY, 'Time (24-hr): ') # ---------------- start time self.btnSpin = wx.SpinButton(self, wx.ID_ANY, wx.DefaultPosition, (-1, 20), wx.SP_VERTICAL) starttime = gbl.wxdatetime2timestring(self.start_datetime) self.startTime = masked.TimeCtrl(self, wx.ID_ANY, value=starttime, name='time: \n24 hour control', fmt24hr=True, spinButton=self.btnSpin, style=wx.TE_PROCESS_ENTER) self.instruction = wx.StaticText( self, wx.ID_ANY, 'Clicking on the video will change top left coordinate values.') """ # ------------------------------------------------------------------------------------------------ activate tracking self.trackBox = wx.CheckBox(self, wx.ID_ANY, 'Activate Tracking') self.trackBox.Enable(True) self.trackBox.SetValue(str(self.track)) # ---------------------------------------------------------------------------------------- sleep deprivation monitor self.isSDMonitor = wx.CheckBox(self, wx.ID_ANY, 'Sleep Deprivation Monitor') self.isSDMonitor.Enable(True) self.isSDMonitor.SetValue(str(self.issdmonitor)) # ---------------------------------------------------------------------------------------------------- tracking type self.trackChoice = [(wx.RadioButton(self, wx.ID_ANY, 'Activity as distance traveled', style=wx.RB_GROUP)), (wx.RadioButton(self, wx.ID_ANY, 'Activity as midline crossings count')), (wx.RadioButton(self, wx.ID_ANY, 'Only position of flies'))] for count in range(0, len(self.trackChoice)): self.trackChoice[count].Enable(True) if self.trackType == count: self.trackChoice[count].SetValue(True) else: self.trackChoice[count].SetValue(False) """ # -------------------------------------------------------------------------------------------- instructional diagram self.diagram = wx.Bitmap( os.path.join(gbl.exec_dir, 'maskmakerdiagram.bmp'), wx.BITMAP_TYPE_BMP) self.diagramctl = wx.StaticBitmap(self, -1, self.diagram) # --------------------------------------------------------------------------------------- ROI Coordinates Input Grid self.rowLabels = [ wx.StaticText(self, -1, ' '), wx.StaticText(self, -1, 'Number'), # row labels wx.StaticText(self, -1, 'Top Left'), wx.StaticText(self, -1, 'Span'), wx.StaticText(self, -1, 'Gap'), wx.StaticText(self, -1, 'Tilt') ] self.X = [] self.Y = [] self.X.append(wx.StaticText( self, wx.ID_ANY, "Columns (X)")) # column header for columns self.Y.append(wx.StaticText(self, wx.ID_ANY, "Rows (Y)")) # column header for rows for cnt in range(0, 5): self.X.append(NumCtrl(self, wx.ID_ANY, 0)) self.Y.append(NumCtrl(self, wx.ID_ANY, 0)) # ------------------------------------------------------------------------------------ mask generator & save buttons self.btnMaskGen = wx.Button(self, wx.ID_ANY, label="Generate Mask", size=(130, 25)) self.btnMaskGen.Enable(True) self.btnSaveMask = wx.Button(self, wx.ID_ANY, label="Save Mask", size=(130, 25)) self.btnSaveMask.Enable(True)