Skip to content

Commit

Permalink
Move PMR workflow menu actions to PMR tool
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalemink committed Oct 2, 2023
1 parent 2da3024 commit c7615ae
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 71 deletions.
10 changes: 8 additions & 2 deletions src/mapclient/tools/pmr/dialogs/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"""
from PySide6 import QtWidgets

from mapclient.settings.definitions import USE_EXTERNAL_GIT
from mapclient.tools.pmr.widgets.workspacewidget import WorkspaceWidget
from mapclient.tools.pmr.settings.general import PMR
from mapclient.tools.pmr.pmrtool import PMRTool
from mapclient.tools.pmr.authoriseapplicationdialog import AuthoriseApplicationDialog
Expand All @@ -27,13 +29,17 @@

class PMRRegisterDialog(QtWidgets.QDialog):

def __init__(self, external_git, parent=None):
def __init__(self, workflow_widget, parent=None):
super(PMRRegisterDialog, self).__init__(parent)
self._ui = Ui_RegisterDialog()
self._ui.setupUi(self)

self._workspace_widget = WorkspaceWidget(workflow_widget)
self._ui.workspaceTab.layout().addWidget(self._workspace_widget)

pmr_info = PMR()
self._pmr_tool = PMRTool(pmr_info, external_git)
om = workflow_widget.model().optionsManager()
self._pmr_tool = PMRTool(pmr_info, om.getOption(USE_EXTERNAL_GIT))

self._makeConnections()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@
You should have received a copy of the GNU General Public License
along with MAP Client. If not, see <http://www.gnu.org/licenses/>..
"""
import os.path

from PySide6 import QtWidgets, QtCore

from mapclient.settings.definitions import USE_EXTERNAL_GIT
from mapclient.view.ui.ui_importworkflowdialog import Ui_ImportWorkflowDialog
from mapclient.tools.pmr.ui.ui_importworkflowdialog import Ui_ImportWorkflowDialog
from mapclient.tools.pmr.pmrworkflowwidget import PMRWorkflowWidget
from mapclient.tools.pmr.pmrtool import workflow_search_string
import os.path


class ImportWorkflowDialog(QtWidgets.QDialog):

def __init__(self, previousLocation, parent=None):
def __init__(self, previous_location, use_external_git, parent=None):
super(ImportWorkflowDialog, self).__init__(parent)
self._ui = Ui_ImportWorkflowDialog()
self._ui.setupUi(self)
self._setupPMRWidget()

self._previousLocation = previousLocation
self._previousLocation = previous_location
self._use_external_git = use_external_git

self._setupPMRWidget()
self._makeConnections()

def _makeConnections(self):
Expand All @@ -48,9 +49,7 @@ def keyPressEvent(self, event):
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 = PMRWorkflowWidget(self._use_external_git, self)
self._pmr_widget.setExport(False)
self._pmr_widget.setImport(False)
self._pmr_widget.setSearchDomain(workflow_search_string)
Expand Down Expand Up @@ -88,7 +87,7 @@ def accept(self, *args, **kwargs):
" 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)
workflowDir = QtWidgets.QFileDialog.getExistingDirectory(self, caption='Select Workflow Directory', dir=self._previousLocation)
if workflowDir:
self._ui.lineEditLocation.setText(workflowDir)

Expand Down
6 changes: 6 additions & 0 deletions src/mapclient/tools/pmr/qt/registerdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="workspaceTab">
<attribute name="title">
<string>Workspace</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_6"/>
</widget>
</widget>
</item>
<item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'importworkflowdialog.ui'
##
## Created by: Qt User Interface Compiler version 6.4.2
## Created by: Qt User Interface Compiler version 6.5.1
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand Down
8 changes: 7 additions & 1 deletion src/mapclient/tools/pmr/ui/ui_registerdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
################################################################################
## Form generated from reading UI file 'registerdialog.ui'
##
## Created by: Qt User Interface Compiler version 6.4.1
## Created by: Qt User Interface Compiler version 6.5.1
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
Expand Down Expand Up @@ -121,6 +121,11 @@ def setupUi(self, RegisterDialog):
self.horizontalLayout_5.addWidget(self.settingsWidget)

self.tabWidget.addTab(self.settingsTab, "")
self.workspaceTab = QWidget()
self.workspaceTab.setObjectName(u"workspaceTab")
self.verticalLayout_6 = QVBoxLayout(self.workspaceTab)
self.verticalLayout_6.setObjectName(u"verticalLayout_6")
self.tabWidget.addTab(self.workspaceTab, "")

self.verticalLayout.addWidget(self.tabWidget)

Expand Down Expand Up @@ -150,5 +155,6 @@ def retranslateUi(self, RegisterDialog):
self.pushButtonDeregister.setText(QCoreApplication.translate("RegisterDialog", u"&Deregister", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.registerTab), QCoreApplication.translate("RegisterDialog", u"Register", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.settingsTab), QCoreApplication.translate("RegisterDialog", u"Settings", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.workspaceTab), QCoreApplication.translate("RegisterDialog", u"Workspace", None))
# retranslateUi

90 changes: 90 additions & 0 deletions src/mapclient/tools/pmr/widgets/workspacewidget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import os
import logging

from PySide6 import QtWidgets

from mapclient.settings.definitions import USE_EXTERNAL_GIT
from mapclient.core.workflow.workflowerror import WorkflowError
from mapclient.view.utils import set_wait_cursor
from mapclient.view.utils import handle_runtime_error
from mapclient.tools.pmr.settings.general import PMR
from mapclient.tools.pmr.pmrtool import PMRTool
from mapclient.tools.pmr.importworkflowdialog import ImportWorkflowDialog

logger = logging.getLogger(__name__)


class WorkspaceWidget(QtWidgets.QWidget):

def __init__(self, workflow_widget, parent=None):
super().__init__(parent)

self._workflow_widget = workflow_widget
self._use_external_git = workflow_widget

self._setup_ui()
self._make_connections()

def _setup_ui(self):
self._import_button = QtWidgets.QPushButton("Import")
import_layout = QtWidgets.QHBoxLayout()
import_layout.addWidget(self._import_button)
import_layout.addStretch(1)

self._update_button = QtWidgets.QPushButton("Update")
self._update_button.setEnabled(False)
update_layout = QtWidgets.QHBoxLayout()
update_layout.addWidget(self._update_button)
update_layout.addStretch(1)

layout = QtWidgets.QVBoxLayout()
layout.addLayout(import_layout)
layout.addLayout(update_layout)
layout.addStretch(1)
self.setLayout(layout)

def _make_connections(self):
self._import_button.clicked.connect(self.import_from_pmr)
self._update_button.clicked.connect(self.update_from_pmr)

def import_from_pmr(self):
m = self._workflow_widget.model().workflowManager()
dlg = ImportWorkflowDialog(m.previousLocation(), self._use_external_git, self)

if dlg.exec():
destination_dir = dlg.destinationDir()
workspace_url = dlg.workspaceUrl()
if os.path.exists(destination_dir) and workspace_url:
try:
self._clone_from_pmr(workspace_url, destination_dir)
logger.info('Perform workflow checks on import ...')
self._workflow_widget.performWorkflowChecks(destination_dir)
self._workflow_widget._load(destination_dir)
except (ValueError, WorkflowError) as e:
logger.error('Invalid Workflow. ' + str(e))
QtWidgets.QMessageBox.critical(self, 'Error Caught', 'Invalid Workflow. ' + str(e))

def update_from_pmr(self):
self._update_from_pmr()

@handle_runtime_error
@set_wait_cursor
def _update_from_pmr(self):
m = self._workflow_widget.model().workflowManager()
om = self._workflow_widget.model().optionsManager()
pmr_info = PMR()
pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT))

pmr_tool.pullFromRemote(m.location())

@handle_runtime_error
@set_wait_cursor
def _clone_from_pmr(self, workspace_url, workflow_dir):
om = self._workflow_widget.model().optionsManager()
pmr_info = PMR()
pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT))

pmr_tool.cloneWorkspace(
remote_workspace_url=workspace_url,
local_workspace_dir=workflow_dir,
)
5 changes: 2 additions & 3 deletions src/mapclient/view/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from mapclient.settings.info import DEFAULT_WORKFLOW_ANNOTATION_FILENAME
from mapclient.settings.definitions import WIZARD_TOOL_STRING, METRICS_PERMISSION, \
PMR_TOOL_STRING, PYSIDE_RCC_EXE, USE_EXTERNAL_RCC, PYSIDE_UIC_EXE, USE_EXTERNAL_UIC, \
PREVIOUS_PW_WRITE_STEP_LOCATION, PREVIOUS_PW_ICON_LOCATION, USE_EXTERNAL_GIT, METRICS_PERMISSION_ATTAINED, METRICS_CLIENT_ID
PREVIOUS_PW_WRITE_STEP_LOCATION, PREVIOUS_PW_ICON_LOCATION, METRICS_PERMISSION_ATTAINED, METRICS_CLIENT_ID
from mapclient.view.utils import set_wait_cursor
from mapclient.core.metrics import get_metrics_logger

Expand Down Expand Up @@ -528,9 +528,8 @@ def _show_update_workflow_dialog(self):
dlg.exec_()

def _show_pmr_tool(self):
om = self._model.optionsManager()
from mapclient.tools.pmr.dialogs.register import PMRRegisterDialog
dlg = PMRRegisterDialog(om.getOption(USE_EXTERNAL_GIT), self)
dlg = PMRRegisterDialog(self._workflowWidget, self)
dlg.setModal(True)
dlg.exec_()

Expand Down
57 changes: 3 additions & 54 deletions src/mapclient/view/workflow/workflowwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from mapclient.view.workflow.ui.ui_workflowwidget import Ui_WorkflowWidget
from mapclient.view.workflow.workflowgraphicsscene import WorkflowGraphicsScene
from mapclient.tools.pmr.pmrtool import PMRTool
from mapclient.view.importworkflowdialog import ImportWorkflowDialog
from mapclient.view.managers.plugins.pluginupdater import PluginUpdater
from mapclient.tools.pmr.settings.general import PMR
from mapclient.settings.general import get_virtualenv_directory
Expand Down Expand Up @@ -94,6 +93,9 @@ def _make_connections(self):
self._ui.executeButton.clicked.connect(self.executeWorkflow)
self._undoStack.indexChanged.connect(self.undoStackIndexChanged)

def model(self):
return self._main_window.model()

def _filter_text_changed(self, text):
reg_exp = QtCore.QRegularExpression(text, QtCore.QRegularExpression.PatternOption.CaseInsensitiveOption)
self._ui.stepTreeView.setFilterRegularExpression(reg_exp)
Expand All @@ -115,8 +117,6 @@ def _update_ui(self):
self.action_Save.setEnabled(wfm.isModified() and widget_visible)
self.action_SaveAs.setEnabled(widget_visible)
self._action_annotation.setEnabled(workflow_open and widget_visible)
self.action_Import.setEnabled(widget_visible)
self.action_Update.setEnabled(workflow_tracked)
self.action_New.setEnabled(widget_visible)
self.action_NewPMR.setEnabled(widget_visible)
self.action_Open.setEnabled(widget_visible)
Expand Down Expand Up @@ -442,47 +442,6 @@ def performWorkflowChecks(self, workflow_dir):
self._main_window._show_plugin_errors_dialog()
self.updateStepTree()

def importFromPMR(self):
m = self._main_window.model().workflowManager()
dlg = ImportWorkflowDialog(m.previousLocation(), self._main_window)
if dlg.exec():
destination_dir = dlg.destinationDir()
workspace_url = dlg.workspaceUrl()
if os.path.exists(destination_dir) and workspace_url:
try:
self._cloneFromPMR(workspace_url, destination_dir)
logger.info('Perform workflow checks on import ...')
self.performWorkflowChecks(destination_dir)
self._load(destination_dir)
except (ValueError, WorkflowError) as e:
logger.error('Invalid Workflow. ' + str(e))
QtWidgets.QMessageBox.critical(self, 'Error Caught', 'Invalid Workflow. ' + str(e))

def updateFromPMR(self):
self._updateFromPMR()

@handle_runtime_error
@set_wait_cursor
def _updateFromPMR(self):
m = self._main_window.model().workflowManager()
om = self._main_window.model().optionsManager()
pmr_info = PMR()
pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT))

pmr_tool.pullFromRemote(m.location())

@handle_runtime_error
@set_wait_cursor
def _cloneFromPMR(self, workspace_url, workflowDir):
om = self._main_window.model().optionsManager()
pmr_info = PMR()
pmr_tool = PMRTool(pmr_info, use_external_git=om.getOption(USE_EXTERNAL_GIT))

pmr_tool.cloneWorkspace(
remote_workspace_url=workspace_url,
local_workspace_dir=workflowDir,
)

@handle_runtime_error
@set_wait_cursor
def _load(self, workflow_dir):
Expand Down Expand Up @@ -706,12 +665,6 @@ def _create_menu_items(self):
self.action_Export_CFG = QtGui.QAction('Export Config', menu_workflow)
self._set_action_properties(self.action_Export_CFG, 'action_Export_CFG', self.export_cfg, '',
'Export workflow configuration to file')
self.action_Import = QtGui.QAction('I&mport', menu_file)
self._set_action_properties(self.action_Import, 'action_Import', self.importFromPMR, 'Ctrl+M',
'Import existing Workflow from PMR')
self.action_Update = QtGui.QAction('&Update', menu_file)
self._set_action_properties(self.action_Update, 'action_Update', self.updateFromPMR, 'Ctrl+U',
'update existing PMR Workflow')
self.action_Close = QtGui.QAction('&Close', menu_file)
self._set_action_properties(self.action_Close, 'action_Close', self.close, 'Ctrl+W', 'Close open Workflow')
self.action_Save = QtGui.QAction('&Save', menu_file)
Expand Down Expand Up @@ -754,9 +707,6 @@ def _create_menu_items(self):
menu_file.insertAction(last_file_menu_action, self.action_Import_CFG)
menu_file.insertAction(last_file_menu_action, self.action_Export_CFG)
menu_file.insertSeparator(last_file_menu_action)
menu_file.insertAction(last_file_menu_action, self.action_Import)
menu_file.insertAction(last_file_menu_action, self.action_Update)
menu_file.insertSeparator(last_file_menu_action)
menu_file.insertAction(last_file_menu_action, self.action_Close)
menu_file.insertSeparator(last_file_menu_action)

Expand All @@ -769,4 +719,3 @@ def _create_menu_items(self):
# menu_workflow.addAction(self.action_Continue)
menu_workflow.addAction(self.action_Reverse)
menu_workflow.addAction(self.action_Abort)
menu_workflow.insertSeparator(last_view_menu_action)

0 comments on commit c7615ae

Please sign in to comment.