Пример #1
0
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')
Пример #2
0
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)