コード例 #1
0
class ConfigureDialog(QDialog):
    '''
    Configure dialog to present the user with the options to configure this step.
    '''


    def __init__(self, state, parent=None):
        '''
        Constructor
        '''
        QDialog.__init__(self, parent)
        self._ui = Ui_ConfigureDialog()
        self._ui.setupUi(self)
        self._setupPMRTab()

        self.setState(state)

        self.validate()

        self._makeConnections()

    def _makeConnections(self):
        self._ui.identifierLineEdit.textChanged.connect(self.validate)
        self._ui.localLineEdit.textChanged.connect(self._localLocationEdited)
        self._ui.localButton.clicked.connect(self._localLocationClicked)
        self._pmr_widget._ui.lineEditWorkspace.textChanged.connect(self._workspaceChanged)
#         self._ui.pmrRegisterLabel.linkActivated.connect(self._register)

    def _setupPMRTab(self):
        self._pmr_widget = PMRWorkflowWidget(self)
        self._pmr_widget.setImport(False)
        self._pmr_widget.setExport(False)
        self._pmr_widget.setSearchDomain([ontological_search_string, plain_text_search_string])

        layout = self._ui.pmrTab.layout()
        layout.addWidget(self._pmr_widget)

    def setState(self, state):
        self._ui.identifierLineEdit.setText(state._identifier)
        self._ui.localLineEdit.setText(state._local_location)
        self._pmr_widget.setWorkspaceUrl(state._pmr_location)
        self._ui.imageSourceTypeComboBox.setCurrentIndex(state._image_type)
        self._ui.tabWidget.setCurrentIndex(state._current_tab)
        self._ui.previousLocationLabel.setText(state._previous_local_location)

    def getState(self):
        state = ConfigureDialogState(
            self._ui.identifierLineEdit.text(),
            self._ui.localLineEdit.text(),
            self._pmr_widget.workspaceUrl(),
            self._ui.imageSourceTypeComboBox.currentIndex(),
            self._ui.tabWidget.currentIndex(),
            self._ui.previousLocationLabel.text())

        return state

    def _localLocationClicked(self):
        location = QFileDialog.getExistingDirectory(self, 'Select Image File(s) Location', self._ui.previousLocationLabel.text())

        if location:
            self._ui.previousLocationLabel.setText(location)
            self._ui.localLineEdit.setText(location)

    def _workspaceChanged(self, text):
        pass

    def _localLocationEdited(self):
        self.validate()

    def localLocation(self):
        return self._ui.localLineEdit.text()

    def validate(self):
        identifierValid = len(self._ui.identifierLineEdit.text()) > 0
        localValid = os.path.exists(self._ui.localLineEdit.text())
        valid = identifierValid

        self._ui.buttonBox.button(QDialogButtonBox.Ok).setEnabled(valid)

        if identifierValid:
            self._ui.identifierLineEdit.setStyleSheet(DEFAULT_STYLE_SHEET)
        else:
            self._ui.identifierLineEdit.setStyleSheet(REQUIRED_STYLE_SHEET)

        return valid and localValid
コード例 #2
0
class ConfigureDialog(QDialog):
    """
    Configure dialog to present the user with the options to configure this step.
    """
    def __init__(self, state, parent=None):
        QDialog.__init__(self, parent)
        self._ui = Ui_ConfigureDialog()
        self._ui.setupUi(self)
        self._setupPMRTab()
        self._workflow_location = None

        self.setState(state)

        self._makeConnections()

    def _makeConnections(self):
        self._ui.identifierLineEdit.textChanged.connect(self.validate)
        self._ui.localLineEdit.textChanged.connect(self._localLocationEdited)
        self._ui.localButton.clicked.connect(self._localLocationClicked)
        self._pmr_widget._ui.lineEditWorkspace.textChanged.connect(
            self._workspaceChanged)
#         self._ui.pmrRegisterLabel.linkActivated.connect(self._register)

    def _setupPMRTab(self):
        self._pmr_widget = PMRWorkflowWidget(self)
        self._pmr_widget.setImport(False)
        self._pmr_widget.setExport(False)
        self._pmr_widget.setSearchDomain(
            [ontological_search_string, plain_text_search_string])

        layout = self._ui.pmrTab.layout()
        layout.addWidget(self._pmr_widget)

    def setState(self, state):
        self._ui.identifierLineEdit.setText(state._identifier)
        self._ui.localLineEdit.setText(state._local_location)
        self._pmr_widget.setWorkspaceUrl(state._pmr_location)
        self._ui.imageSourceTypeComboBox.setCurrentIndex(state._image_type)
        self._ui.tabWidget.setCurrentIndex(state._current_tab)
        self._ui.previousLocationLabel.setText(state._previous_local_location)

    def getState(self):
        state = ConfigureDialogState(
            self._ui.identifierLineEdit.text(), self._ui.localLineEdit.text(),
            self._pmr_widget.workspaceUrl(),
            self._ui.imageSourceTypeComboBox.currentIndex(),
            self._ui.tabWidget.currentIndex(),
            self._ui.previousLocationLabel.text())

        return state

    def _localLocationClicked(self):
        location = QFileDialog.getExistingDirectory(
            self, 'Select Image File(s) Location',
            self._ui.previousLocationLabel.text())

        if location:
            self._ui.previousLocationLabel.setText(location)
            self._ui.localLineEdit.setText(
                os.path.relpath(location, self._workflow_location))

    def _workspaceChanged(self, text):
        pass

    def setWorkflowLocation(self, location):
        self._workflow_location = location

    def _localLocationEdited(self):
        self.validate()

    def localLocation(self):
        return self._ui.localLineEdit.text()

    def validate(self):
        identifierValid = len(self._ui.identifierLineEdit.text()) > 0
        localValid = self._ui.localLineEdit.text() and \
            os.path.exists(os.path.join(self._workflow_location, self._ui.localLineEdit.text()))
        valid = identifierValid

        self._ui.buttonBox.button(QDialogButtonBox.Ok).setEnabled(valid)

        if identifierValid:
            self._ui.identifierLineEdit.setStyleSheet(DEFAULT_STYLE_SHEET)
        else:
            self._ui.identifierLineEdit.setStyleSheet(REQUIRED_STYLE_SHEET)

        return valid and localValid