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 changeConfig(self): # TODO doesn't erase consoles # ------------------------------ see if user wants to save current configuration before changing to another one. if gbl.shouldSaveCfg: cfg.Q_wantToSave( self) # asks user if config should be saved, & if so, saves gbl.shouldSaveCfg = False gbl.cfg_dict = [gbl.cfg_dict[0], gbl.cfg_dict[1] ] # remove all but monitors 1 from dictionary self.GrandParent.config.loadConfigFile( self.filePathName) # load the new file gbl.mon_ID = 1 cfg.cfg_dict_to_nicknames() # copy config parameters to nicknames cfg.mon_dict_to_nicknames() # copy monitor 1 parameters to nicknames # -------------------------------------------------------------------- clear out previous scrolled window panels self.scrolledThumbs.clearGrid(self.panelType) # -------------------------------------------------------- load new configuration into table and scrolled window self.fillTable() # put new configuration into the table self.pickCFGfile.ChangeValue( self.filePathName) # update the config file text control cfg.cfg_dict_to_nicknames() # load configuration page parameters self.fillTable() # update the configuration table self.scrolledThumbs.refreshGrid( ) # update and start the thumbnails window self.parent.repaginate( ) # add monitor pages to notebook & end on config page self.scrolledThumbs.EnableScrolling(1, 1) self.Layout()
def __init__(self, parent): wx.Panel.__init__(self, parent, wx.ID_ANY, size=(640, 480), name=gbl.mon_name) self.parent = parent self.mon_ID = gbl.mon_ID cfg.cfg_dict_to_nicknames( ) # set all nicknames for this monitor. use these so changes will be saved on page change. cfg.mon_dict_to_nicknames() self.start_datetime = gbl.start_datetime self.mon_name = gbl.mon_name self.preview_size = gbl.preview_size self.preview_fps = gbl.preview_fps self.line_thickness = gbl.line_thickness self.source = gbl.source self.monitors = gbl.monitors self.data_folder = gbl.data_folder self.source_type = gbl.source_type self.source_fps = gbl.source_fps self.issdmonitor = gbl.issdmonitor self.track_type = gbl.track_type self.track = gbl.track self.mask_file = gbl.mask_file self.widgets() self.binders() self.sizers()
def __init__(self, parent): wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style=wx.NB_LEFT, name='NotebookNameStr') # initialize notebook self.notebookPages = [] self.notebookPages.append( cfgPanel.cfgPanel(self)) # -----configuration page is element 0 cfg.cfg_dict_to_nicknames( ) # load configuration parameters into globals self.AddPage(self.notebookPages[0], 'Configuration') for gbl.mon_ID in range( 1, gbl.monitors + 1): # monitor pages are numbered by monitor number cfg.mon_dict_to_nicknames( ) # load monitor configuration into globals self.addMonitorPage() # add monitor page to notebook self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.onPageChanged) self.Layout() gbl.mon_ID = 0 # set mon_ID to zero which is configuration page
def refreshConsoleGrid(self): # ------------------------------------- Make array of thumbnails to populate the grid oldMon_ID = 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 self.trackedMonitors = ['tracked monitors'] self.trackedConsoles = ['consoles'] for gbl.mon_ID in range(1, gbl.monitors + 1): cfg.mon_dict_to_nicknames() # load monitor parameters to globals # create thread with tracked monitor and scroll panel and add to grid self.trackedMonitors.append(track.trackedMonitor(self, gbl.mon_ID)) self.trackedConsoles.append(self.trackedMonitors[gbl.mon_ID].console) self.thumbPanels.append(trackingThread(self, self.trackedMonitors[gbl.mon_ID], gbl.mon_ID)) # create tracked object self.thumbGridSizer.Add(self.trackedConsoles[gbl.mon_ID], 1, wx.ALIGN_CENTER_HORIZONTAL, 5) # add console to scrolled window self.SetSizerAndFit(self.thumbGridSizer) # did not fix all thumbs in one place self.Parent.Layout() for gbl.mon_ID in range(1, gbl.monitors + 1): self.thumbPanels[gbl.mon_ID].start() # start tracking after grid sizer is completely set gbl.mon_ID = oldMon_ID # go back to the 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 changeConfig(self): gbl.cfg_dict = [gbl.cfg_dict[0], gbl.cfg_dict[1]] # remove all but monitors 1 from dictionary self.GrandParent.config.loadConfigFile(self.filePathName) gbl.mon_ID = 1 cfg.cfg_dict_to_nicknames() cfg.mon_dict_to_nicknames() self.fillTable() # put new configuration into the table # self.scrolledThumbs.refreshThumbGrid() # create the thumbnail window self.parent.repaginate() # add monitor pages to notebook & end on config page self.pickCFGfile.SetValue(self.filePathName)
def repaginate( self ): # -------------------------------------- update notebook after number of pages has changed # page 0 (config page) will not be affected except for thumbnails # then go to configuration page # -------------------------------------------------------------------- delete each page from notebook (except 0) self.Unbind(wx.EVT_NOTEBOOK_PAGE_CHANGED ) # prevent page changing while deleting pages for gbl.mon_ID in range(len(self.notebookPages) - 1, 0, -1): self.notebookPages[gbl.mon_ID].clearVideo( ) # stop & remove video, timer, and thread for monitor pages # self.notebookPages.pop(gbl.mon_ID) # remove page from list of pages del self.notebookPages[ gbl.mon_ID] # remove page from list of pages self.DeletePage(gbl.mon_ID) # remove page from notebook object # ---------------------------------------------------- stop configuration page thumbnail and console timers try: # ------ don't know if thumbnails or console are showing self.notebookPages[0].scrolledThumbs.clearThumbGrid() except: pass try: # ------ don't know if thumbnails or console are showing self.notebookPages[0].scrolledThumbs.clearConsoleGrid() except: pass # ------------------------------------------------------------------------------------- recreate notebook pages cfg.cfg_dict_to_nicknames( ) # load configuration parameters into globals self.notebookPages[0].scrolledThumbs.thumbPanels = [ 'videoMonitors' ] # initiate a new thumbnail list; element 0 identifies type of list # ----------------------------------------------------------------------------------- add back each monitor page for gbl.mon_ID in range( 1, gbl.monitors + 1): # monitor pages are numbered by monitor number cfg.mon_dict_to_nicknames( ) # load monitor configuration into globals self.addMonitorPage() # add monitor page to notebook self.notebookPages[0].fillTable() # update the configuration table self.notebookPages[0].scrolledThumbs.refreshThumbGrid( ) # update the scrolled thumbs window gbl.mon_ID = 0 # ------------------------------------------------------------ go to configuration page cfg.cfg_dict_to_nicknames() self.SetSelection(gbl.mon_ID) self.Layout() self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.onPageChanged) # restore binding
def onAddMonitor( self, event ): # --------------------------------------------------------------- Add monitor """ adds a monitor to the list more than 9 monitors creates issues due to differences between alphabetical and numerical sorting. Avoiding problems by not allowing more than 9 monitors. """ cfg.cfg_nicknames_to_dicts( ) # -------------------------------------------- save current cfg settings if gbl.monitors >= 9: # no more than 9 monitors allowed self.TopLevelParent.SetStatusText( 'Too many monitors. Cannot add another.') winsound.Beep(600, 200) return False # -------------------------------------------------------------------- put new monitor settings in gbl nicknames gbl.cfg_dict.append({}) # add a dictionary to the cfg_dict list cfg.cfg_dict_to_nicknames() gbl.monitors += 1 # increase the number of monitors gbl.mon_ID = gbl.monitors # update the current mon_ID gbl.mon_name = 'Monitor%d' % gbl.mon_ID # update the monitor name # if gbl.source_type == 0: # create new webcam name if this is a webcam # gbl.webcams_inuse.append(gbl.mon_name) # only one webcam is supported, but multiple monitors can use it # gbl.webcams += 1 # gbl.source = 'Webcam%d' % gbl.webcams # gbl.source = 'Webcam1' # only one webcam is supported, but multiple monitors can use it cfg.cfg_nicknames_to_dicts( ) # ---------------------------------- save new configuration settings to cfg_dict cfg.mon_nicknames_to_dicts( gbl.mon_ID ) # ----------------------------------------- apply new monitor settings to cfg_dict # --------------------------------------------------------------------------------- add monitor page to notebook self.parent.addMonitorPage() gbl.mon_ID = gbl.cfg_dict[0]['monitors'] cfg.mon_dict_to_nicknames() self.Parent.notebookPages[0].fillTable( ) # update the configuration table self.scrolledThumbs.refreshThumbGrid() # create the thumbnail window # self.SetSizerAndFit(self.cfgPanelSizer) # self.Layout() gbl.mon_ID = 0
def onGoToPage( self, page_num ): # --------------------------------------------- for changing pages without an event gbl.statbar.SetStatusText(' ') old_ID = gbl.mon_ID if old_ID != 0: # ------------------------------------------------------------------ leaving a monitor page cfg.mon_nicknames_to_dicts( old_ID) # save any changes made to the monitor self.notebookPages[old_ID].clearVideo() # remove video and timer if old_ID == 0: # ---------------------------------------------------------- leaving the configuration page cfg.cfg_nicknames_to_dicts( ) # save any new changes to config parameters try: # ------ don't know if thumbnails or console are showing self.notebookPages[0].scrolledThumbs.clearThumbGrid( ) # remove all thumbnails, timers, and threads except: pass try: # ------ don't know if thumbnails or console are showing self.notebookPages[0].scrolledThumbs.clearConsoleGrid( ) # remove all thumbnails, timers, and threads except: pass # -------------------------------------------------------------------------------- update to the new page number gbl.mon_ID = page_num if page_num == 0: # -------------------------------------------------------- going to configuration page cfg.cfg_dict_to_nicknames() # load configuration page parameters self.notebookPages[0].fillTable() # update the configuration table self.notebookPages[0].scrolledThumbs.refreshThumbGrid( ) # update and start the thumbnails window # self.notebookPages[0].scrolledThumbs.SetScrollbars(1,1,1,1) # does not restore scrollbars # self.Layout() else: # ---------------------------------------------------------------------- going to a monitor page if gbl.mon_ID != 0: cfg.mon_dict_to_nicknames( ) # update nicknames to values for the selected monitor self.notebookPages[ gbl.mon_ID].previewPanel.parent.refreshVideo() # start video self.notebookPages[0].scrolledThumbs.EnableScrolling(1, 1) self.notebookPages[0].Layout() print('check')
def fillTable(self): # --------------------------------------- use cfg dictionary to fill in table currentrows = self.cfgTable.GetNumberRows() # clear the grid & resize to fit new configuration self.cfgTable.AppendRows(gbl.monitors, updateLabels=False) # add new rows to end self.cfgTable.DeleteRows(0, currentrows, updateLabels=False) # deletes old rows from beginning oldMonID = gbl.mon_ID for gbl.mon_ID in range(1, gbl.monitors +1): # columns are: 'Monitor', 'Track type', 'Track', 'Source', 'Mask', 'Output' # row numbers are 0-indexed cfg.mon_dict_to_nicknames() # get this monitor's settings # ----------------------------------------------------------------- table uses 0-indexing in following steps self.cfgTable.SetCellValue(gbl.mon_ID -1, 0, gbl.mon_name) self.cfgTable.SetCellAlignment(gbl.mon_ID -1, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) if gbl.track_type == 0: track_typeTxt = 'Distance' # track type elif gbl.track_type == 1: track_typeTxt = 'Virtual BM' elif gbl.track_type == 2: track_typeTxt = 'Position' else: print('track_type is out of range') track_typeTxt = 'None' self.cfgTable.SetCellValue(gbl.mon_ID -1, 1, track_typeTxt) self.cfgTable.SetCellAlignment(gbl.mon_ID -1, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.cfgTable.SetCellValue(gbl.mon_ID -1, 2, str(gbl.track)) # track self.cfgTable.SetCellAlignment(gbl.mon_ID -1, 2, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) if gbl.source is not None: self.cfgTable.SetCellValue(gbl.mon_ID -1, 3, gbl.source) # source else: self.cfgTable.SetCellValue(gbl.mon_ID -1, 3, 'None Selected') if gbl.mask_file is not None: self.cfgTable.SetCellValue(gbl.mon_ID -1, 4, os.path.split(gbl.mask_file)[1]) # mask_file else: self.cfgTable.SetCellValue(gbl.mon_ID - 1, 4, 'None Selected') if gbl.data_folder is not None: outfile = os.path.join(gbl.data_folder, gbl.mon_name) # output file name self.cfgTable.SetCellValue(gbl.mon_ID - 1, 5, outfile) else: self.cfgTable.SetCellValue(gbl.mon_ID - 1, 4, 'None Selected') gbl.mon_ID = oldMonID if gbl.mon_ID != 0: cfg.mon_dict_to_nicknames() self.cfgTable.AutoSize() # cell size based on contents self.Layout()
def __init__(self, parent, mon_ID, videoOn=False): self.parent = parent self.mon_ID = gbl.mon_ID = mon_ID # make sure the settings for this monitor are in the nicknames self.videoOn = videoOn # normally don't want to watch frame by frame during tracking cfg.mon_dict_to_nicknames() # ---------------------------------------------- copy source settings to self to protect from threading self.mon_name = gbl.mon_name self.source_type = gbl.source_type self.source = gbl.source self.devnum = 0 # only one camera is currently supported self.mmsize = gbl.source_mmsize self.fps = gbl.source_fps self.preview_size = gbl.preview_size # used to set console size self.start_datetime = gbl.start_datetime self.mask_file = gbl.mask_file self.data_folder = gbl.data_folder # ------ variables unique to this class self.loop = False # never loop tracking self.keepPlaying = False # don't start yet self.outputprefix = os.path.join(self.data_folder, self.mon_name) self.console = consolePanel(parent, size=gbl.thumb_size) # the output console # ------------------------------------ use the sourcetype to create the correct type of object for capture if self.source_type == 0: self.captureMovie = VM.realCam(self.mon_ID, 1, devnum=0) # NOT IN USE elif self.source_type == 1: self.captureMovie = VM.virtualCamMovie(self.mon_ID, 1, self.source, loop=False) elif self.source_type == 2: self.captureMovie = VM.virtualCamFrames(self.mon_ID, 1, self.source, loop=False) (self.cols, self.rows) = self.size = self.captureMovie.initialSize self.distscale = (float(self.mmsize[0]) / float(self.size[0]), float(self.mmsize[1]) / float(self.size[1])) self.areascale = self.distscale[0] * self.distscale[1] self.haveMask = self.loadROIsfromMaskFile( ) # -----------------------------------------------ROIs
def __init__(self, parent, mon_ID): self.mon_ID = gbl.mon_ID = mon_ID # make sure the settings for this monitor are in the nicknames cfg.mon_dict_to_nicknames() self.mon_name = gbl.mon_name wx.Panel.__init__(self, parent, id=wx.ID_ANY, name=self.mon_name) # -------------------------------------------------------------------------------------------- source settings self.parent = parent self.loop = False # never loop tracking self.keepPlaying = False # don't start yet self.source = gbl.source self.source_type = gbl.source_type self.devnum = 0 # only one camera is currently supported self.fps = gbl.source_fps self.start_datetime = gbl.start_datetime self.mask_file = gbl.mask_file self.data_folder = gbl.data_folder self.outputprefix = os.path.join( self.data_folder, self.mon_name) # path to folder where output will be saved self.console = self.consolePanel( parent, size=gbl.thumb_size) # the output console # ---------------------------------------- use the sourcetype to create the correct type of object for capture if self.source_type == 0: self.captureMovie = VM.realCam(self.mon_ID, 1, devnum=0) elif self.source_type == 1: self.captureMovie = VM.virtualCamMovie(self.mon_ID, 1, self.source, loop=False) elif self.source_type == 2: self.captureMovie = VM.virtualCamFrames(self.mon_ID, 1, self.source, loop=False) (self.cols, self.rows) = self.size = self.captureMovie.initialSize self.ROIs = gbl.loadROIsfromMaskFile( self.mask_file ) # -----------------------------------------------------ROIs
def __init__(self, parent): wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style=wx.NB_LEFT, name='Notebook') # ------------------------------------------------------------------------------------ create configuration page cfg.cfg_dict_to_nicknames() # load configuration parameters into global nicknames self.notebookPages = [] # create list to contain notebook page information indexed by mon_ID self.notebookPages.append(cfgPanel.cfgPanel(self)) # ----- configuration page is element 0 self.AddPage(self.notebookPages[0], 'Configuration') # ----- add configuration page to notebook # ----------------------------------------------------------------------------------------- create monitor pages for gbl.mon_ID in range(1, gbl.monitors+1): # monitor page numbers match monitor number cfg.mon_dict_to_nicknames() # load monitor configuration into global nicknames self.notebookPages.append(monPanel.monPanel(self)) # make the monitor page self.AddPage(self.notebookPages[gbl.mon_ID], gbl.mon_name) # add to notebook # ------------------------------------------------------------------------------------------- bind event handler self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.onPageChanged) self.Layout() gbl.mon_ID = self.page_num = 0 # set mon_ID to zero which is configuration page
def onGoToPage(self, nextpage): self.page_num = nextpage # assume page will change. user cancellation sets self.page_num back to gbl.mon_ID gbl.statbar.SetStatusText(' ') # TODO: stop duplicate preview panels # ------------------------------------------------------------------------------------------------ save changes if gbl.mon_ID != 0: # ------------------------------------------------------------- leaving a monitor page self.page_num = self.notebookPages[gbl.mon_ID].Q_shouldSaveMask(nextpage)# new mask not saved. want to save? if gbl.shouldSaveCfg: # cfg changed. want to save? --------------------------- leaving any page self.page_num = cfg.Q_wantToSave(self.notebookPages[gbl.mon_ID],nextpage) if self.page_num <> gbl.mon_ID: # if the page is still going to change, remove the video panels if gbl.mon_ID == 0: # ------------------------------------------------- leaving the configuration page # remove all thumbnails, timers, and threads self.notebookPages[0].scrolledThumbs.clearGrid(self.notebookPages[0].panelType) if gbl.mon_ID != 0: # -------------------------------------------------------------- leaving a monitor page self.notebookPages[gbl.mon_ID].clearVideo() # remove video and timer # ----------------------------------------------------------------------- update nickname to the new page number gbl.mon_ID = self.page_num if gbl.mon_ID == 0: # ---------------------------------------------------- refresh configuration page cfg.cfg_dict_to_nicknames() # load configuration page parameters self.notebookPages[0].fillTable() # update the configuration table self.notebookPages[0].scrolledThumbs.refreshGrid() # restart the thumbnail windows self.notebookPages[0].scrolledThumbs.EnableScrolling(1, 1) # restore scrollbars self.notebookPages[0].SetSizer(self.notebookPages[gbl.mon_ID].cfgPanelSizer) self.notebookPages[0].Layout() self.Layout() # ----------------------------------------------------------------- refresh the monitor page elif gbl.mon_ID != 0: # TODO: why double preview panels? changing source fixes it cfg.mon_dict_to_nicknames() # update nicknames for the selected monitor self.notebookPages[gbl.mon_ID].refreshVideo() # restart start video (monPanel.py) self.notebookPages[gbl.mon_ID].SetSizer(self.notebookPages[gbl.mon_ID].mainSizer) self.notebookPages[gbl.mon_ID].Layout() self.Layout()
def onRemoveMonitor( self, event ): # ------------------------------------------------------ Remove current monitor if self.monitors < 1: # don't remove the last monitor self.TopLevelParent.SetStatusText('Cannot remove last monitor.') winsound.Beep(600, 200) return False old_mon = self.mon_ID # keep track of monitor to be removed gbl.cfg_dict.pop( old_mon ) # delete monitor from dictionary; renumbers list automatically # if self.source[0:6] == 'Webcam': # if needed change global copy of number of webcams # gbl.webcams -= 1 # change number of webcams # gbl.webcams_inuse.remove(self.mon_name) # remove name from webcam list # ------------------------------------------------------------------------ reset higher numbered monitors' names for mon_count in range(old_mon, self.monitors): gbl.cfg_dict[mon_count]['mon_name'] = 'Monitor%d' % ( mon_count) # change monitor names # if gbl.cfg_dict[mon_count]['source'][0:6] == 'Webcam': # gbl.cfg_dict[mon_count]['source'][0:6] = 'Webcam%d' % mon_count # rename webcam -> only 1 webcam currently supported gbl.monitors -= 1 # ------------------------------------------------------ Change global settings if old_mon > gbl.monitors: # change current monitor number only if last monitor was deleted self.mon_ID = old_mon - 1 gbl.mon_ID = self.mon_ID cfg.cfg_nicknames_to_dicts( ) # -------------------------- update config dictionary to change # of monitors cfg.mon_dict_to_nicknames( ) # ------------------------------------------------- get new monitor settings self.parent.repaginate( ) # this will delete the notebook pages and recreate the notebook
def repaginate(self): # page 0 (config page) will not be affected except for thumbnails self.Unbind(wx.EVT_NOTEBOOK_PAGE_CHANGING) # prevent changes from triggering events self.Unbind(wx.EVT_NOTEBOOK_PAGE_CHANGED) # prevent changes from triggering events # -------------------------------------------------------------------- delete each page from notebook (except 0) for gbl.mon_ID in range(len(self.notebookPages)-1, 0, -1): self.notebookPages[gbl.mon_ID].clearVideo() # stop & remove video, timer, and thread for monitor pages del self.notebookPages[gbl.mon_ID] # remove page from list of pages self.DeletePage(gbl.mon_ID) # remove page from notebook object # --------------------------------------------------------- stop configuration page thumbnail and console timers self.notebookPages[0].scrolledThumbs.clearGrid(self.notebookPages[0].panelType) # -------------------------------------------------------------------------------------- recreate notebook pages cfg.cfg_dict_to_nicknames() # load configuration parameters into globals self.notebookPages[0].scrolledThumbs.thumbPanels = ['videoMonitors'] # initiate a new thumbnail list; # ----------------------------------------------------------------------------------- add back each monitor page for gbl.mon_ID in range(1, gbl.monitors+1): # pages are numbered by monitor number cfg.mon_dict_to_nicknames() # load monitor configuration into globals gbl.mon_name = 'Monitor%d' % gbl.mon_ID # correct mon_name cfg.mon_nicknames_to_dicts(gbl.mon_ID) # save new mon_name self.addMonitorPage() # add monitor page to notebook self.notebookPages[0].fillTable() # update the configuration table self.notebookPages[0].scrolledThumbs.refreshGrid() # update the scrolled thumbs window gbl.mon_ID = 0 # ------------------------------------------------------------ go to configuration page self.SetSelection(gbl.mon_ID) self.notebookPages[0].scrolledThumbs.EnableScrolling(1, 1) self.notebookPages[0].Layout() self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.onPageChanged) # restore binding
def fillTable(self): # using the cfg dictionary """ columns are: 'Monitor', 'Track type', 'Track', 'Source', 'Mask', 'Output' row numbers are 0-indexed """ # ------------------------------------------------------ clear the current grid and resize for new configuration currentrows = self.cfgTable.GetNumberRows( ) # get number of rows in current table self.cfgTable.AppendRows( gbl.monitors, updateLabels=False) # add new rows to end for each monitor self.cfgTable.DeleteRows( 0, currentrows, updateLabels=False) # delete old rows from beginning # --------------------------------------------------------------------- fill in table for gbl.mon_ID in range(1, gbl.monitors + 1): # one monitor to a row cfg.mon_dict_to_nicknames() # get this monitor's settings # ---------------------------------------------- table uses 0-indexing in following steps self.cfgTable.SetCellValue(gbl.mon_ID - 1, 0, gbl.mon_name) self.cfgTable.SetCellAlignment(gbl.mon_ID - 1, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) if gbl.track_type == 0: track_typeTxt = 'Distance' # track type elif gbl.track_type == 1: track_typeTxt = 'Virtual BM' # only distance tracking is implemented elif gbl.track_type == 2: track_typeTxt = 'Position' else: gbl.statbar.SetStatusText('Track_type is out of range.') winsound.Beep(600, 200) track_typeTxt = 'None' self.cfgTable.SetCellValue(gbl.mon_ID - 1, 1, track_typeTxt) self.cfgTable.SetCellAlignment(gbl.mon_ID - 1, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.cfgTable.SetCellValue(gbl.mon_ID - 1, 2, str( gbl.track)) # all monitors are tracked self.cfgTable.SetCellAlignment(gbl.mon_ID - 1, 2, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) if gbl.source is not None: self.cfgTable.SetCellValue(gbl.mon_ID - 1, 3, gbl.source) # source else: self.cfgTable.SetCellValue(gbl.mon_ID - 1, 3, 'None Selected') if gbl.mask_file is not None: self.cfgTable.SetCellValue(gbl.mon_ID - 1, 4, os.path.split( gbl.mask_file)[1]) # mask_file else: self.cfgTable.SetCellValue(gbl.mon_ID - 1, 4, 'None Selected') if gbl.data_folder is not None: outfile = os.path.join(gbl.data_folder, gbl.mon_name) # output file name self.cfgTable.SetCellValue(gbl.mon_ID - 1, 5, outfile) else: self.cfgTable.SetCellValue(gbl.mon_ID - 1, 4, 'None Selected') gbl.mon_ID = 0 # reset ID to configuration value self.cfgTable.AutoSize() # reset cell size based on contents self.Layout()