def pluginMenu(self, evt): """Anonymize DICOM / DICOM RT data.""" dlgAnonymize = self.res.LoadDialog(self.parent, "AnonymizeDialog") dlgAnonymize.Init() if dlgAnonymize.ShowModal() == wx.ID_OK: path = dlgAnonymize.path name = str(dlgAnonymize.name) patientid = str(dlgAnonymize.patientid) privatetags = dlgAnonymize.privatetags # If the path doesn't exist, create it if not os.path.exists(path): os.mkdir(path) # Initialize the progress dialog dlgProgress = guiutil.get_progress_dialog( wx.GetApp().GetTopWindow(), "Anonymizing DICOM data...") # Initialize and start the anonymization thread self.t = threading.Thread(target=self.AnonymizeDataThread, args=(self.data, path, name, patientid, privatetags, dlgProgress.OnUpdateProgress)) self.t.start() # Show the progress dialog dlgProgress.ShowModal() dlgProgress.Destroy() else: pass dlgAnonymize.Destroy() return
def OnLoadTree(self, event): """Update and load the DICOM tree.""" choiceItem = event.GetInt() # Load the dataset chosen from the choice control if not (choiceItem == 0): dataset = self.choiceDICOM.GetClientData(choiceItem) else: return self.tlcTreeView.DeleteAllItems() self.root = self.tlcTreeView.AppendItem(self.tlcTreeView.GetRootItem(),dataset.SOPClassUID.name) self.tlcTreeView.Collapse(self.root) # Initialize the progress dialog dlgProgress = guiutil.get_progress_dialog( wx.GetApp().GetTopWindow(), "Loading DICOM data...") # Set up the queue so that the thread knows which item was added self.queue = queue.Queue() # Initialize and start the recursion thread self.t=threading.Thread(target=self.RecurseTreeThread, args=(dataset, self.root, self.AddItemTree, dlgProgress.OnUpdateProgress, len(dataset))) self.t.start() # Show the progress dialog dlgProgress.ShowModal() dlgProgress.Destroy() self.tlcTreeView.SetFocus() self.tlcTreeView.Expand(self.root)
def pluginMenu(self, evt): """Open a new RT Dose object and sum it with the current dose""" self.ptdata = ImportDicom(self.parent) if (self.ptdata['rtplan'].SeriesInstanceUID != \ self.rtplan.SeriesInstanceUID): dlg = wx.MessageDialog(self.parent, "The image sets for both doses do not match.", "Cannot sum doses.", wx.OK | wx.ICON_WARNING) dlg.ShowModal() dlg.Destroy() return old = self.rtdose new = self.ptdata['rtdose'] dlgProgress = guiutil.get_progress_dialog( wx.GetApp().GetTopWindow(), "Creating Plan Sum...") q = queue.Queue() threading.Thread(target=SumPlan, args=(old, new, q, dlgProgress.OnUpdateProgress)).start() dlgProgress.ShowModal() dlgProgress.Destroy() sumDicomObj = q.get() if hasattr(sumDicomObj, 'DVHSequence'): del sumDicomObj.DVHSequence self.ptdata['rtdose'] = sumDicomObj if 'rxdose' in self.ptdata and self.rxdose: self.ptdata['rxdose'] = self.rxdose + self.ptdata['rxdose'] pub.sendMessage('patient.updated.raw_data', msg=self.ptdata)
def pluginMenu(self, evt): """Open a new RT Dose object and sum it with the current dose""" self.ptdata = ImportDicom(self.parent) if (self.ptdata['rtplan'].SeriesInstanceUID != \ self.rtplan.SeriesInstanceUID): dlg = wx.MessageDialog( self.parent, "The image sets for both doses do not match.", "Cannot sum doses.", wx.OK | wx.ICON_WARNING) dlg.ShowModal() dlg.Destroy() return old = self.rtdose new = self.ptdata['rtdose'] dlgProgress = guiutil.get_progress_dialog(wx.GetApp().GetTopWindow(), "Creating Plan Sum...") q = queue.Queue() threading.Thread(target=SumPlan, args=(old, new, q, dlgProgress.OnUpdateProgress)).start() dlgProgress.ShowModal() dlgProgress.Destroy() sumDicomObj = q.get() if hasattr(sumDicomObj, 'DVHSequence'): del sumDicomObj.DVHSequence self.ptdata['rtdose'] = sumDicomObj if 'rxdose' in self.ptdata and self.rxdose: self.ptdata['rxdose'] = self.rxdose + self.ptdata['rxdose'] pub.sendMessage('patient.updated.raw_data', msg=self.ptdata)
def pluginMenu(self, evt): """Anonymize DICOM / DICOM RT data.""" dlgAnonymize = self.res.LoadDialog(self.parent, "AnonymizeDialog") dlgAnonymize.Init() if dlgAnonymize.ShowModal() == wx.ID_OK: path = dlgAnonymize.path name = str(dlgAnonymize.name) patientid = str(dlgAnonymize.patientid) privatetags = dlgAnonymize.privatetags # If the path doesn't exist, create it if not os.path.exists(path): os.mkdir(path) # Initialize the progress dialog dlgProgress = guiutil.get_progress_dialog( wx.GetApp().GetTopWindow(), "Anonymizing DICOM data...") # Initialize and start the anonymization thread self.t=threading.Thread(target=self.AnonymizeDataThread, args=(self.data, path, name, patientid, privatetags, dlgProgress.OnUpdateProgress)) self.t.start() # Show the progress dialog dlgProgress.ShowModal() dlgProgress.Destroy() else: pass dlgAnonymize.Destroy() return
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 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 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.data)) or (self.ptdata == msg.data): return else: self.ptdata = msg.data # 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.iteritems(): self.menuPlugins.Delete(menuid) self.menuDict = {} # Delete the previous export menus if len(self.menuExportDict): self.menuExportItem.Enable(False) for menuid, menu in self.menuExportDict.iteritems(): self.menuExport.Delete(menuid) self.menuExportDict = {} # Reset the preferences template self.preftemplate = [{"General": self.generalpreftemplate}] # Set up the plugins for each plugin entry point of dicompyler for i, p in enumerate(self.plugins): 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 if props["plugin_type"] == "menu": if not len(self.menuDict): self.menuPlugins.AppendSeparator() self.menuDict[100 + i] = self.menuPlugins.Append(100 + i, props["name"] + "...") plugin = p.plugin(self) wx.EVT_MENU(self, 100 + i, plugin.pluginMenu) # Load the export menu plugins if props["plugin_type"] == "export": if not len(self.menuExportDict): self.menuExportItem.Enable(True) self.menuExportDict[200 + i] = self.menuExport.Append(200 + i, props["menuname"]) plugin = p.plugin(self) wx.EVT_MENU(self, 200 + i, plugin.pluginMenu) # Add the plugin preferences if they exist if hasattr(plugin, "preferences"): self.preftemplate.append({props["name"]: plugin.preferences}) pub.sendMessage("preferences.updated.template", self.preftemplate) 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()