class ImportWorkflowDialog(QtGui.QDialog): ''' classdocs ''' def __init__(self, previousLocation, parent=None): ''' Constructor ''' super(ImportWorkflowDialog, self).__init__(parent) self._ui = Ui_ImportWorkflowDialog() self._ui.setupUi(self) self._setupPMRWidget() self._previousLocation = previousLocation self._makeConnections() def _makeConnections(self): self._ui.pushButtonLocation.clicked.connect(self._setDestination) def _setupPMRWidget(self): self._pmr_widget = PMRWorkflowWidget(self) self._pmr_widget.setExport(False) self._pmr_widget.setImport(False) self._pmr_widget.setSearchDomain(workflow_search_string) layout = self.layout() # Save a little time by setting the layout disabled while # the layout is being de-constructed and constructed again. layout.setEnabled(False) # Remove the existing items in the layout existing_items = [] for index in range(layout.count(), 0, -1): existing_items.append(layout.takeAt(index - 1)) # Put all the items into the layout in the desired order layout.addWidget(self._pmr_widget) existing_items.reverse() for item in existing_items: layout.addItem(item) layout.setEnabled(True) def destinationDir(self): return self._ui.lineEditLocation.text() def workspaceUrl(self): return self._pmr_widget.workspaceUrl() def _setDestination(self): workflowDir = QtGui.QFileDialog.getExistingDirectory(self, caption='Select Workflow Directory', directory=self._previousLocation) if workflowDir: self._ui.lineEditLocation.setText(workflowDir)
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
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
class ImportWorkflowDialog(QtWidgets.QDialog): def __init__(self, previousLocation, parent=None): super(ImportWorkflowDialog, self).__init__(parent) self._ui = Ui_ImportWorkflowDialog() self._ui.setupUi(self) self._setupPMRWidget() self._previousLocation = previousLocation self._makeConnections() def _makeConnections(self): self._ui.lineEditLocation.returnPressed.connect(self._setDestination) self._ui.pushButtonLocation.clicked.connect(self._setDestination) def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Return: return True return QtWidgets.QDialog.keyPressEvent(self, event) def _setupPMRWidget(self): om = self.parent().model().optionsManager() use_external_git = om.getOption(USE_EXTERNAL_GIT) self._pmr_widget = PMRWorkflowWidget(use_external_git, self) self._pmr_widget.setExport(False) self._pmr_widget.setImport(False) self._pmr_widget.setSearchDomain(workflow_search_string) self._pmr_widget._ui.lineEditSearch.setFocus() self._pmr_widget._ui.lineEditSearch.returnPressed.connect( self._pmr_widget._searchClicked) layout = self.layout() # Save a little time by setting the layout disabled while # the layout is being de-constructed and constructed again. layout.setEnabled(False) # Remove the existing items in the layout existing_items = [] for index in range(layout.count(), 0, -1): existing_items.append(layout.takeAt(index - 1)) # Put all the items into the layout in the desired order layout.addWidget(self._pmr_widget) existing_items.reverse() for item in existing_items: layout.addItem(item) layout.setEnabled(True) def destinationDir(self): return self._ui.lineEditLocation.text() def workspaceUrl(self): return self._pmr_widget.workspaceUrl() def accept(self, *args, **kwargs): destination_dir = self.destinationDir() workspace_url = self.workspaceUrl() if os.path.exists(destination_dir) and workspace_url: return QtWidgets.QDialog.accept(self, *args, **kwargs) else: QtWidgets.QMessageBox.critical(self, 'Error Caught', "Invalid Import Settings. Either the workspace url '%s' was not set" \ " or the destination directory '%s' does not exist. " % (workspace_url, destination_dir)) def _setDestination(self): workflowDir = QtWidgets.QFileDialog.getExistingDirectory( self, caption='Select Workflow Directory', directory=self._previousLocation) if workflowDir: self._ui.lineEditLocation.setText(workflowDir)