def OnPress(self, e): # TODO: make this less hard coded k = e.GetUniChar() if chr(k) in ['1', '2', '3', '4', '5']: k = int(chr(k)) - 1 if self.game.command(0, k): self.Refresh() elif chr(k) in ['6', '7', '8', '9', '0']: k = int(chr(k)) if k != 0: k -= 6 else: k = 4 if self.game.command(1, k): self.Refresh() elif k == wx.WXK_ESCAPE: # quite game self.Close() elif k == wx.WXK_DELETE: # reset game pub.unsubAll() self.Close() Window() # TODO: resize properly elif chr(k) == '+': pass elif chr(k) == '-': pass else: pass
def Close(self, event=None): Publisher.unsubAll() if self.udpListening: # print "Destroying UDP Response Listener..." network.udpresponselistener.destroy() self.Destroy() os._exit(0)
def Close(self, event=None): Publisher.unsubAll() if not platform.system() == 'Windows': self.notebook.Close() network.udpresponselistener.destroy() self.Destroy() sys.exit(0)
def OnCloseWindow(self, event): """ Actions triggered when main window is closed. Parameters: event - event object (wx.Event) """ self.StopDeviceTimer(destroy=True) # store widget positions if hasattr(self,'nb_widgets'): if self.nb_widgets!=None: cfg = wx.Config("TeraPy") mgr = self.nb_widgets.GetAuiManager() cfg.Write("Widgets",mgr.SavePerspective()) # stop scan thread if not(self.is_scanning): pub.unsubAll() self.Destroy() else: if wx.MessageBox("Scan is running! Really quit?", "Quit", style=wx.YES | wx.NO) == wx.YES: pub.sendMessage("scan.stop") pub.unsubAll() wx.CallAfter(self.Destroy)
def UdpListenerStopped(self): # print "UDP LISTENER STOPPED IN PANEL %d" % self.index global HOST_SYS Publisher.unsubAll() if self.prgDialog: self.prgDialog.Update(100) if HOST_SYS == HOST_WIN: self.prgDialog.Destroy()
def LoadRemoteFiles(self, event=None): # remove previous listener that may be present from other tab Publisher.unsubAll() # send udp request to receive files over tcp Publisher.subscribe(self.UpdateRemoteFiles, 'remote_files_loaded') msgData = network.messages.getMessage(FILE_DATA_REQUEST) network.udpconnector.sendMessage(msgData, self.host) # open tcp socket for file transmission network.tcpfilesocket.openFileSocket(self, HOST_SYS == HOST_WIN) self.invalidate = False
def Close(self, event=None): # remove temp dir if present from os.path import expanduser home = expanduser("~") appPath = home + '/.raspmedia/' tmpPath = appPath + 'tmp/' if os.path.isdir(tmpPath): shutil.rmtree(tmpPath) Publisher.unsubAll() self.notebook.Close() network.udpresponselistener.destroy() self.Destroy() sys.exit(0)
def on_close_window(self, evt=None): """ This method cleans up and closes the Odemis GUI. """ logging.info("Exiting Odemis") if self.main_data.is_acquiring.value: msg = ( "Acquisition in progress!\n\n" "Please cancel the current acquisition operation before exiting Odemis." ) dlg = wx.MessageDialog(self.main_frame, msg, "Exit", wx.OK | wx.ICON_STOP) # if dlg.ShowModal() == wx.ID_NO: dlg.ShowModal() dlg.Destroy() # frame return # Check if there's any action to do before tab termination # Do not terminate if returned False if not self.tab_controller.query_terminate(): return for p in self.plugins: try: p.terminate() except Exception: logging.exception("Failed to end the plugin properly") self.plugins = [] if self.dev_powermate: self.dev_powermate.terminate() try: pub.unsubAll() # let all the tabs know we are stopping self.tab_controller.terminate() except Exception: logging.exception("Error during GUI shutdown") try: log.stop_gui_logger() except Exception: logging.exception("Error stopping GUI logging") self.main_frame.Destroy()
def on_close_window(self, evt=None): #pylint: disable=W0613 """ This method cleans up and closes the Odemis GUI. """ logging.info("Exiting Odemis") if self.main_data.is_acquiring.value: msg = ("Acquisition in progress!\n\n" "Please cancel the current acquistion operation before exiting Odemis." ) dlg = wx.MessageDialog(self.main_frame, msg, "Exit", wx.OK | wx.ICON_STOP) # if dlg.ShowModal() == wx.ID_NO: dlg.ShowModal() dlg.Destroy() # frame return try: # Put cleanup actions here (like disconnect from odemisd) pub.unsubAll() # Stop live view try: self.main_data.opticalState.value = guimodel.STATE_OFF except AttributeError: pass # just no such microscope present try: self.main_data.emState.value = guimodel.STATE_OFF except AttributeError: pass # let all the tabs know we are stopping self._tab_controller.terminate() if self.http_proc: self.http_proc.terminate() #pylint: disable=E1101 except Exception: logging.exception("Error during GUI shutdown") try: log.stop_gui_logger() except Exception: logging.exception("Error stopping GUI logging") self.main_frame.Destroy()
def on_close_window(self, evt=None): """ This method cleans up and closes the Odemis GUI. """ logging.info("Exiting Odemis") if self.main_data.is_acquiring.value: msg = ("Acquisition in progress!\n\n" "Please cancel the current acquisition operation before exiting Odemis.") dlg = wx.MessageDialog(self.main_frame, msg, "Exit", wx.OK | wx.ICON_STOP) # if dlg.ShowModal() == wx.ID_NO: dlg.ShowModal() dlg.Destroy() # frame return for p in self.plugins: try: p.terminate() except Exception: logging.exception("Failed to end the plugin properly") self.plugins = [] if self.dev_powermate: self.dev_powermate.terminate() try: pub.unsubAll() # let all the tabs know we are stopping self.tab_controller.terminate() except Exception: logging.exception("Error during GUI shutdown") try: log.stop_gui_logger() except Exception: logging.exception("Error stopping GUI logging") self.main_frame.Destroy()
def UdpListenerStopped(self): # print "UDP LISTENER STOPPED IN PANEL %d" % self.index global HOST_SYS if self.pageDataLoading: if self.remoteListLoading: self.pageDataLoading = False Publisher.unsubAll() if self.parent.prgDialog: # print "CLOSING PRG DIALOG IN PARENT..." self.parent.prgDialog.Update(100) if HOST_SYS == HOST_WIN: self.parent.prgDialog.Destroy() if self.prgDialog: # print "CLOSING PRG DIALOG IN PANEL..." self.prgDialog.Update(100) if HOST_SYS == HOST_WIN: self.prgDialog.Destroy() else: self.LoadRemoteFileList() else: if self.prgDialog: self.prgDialog.Update(100) if HOST_SYS == HOST_WIN: self.prgDialog.Destroy()
def OnLoadPatientData(self, msg): """Update and load the patient data.""" # Skip loading if the dataset is empty or if the dataset is the same if (not len(msg)) or (self.ptdata == msg): return else: # Unsubscribe all listeners to the raw data updated while # it is re-processed pub.unsubAll('patient.updated.raw_data') pub.subscribe(self.OnLoadPatientData, 'patient.updated.raw_data') self.ptdata = msg # Delete the previous notebook pages self.notebook.DeleteAllPages() # Delete the previous toolbar items for t in range(0, self.toolbar.GetToolsCount()): # Only delete the plugin toolbar items if (t >= len(self.maintools)): self.toolbar.DeleteToolByPos(len(self.maintools)) # Delete the previous plugin menus if len(self.menuDict): self.menuPlugins.Delete(wx.ID_SEPARATOR) for menuid, menu in self.menuDict.items(): self.menuPlugins.Delete(menuid) # Remove the menu object from memory del(menu) self.menuDict = {} # Delete the previous export menus if len(self.menuExportDict): self.menuExportItem.Enable(False) for menuid, menu in self.menuExportDict.items(): self.menuExport.Delete(menuid) del(menu) self.menuExportDict = {} # Reset the preferences template self.preftemplate = [{'General':self.generalpreftemplate}] # Initialize the list of subplugins subplugins = [] # Set up the plugins for each plugin entry point of dicompyler for i, plugin in enumerate(self.plugins): # Skip plugin if it doesn't contain the required dictionary # or actually is a proper Python module p = plugin['plugin'] if not hasattr(p, 'pluginProperties') or \ (p.__name__ in self.pluginsDisabled): continue props = p.pluginProperties() # Only load plugin versions that are qualified if (props['plugin_version'] == 1): # Check whether the plugin can view the loaded DICOM data add = False if len(props['min_dicom']): for key in props['min_dicom']: if (key == 'rxdose'): pass elif key in self.ptdata.keys(): add = True else: add = False break # Plugin can view all DICOM data so always load it else: add = True # Initialize the plugin if add: # Load the main panel plugins if (props['plugin_type'] == 'main'): plugin = p.pluginLoader(self.notebook) self.notebook.AddPage(plugin, props['name']) # Load the menu plugins elif (props['plugin_type'] == 'menu'): if not len(self.menuDict): self.menuPlugins.AppendSeparator() self.menuPlugins.Append(100+i, props['name']+'...') plugin = p.plugin(self) self.menuDict[100+i] = plugin self.Bind(wx.EVT_MENU, plugin.pluginMenu, id=100+i) # Load the export menu plugins elif (props['plugin_type'] == 'export'): if not len(self.menuExportDict): self.menuExportItem.Enable(True) self.menuExport.Append(200+i, props['menuname']) plugin = p.plugin(self) self.menuExportDict[200+i] = plugin self.Bind(wx.EVT_MENU, plugin.pluginMenu, id=200+i) # If a sub-plugin, mark it to be initialized later else: subplugins.append(p) continue # Add the plugin preferences if they exist if hasattr(plugin, 'preferences'): self.preftemplate.append({props['name']:plugin.preferences}) pub.sendMessage('preferences.updated.template', msg=self.preftemplate) # Load the subplugins and notify the parent plugins for s in subplugins: props = s.pluginProperties() msg = 'plugin.loaded.' + props['plugin_type'] + '.' +s.__name__ pub.sendMessage(msg, msg=s) dlgProgress = guiutil.get_progress_dialog(self, "Loading Patient Data...") self.t=threading.Thread(target=self.LoadPatientDataThread, args=(self, self.ptdata, dlgProgress.OnUpdateProgress, self.OnUpdatePatientData)) self.t.start() dlgProgress.ShowModal() if dlgProgress: dlgProgress.Destroy()
def Close(self, event=None): Publisher.unsubAll() self.parent.SettingsClosedWithConfig(self.config) self.Destroy()
def OnLoadPatientData(self, msg): """Update and load the patient data.""" # Skip loading if the dataset is empty or if the dataset is the same if (not len(msg)) or (self.ptdata == msg): return else: # Unsubscribe all listeners to the raw data updated while # it is re-processed pub.unsubAll('patient.updated.raw_data') pub.subscribe(self.OnLoadPatientData, 'patient.updated.raw_data') self.ptdata = msg # Delete the previous notebook pages self.notebook.DeleteAllPages() # Delete the previous toolbar items for t in range(0, self.toolbar.GetToolsCount()): # Only delete the plugin toolbar items if (t >= len(self.maintools)): self.toolbar.DeleteToolByPos(len(self.maintools)) # Delete the previous plugin menus if len(self.menuDict): self.menuPlugins.Delete(wx.ID_SEPARATOR) for menuid, menu in self.menuDict.items(): self.menuPlugins.Delete(menuid) # Remove the menu object from memory del (menu) self.menuDict = {} # Delete the previous export menus if len(self.menuExportDict): self.menuExportItem.Enable(False) for menuid, menu in self.menuExportDict.items(): self.menuExport.Delete(menuid) del (menu) self.menuExportDict = {} # Reset the preferences template self.preftemplate = [{'General': self.generalpreftemplate}] # Initialize the list of subplugins subplugins = [] # Set up the plugins for each plugin entry point of dicompyler for i, plugin in enumerate(self.plugins): # Skip plugin if it doesn't contain the required dictionary # or actually is a proper Python module p = plugin['plugin'] if not hasattr(p, 'pluginProperties') or \ (p.__name__ in self.pluginsDisabled): continue props = p.pluginProperties() # Only load plugin versions that are qualified if (props['plugin_version'] == 1): # Check whether the plugin can view the loaded DICOM data add = False if len(props['min_dicom']): for key in props['min_dicom']: if (key == 'rxdose'): pass elif key in self.ptdata.keys(): add = True else: add = False break # Plugin can view all DICOM data so always load it else: add = True # Initialize the plugin if add: # Load the main panel plugins if (props['plugin_type'] == 'main'): plugin = p.pluginLoader(self.notebook) self.notebook.AddPage(plugin, props['name']) # Load the menu plugins elif (props['plugin_type'] == 'menu'): if not len(self.menuDict): self.menuPlugins.AppendSeparator() self.menuPlugins.Append(100 + i, props['name'] + '...') plugin = p.plugin(self) self.menuDict[100 + i] = plugin self.Bind(wx.EVT_MENU, plugin.pluginMenu, id=100 + i) # Load the export menu plugins elif (props['plugin_type'] == 'export'): if not len(self.menuExportDict): self.menuExportItem.Enable(True) self.menuExport.Append(200 + i, props['menuname']) plugin = p.plugin(self) self.menuExportDict[200 + i] = plugin self.Bind(wx.EVT_MENU, plugin.pluginMenu, id=200 + i) # If a sub-plugin, mark it to be initialized later else: subplugins.append(p) continue # Add the plugin preferences if they exist if hasattr(plugin, 'preferences'): self.preftemplate.append( {props['name']: plugin.preferences}) pub.sendMessage('preferences.updated.template', msg=self.preftemplate) # Load the subplugins and notify the parent plugins for s in subplugins: props = s.pluginProperties() msg = 'plugin.loaded.' + props['plugin_type'] + '.' + s.__name__ pub.sendMessage(msg, msg=s) dlgProgress = guiutil.get_progress_dialog(self, "Loading Patient Data...") self.t = threading.Thread(target=self.LoadPatientDataThread, args=(self, self.ptdata, dlgProgress.OnUpdateProgress, self.OnUpdatePatientData)) self.t.start() dlgProgress.ShowModal() if dlgProgress: dlgProgress.Destroy()
def Close(self, event=None): Publisher.unsubAll() self.notebook.Close() network.udpresponselistener.destroy() self.Destroy() sys.exit(0)