class TripLogDialog(wx.Dialog): def __init__(self): pre = wx.PreDialog() self.PostCreate(pre) def Init(self, tripexecuter): self.tripexecuter = tripexecuter self.tripexecuter.add_log_listener(self) self.txt_log = XRCCTRL(self, "txt_log") wx.EVT_BUTTON(self, XRCID("btn_ok"), self.close) self.btn_ok = XRCCTRL(self, "btn_ok") self.btn_ok.Enable(False) self.check_close = XRCCTRL(self, "check_close") def close(self, evt): self.Close() def finish(self): self.btn_ok.Enable(True) if self.check_close.IsChecked(): self.Close() def write(self, txt): self.txt_log.AppendText("%s\n" % txt)
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 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 TripVoiDialog(wx.Dialog): def __init__(self): pre = wx.PreDialog() self.PostCreate(pre) pub.subscribe(self.patient_data_updated, "patient.loaded") pub.sendMessage("patient.request", {}) def patient_data_updated(self, msg): self.data = msg.data def select_drop_by_value(self, drop, value): for i, item in enumerate(drop.GetItems()): if item == value: drop.SetSelection(i) def Init(self, voi): self.voi = voi wx.EVT_BUTTON(self, XRCID('btn_ok'), self.save_and_close) wx.EVT_BUTTON(self, XRCID('btn_close'), self.close) self.label_name = XRCCTRL(self, "label_name") self.label_name.SetLabel(voi.get_name()) self.txt_dose = XRCCTRL(self, "txt_dose") self.txt_dose.SetValue("%.2f" % (voi.get_dose())) self.check_target = XRCCTRL(self, "check_target") self.check_target.SetValue(voi.is_target()) self.check_target.Bind(wx.EVT_CHECKBOX, self.on_check_target_changed) self.check_oar = XRCCTRL(self, "check_oar") self.check_oar.SetValue(voi.is_oar()) self.check_oar.Bind(wx.EVT_CHECKBOX, self.on_check_oar_changed) self.txt_max_dose_fraction = XRCCTRL(self, "txt_max_dose_fraction") self.txt_max_dose_fraction.SetValue("%.2f" % (voi.get_max_dose_fraction())) self.txt_max_dose_fraction.Enable(False) self.txt_dose.Enable(False) if voi.is_target(): self.check_oar.Enable(False) self.txt_dose.Enable(True) if voi.is_oar(): self.txt_max_dose_fraction.Enable(True) self.check_target.Enable(False) self.txt_hu_value = XRCCTRL(self, "txt_hu_value") self.txt_hu_offset = XRCCTRL(self, "txt_hu_offset") if not voi.get_hu_value() is None: self.txt_hu_value.SetValue("%d" % voi.get_hu_value()) if not voi.get_hu_offset() is None: self.txt_hu_offset.SetValue("%d" % voi.get_hu_offset()) self.drop_projectile = XRCCTRL(self, "drop_projectile") self.drop_projectile.Append("H") self.drop_projectile.Append("C") self.txt_dose_percent = XRCCTRL(self, "txt_dose_percent") wx.EVT_BUTTON(self, XRCID('btn_set_dosepercent'), self.set_dose_percent) wx.EVT_CHOICE(self, XRCID('drop_projectile'), self.on_projectile_changed) def on_projectile_changed(self, evt): projectile = self.drop_projectile.GetStringSelection() dose_percent = self.voi.get_dose_percent(projectile) if dose_percent is None: self.txt_dose_percent.SetValue("") else: self.txt_dose_percent.SetValue("%d" % dose_percent) def set_dose_percent(self, evt): if not self.drop_projectile.GetStringSelection() == "": self.voi.set_dose_percent(self.drop_projectile.GetStringSelection(), self.txt_dose_percent.GetValue()) def on_check_target_changed(self, evt): if evt.Checked(): self.check_oar.Enable(False) self.txt_dose.Enable(True) else: self.check_oar.Enable(True) self.txt_dose.Enable(False) def on_check_oar_changed(self, evt): if evt.Checked(): self.txt_max_dose_fraction.Enable(True) self.check_target.Enable(False) else: self.check_target.Enable(True) self.txt_max_dose_fraction.Enable(False) def save_and_close(self, evt): voi = self.voi voi.set_dose(self.txt_dose.GetValue()) if voi.is_target() is not self.check_target.IsChecked(): voi.toogle_target() if voi.is_oar() is not self.check_oar.IsChecked(): voi.toogle_oar() voi.set_max_dose_fraction(self.txt_max_dose_fraction.GetValue()) voi.set_hu_offset(self.txt_hu_offset.GetValue()) voi.set_hu_value(self.txt_hu_value.GetValue()) self.Close() def close(self, evt): self.Close()
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)
class FieldDialog(wx.Dialog): def __init__(self): pre = wx.PreDialog() self.PostCreate(pre) def Init(self, field): self.field = field self.btn_ok = XRCCTRL(self, 'btn_ok') wx.EVT_BUTTON(self, XRCID('btn_ok'), self.save_and_close) self.btn_cancel = XRCCTRL(self, 'btn_close') wx.EVT_BUTTON(self, XRCID('btn_close'), self.close) self.label_fieldname = XRCCTRL(self, 'label_fieldname') self.label_fieldname.SetLabel(field.get_name()) self.check_isocenter = XRCCTRL(self, 'check_isocenter') target = field.get_target() if len(target) > 0: self.check_isocenter.SetValue(True) self.check_isocenter.Bind(wx.EVT_CHECKBOX, self.on_check_isocenter_changed) self.txt_targetx = XRCCTRL(self, 'txt_targetx') self.txt_targety = XRCCTRL(self, 'txt_targety') self.txt_targetz = XRCCTRL(self, 'txt_targetz') if len(target) > 0: self.txt_targetx.SetValue("%.2f" % (target[0])) self.txt_targety.SetValue("%.2f" % (target[1])) self.txt_targetz.SetValue("%.2f" % (target[2])) else: self.txt_targetx.Enable(False) self.txt_targety.Enable(False) self.txt_targetz.Enable(False) self.txt_gantry = XRCCTRL(self, 'txt_gantry') self.txt_gantry.SetValue("%.2f" % field.get_gantry()) self.txt_couch = XRCCTRL(self, 'txt_couch') self.txt_couch.SetValue("%.2f" % field.get_couch()) self.txt_fwhm = XRCCTRL(self, 'txt_fwhm') self.txt_fwhm.SetValue("%.2f" % field.get_fwhm()) self.txt_zsteps = XRCCTRL(self, 'txt_zsteps') self.txt_zsteps.SetValue("%.2f" % field.get_zsteps()) self.txt_doseextension = XRCCTRL(self, 'txt_doseext') self.txt_doseextension.SetValue("%.2f" % field.get_doseextension()) self.txt_contourextension = XRCCTRL(self, 'txt_contourext') self.txt_contourextension.SetValue("%.2f" % field.get_contourextension()) self.txt_raster1 = XRCCTRL(self, 'txt_raster1') self.txt_raster2 = XRCCTRL(self, 'txt_raster2') raster = field.get_rasterstep() self.txt_raster1.SetValue("%.2f" % raster[0]) self.txt_raster2.SetValue("%.2f" % raster[1]) self.drop_projectile = XRCCTRL(self, 'drop_projectile') self.drop_projectile.SetSelection( self.drop_projectile.GetItems().index(field.projectile)) def on_check_isocenter_changed(self, evt): if self.check_isocenter.IsChecked(): self.txt_targetx.Enable(True) self.txt_targety.Enable(True) self.txt_targetz.Enable(True) else: self.txt_targetx.Enable(False) self.txt_targety.Enable(False) self.txt_targetz.Enable(False) def save_and_close(self, evt): self.field.set_couch(self.txt_couch.GetValue()) self.field.set_gantry(self.txt_gantry.GetValue()) self.field.set_fwhm(self.txt_fwhm.GetValue()) if self.check_isocenter.IsChecked(): self.field.set_target(self.txt_targetx.GetValue() + "," + self.txt_targety.GetValue() + "," + self.txt_targetz.GetValue()) else: self.field.set_target("") self.field.set_zsteps(self.txt_zsteps.GetValue()) self.field.set_doseextension(self.txt_doseextension.GetValue()) self.field.set_contourextension(self.txt_contourextension.GetValue()) self.field.set_rasterstep(self.txt_raster1.GetValue(), self.txt_raster2.GetValue()) self.field.set_projectile(self.drop_projectile.GetStringSelection()) self.Close() def close(self, evt): self.Close()