class PluginManagerDialog(wx.Dialog): """Manage the available plugins.""" def __init__(self): pre = wx.PreDialog() # the Create step is done by XRC. self.PostCreate(pre) def Init(self, plugins, pluginsDisabled): """Method called after the panel has been initialized.""" # Set window icon if not guiutil.IsMac(): self.SetIcon(guiutil.get_icon()) # Initialize controls self.tcPlugins = XRCCTRL(self, 'tcPlugins') self.panelTreeView = XRCCTRL(self, 'panelTreeView') self.panelProperties = XRCCTRL(self, 'panelProperties') self.lblName = XRCCTRL(self, 'lblName') self.lblAuthor = XRCCTRL(self, 'lblAuthor') self.lblPluginType = XRCCTRL(self, 'lblPluginType') self.lblVersion = XRCCTRL(self, 'lblVersion') self.lblVersionNumber = XRCCTRL(self, 'lblVersionNumber') self.lblDescription = XRCCTRL(self, 'lblDescription') self.checkEnabled = XRCCTRL(self, 'checkEnabled') self.lblMessage = XRCCTRL(self, 'lblMessage') self.btnGetMorePlugins = XRCCTRL(self, 'btnGetMorePlugins') self.btnDeletePlugin = XRCCTRL(self, 'btnDeletePlugin') self.plugins = plugins self.pluginsDisabled = set(pluginsDisabled) # Bind interface events to the proper methods # wx.EVT_BUTTON(self, XRCID('btnDeletePlugin'), self.DeletePlugin) wx.EVT_CHECKBOX(self, XRCID('checkEnabled'), self.OnEnablePlugin) wx.EVT_TREE_ITEM_ACTIVATED(self, XRCID('tcPlugins'), self.OnEnablePlugin) wx.EVT_TREE_SEL_CHANGED(self, XRCID('tcPlugins'), self.OnSelectTreeItem) wx.EVT_TREE_SEL_CHANGING(self, XRCID('tcPlugins'), self.OnSelectRootItem) # Modify the control and font size as needed font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) if guiutil.IsMac(): children = list(self.Children) + \ list(self.panelTreeView.Children) + \ list(self.panelProperties.Children) for control in children: control.SetFont(font) control.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) XRCCTRL(self, 'wxID_OK').SetWindowVariant(wx.WINDOW_VARIANT_NORMAL) font.SetWeight(wx.FONTWEIGHT_BOLD) if guiutil.IsMSWindows(): self.tcPlugins.SetPosition((0, 3)) self.panelTreeView.SetWindowStyle(wx.STATIC_BORDER) if (guiutil.IsMac() or guiutil.IsGtk()): self.tcPlugins.SetPosition((-30, 0)) self.panelTreeView.SetWindowStyle(wx.SUNKEN_BORDER) self.lblName.SetFont(font) self.lblMessage.SetFont(font) self.Layout() self.InitPluginList() self.LoadPlugins() def InitPluginList(self): """Initialize the plugin list control.""" iSize = (16, 16) iList = wx.ImageList(iSize[0], iSize[1]) iList.Add( wx.Bitmap(util.GetResourcePath('bricks.png'), wx.BITMAP_TYPE_PNG)) iList.Add( wx.Bitmap(util.GetResourcePath('plugin.png'), wx.BITMAP_TYPE_PNG)) iList.Add( wx.Bitmap(util.GetResourcePath('plugin_disabled.png'), wx.BITMAP_TYPE_PNG)) self.tcPlugins.AssignImageList(iList) self.root = self.tcPlugins.AddRoot('Plugins') self.baseroot = self.tcPlugins.AppendItem(self.root, "Built-In Plugins", 0) self.userroot = self.tcPlugins.AppendItem(self.root, "User Plugins", 0) font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) font.SetWeight(wx.FONTWEIGHT_BOLD) self.tcPlugins.SetItemFont(self.baseroot, font) self.tcPlugins.SetItemFont(self.userroot, font) def LoadPlugins(self): """Update and load the data for the plugin list control.""" # Set up the plugins for each plugin entry point of dicompyler for n, 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'): continue props = p.pluginProperties() root = self.userroot if (plugin['location'] == 'base'): root = self.baseroot else: root = self.userroot i = self.tcPlugins.AppendItem(root, props['name'], 1) if (p.__name__ in self.pluginsDisabled): self.tcPlugins.SetItemImage(i, 2) self.tcPlugins.SetItemTextColour(i, wx.Colour(169, 169, 169)) self.tcPlugins.SetPyData(i, n) self.tcPlugins.SelectItem(i) self.tcPlugins.ExpandAll() wx.EVT_TREE_ITEM_COLLAPSING(self, XRCID('tcPlugins'), self.OnExpandCollapseTree) wx.EVT_TREE_ITEM_EXPANDING(self, XRCID('tcPlugins'), self.OnExpandCollapseTree) def OnSelectTreeItem(self, evt): """Update the interface when the selected item has changed.""" item = evt.GetItem() n = self.tcPlugins.GetPyData(item) if (n == None): self.panelProperties.Hide() return self.panelProperties.Show() plugin = self.plugins[n] p = plugin['plugin'] props = p.pluginProperties() self.lblName.SetLabel(props['name']) self.lblAuthor.SetLabel(props['author'].replace('&', '&&')) self.lblVersionNumber.SetLabel(str(props['version'])) ptype = props['plugin_type'] self.lblPluginType.SetLabel(ptype[0].capitalize() + ptype[1:]) self.lblDescription.SetLabel(props['description'].replace('&', '&&')) self.checkEnabled.SetValue(not (p.__name__ in self.pluginsDisabled)) self.Layout() self.panelProperties.Layout() def OnSelectRootItem(self, evt): """Block the root items from being selected.""" item = evt.GetItem() n = self.tcPlugins.GetPyData(item) if (n == None): evt.Veto() def OnExpandCollapseTree(self, evt): """Block the tree from expanding or collapsing.""" evt.Veto() def OnEnablePlugin(self, evt=None): """Publish the enabled/disabled state of the plugin.""" item = self.tcPlugins.GetSelection() n = self.tcPlugins.GetPyData(item) plugin = self.plugins[n] p = plugin['plugin'] # Set the checkbox to the appropriate state if the event # comes from the treeview if (evt.EventType == wx.EVT_TREE_ITEM_ACTIVATED.typeId): self.checkEnabled.SetValue(not self.checkEnabled.IsChecked()) if self.checkEnabled.IsChecked(): self.tcPlugins.SetItemImage(item, 1) self.tcPlugins.SetItemTextColour(item, wx.BLACK) self.pluginsDisabled.remove(p.__name__) logger.debug("%s enabled", p.__name__) else: self.tcPlugins.SetItemImage(item, 2) self.tcPlugins.SetItemTextColour(item, wx.Colour(169, 169, 169)) self.pluginsDisabled.add(p.__name__) logger.debug("%s disabled", p.__name__) pub.sendMessage( 'preferences.updated.value', {'general.plugins.disabled_list': list(self.pluginsDisabled)})
class AnonymizeDialog(wx.Dialog): """Dialog that shows the options to anonymize DICOM / DICOM RT data.""" def __init__(self): pre = wx.PreDialog() # the Create step is done by XRC. self.PostCreate(pre) def Init(self): """Method called after the dialog has been initialized.""" # Set window icon if not guiutil.IsMac(): self.SetIcon(guiutil.get_icon()) # Initialize controls self.txtDICOMFolder = XRCCTRL(self, 'txtDICOMFolder') self.checkPatientName = XRCCTRL(self, 'checkPatientName') self.txtFirstName = XRCCTRL(self, 'txtFirstName') self.txtLastName = XRCCTRL(self, 'txtLastName') self.checkPatientID = XRCCTRL(self, 'checkPatientID') self.txtPatientID = XRCCTRL(self, 'txtPatientID') self.checkPrivateTags = XRCCTRL(self, 'checkPrivateTags') self.bmpError = XRCCTRL(self, 'bmpError') self.lblDescription = XRCCTRL(self, 'lblDescription') # Bind interface events to the proper methods wx.EVT_BUTTON(self, XRCID('btnFolderBrowse'), self.OnFolderBrowse) wx.EVT_CHECKBOX(self, XRCID('checkPatientName'), self.OnCheckPatientName) wx.EVT_CHECKBOX(self, XRCID('checkPatientID'), self.OnCheckPatientID) wx.EVT_BUTTON(self, wx.ID_OK, self.OnOK) # Set and bold the font of the description label if guiutil.IsMac(): font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) font.SetWeight(wx.FONTWEIGHT_BOLD) self.lblDescription.SetFont(font) # Initialize the import location via pubsub pub.subscribe(self.OnImportPrefsChange, 'general.dicom.import_location') pub.sendMessage('preferences.requested.value', 'general.dicom.import_location') # Pre-select the text on the text controls due to a Mac OS X bug self.txtFirstName.SetSelection(-1, -1) self.txtLastName.SetSelection(-1, -1) self.txtPatientID.SetSelection(-1, -1) # Load the error bitmap self.bmpError.SetBitmap(wx.Bitmap(util.GetResourcePath('error.png'))) # Initialize variables self.name = self.txtLastName.GetValue( ) + '^' + self.txtFirstName.GetValue() self.patientid = self.txtPatientID.GetValue() self.privatetags = True def OnImportPrefsChange(self, msg): """When the import preferences change, update the values.""" self.path = unicode(msg.data) self.txtDICOMFolder.SetValue(self.path) def OnFolderBrowse(self, evt): """Get the directory selected by the user.""" dlg = wx.DirDialog( self, defaultPath=self.path, message="Choose a folder to save the anonymized DICOM data...") if dlg.ShowModal() == wx.ID_OK: self.path = dlg.GetPath() self.txtDICOMFolder.SetValue(self.path) dlg.Destroy() def OnCheckPatientName(self, evt): """Enable or disable whether the patient's name is anonymized.""" self.txtFirstName.Enable(evt.IsChecked()) self.txtLastName.Enable(evt.IsChecked()) if not evt.IsChecked(): self.txtDICOMFolder.SetFocus() else: self.txtFirstName.SetFocus() self.txtFirstName.SetSelection(-1, -1) def OnCheckPatientID(self, evt): """Enable or disable whether the patient's ID is anonymized.""" self.txtPatientID.Enable(evt.IsChecked()) if not evt.IsChecked(): self.txtDICOMFolder.SetFocus() else: self.txtPatientID.SetFocus() self.txtPatientID.SetSelection(-1, -1) def OnOK(self, evt): """Return the options from the anonymize data dialog.""" # Patient name if self.checkPatientName.IsChecked(): self.name = self.txtLastName.GetValue() if len(self.txtFirstName.GetValue()): self.name = self.name + '^' + self.txtFirstName.GetValue() else: self.name = '' # Patient ID if self.checkPatientID.IsChecked(): self.patientid = self.txtPatientID.GetValue() else: self.patientid = '' # Private tags if self.checkPrivateTags.IsChecked(): self.privatetags = True else: self.privatetags = False self.EndModal(wx.ID_OK) def OnDestroy(self, evt): """Unbind to all events before the plugin is destroyed.""" pub.unsubscribe(self.OnImportPrefsChange, 'general.dicom.import_location') pub.unsubscribe(self.OnUpdatePatient, 'patient.updated.raw_data')
class AnonymizeDialog(wx.Dialog): """Dialog th # Changed foundstructure to fixed 'True' # I didn't understand the reason why RT Structure Set will be # set to 'not found' in this case. (Actually RT Structure has already been found by the above code.) # In this case, 'RT Plan' is not found, RT Structure Set in patient, and foundstructure = False. # Previous code: foundstructure = Falseat shows the options to anonymize DICOM / DICOM RT data.""" def __init__(self): wx.Dialog.__init__(self) def Init(self): """Method called after the dialog has been initialized.""" # Set window icon if not guiutil.IsMac(): self.SetIcon(guiutil.get_icon()) # Initialize controls self.txtDICOMFolder = XRCCTRL(self, 'txtDICOMFolder') self.checkPatientName = XRCCTRL(self, 'checkPatientName') self.txtFirstName = XRCCTRL(self, 'txtFirstName') self.txtLastName = XRCCTRL(self, 'txtLastName') self.checkPatientID = XRCCTRL(self, 'checkPatientID') self.txtPatientID = XRCCTRL(self, 'txtPatientID') self.checkPrivateTags = XRCCTRL(self, 'checkPrivateTags') self.bmpError = XRCCTRL(self, 'bmpError') self.lblDescription = XRCCTRL(self, 'lblDescription') # Bind interface events to the proper methods wx.EVT_BUTTON(self, XRCID('btnFolderBrowse'), self.OnFolderBrowse) wx.EVT_CHECKBOX(self, XRCID('checkPatientName'), self.OnCheckPatientName) wx.EVT_CHECKBOX(self, XRCID('checkPatientID'), self.OnCheckPatientID) wx.EVT_BUTTON(self, wx.ID_OK, self.OnOK) # Set and bold the font of the description label if guiutil.IsMac(): font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) font.SetWeight(wx.FONTWEIGHT_BOLD) self.lblDescription.SetFont(font) # Initialize the import location via pubsub pub.subscribe(self.OnImportPrefsChange, 'general.dicom') pub.sendMessage('preferences.requested.values', msg='general.dicom') # Pre-select the text on the text controls due to a Mac OS X bug self.txtFirstName.SetSelection(-1, -1) self.txtLastName.SetSelection(-1, -1) self.txtPatientID.SetSelection(-1, -1) # Load the error bitmap self.bmpError.SetBitmap(wx.Bitmap(util.GetResourcePath('error.png'))) # Initialize variables self.name = self.txtLastName.GetValue( ) + '^' + self.txtFirstName.GetValue() self.patientid = self.txtPatientID.GetValue() self.privatetags = True def OnImportPrefsChange(self, topic, msg): """When the import preferences change, update the values.""" topic = topic.split('.') if (topic[1] == 'import_location'): self.path = str(msg) self.txtDICOMFolder.SetValue(self.path) def OnFolderBrowse(self, evt): """Get the directory selected by the user.""" dlg = wx.DirDialog( self, defaultPath=self.path, message="Choose a folder to save the anonymized DICOM data...") if dlg.ShowModal() == wx.ID_OK: self.path = dlg.GetPath() self.txtDICOMFolder.SetValue(self.path) dlg.Destroy() def OnCheckPatientName(self, evt): """Enable or disable whether the patient's name is anonymized.""" self.txtFirstName.Enable(evt.IsChecked()) self.txtLastName.Enable(evt.IsChecked()) if not evt.IsChecked(): self.txtDICOMFolder.SetFocus() else: self.txtFirstName.SetFocus() self.txtFirstName.SetSelection(-1, -1) def OnCheckPatientID(self, evt): """Enable or disable whether the patient's ID is anonymized.""" self.txtPatientID.Enable(evt.IsChecked()) if not evt.IsChecked(): self.txtDICOMFolder.SetFocus() else: self.txtPatientID.SetFocus() self.txtPatientID.SetSelection(-1, -1) def OnOK(self, evt): """Return the options from the anonymize data dialog.""" # Patient name if self.checkPatientName.IsChecked(): self.name = self.txtLastName.GetValue() if len(self.txtFirstName.GetValue()): self.name = self.name + '^' + self.txtFirstName.GetValue() else: self.name = '' # Patient ID if self.checkPatientID.IsChecked(): self.patientid = self.txtPatientID.GetValue() else: self.patientid = '' # Private tags if self.checkPrivateTags.IsChecked(): self.privatetags = True else: self.privatetags = False self.EndModal(wx.ID_OK)