Skip to content

Commit

Permalink
Create basic package manager to allow for external packages to be added.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsorby committed May 3, 2021
1 parent b0032b3 commit 3661346
Show file tree
Hide file tree
Showing 12 changed files with 434 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lib64/
parts/
sdist/
var/
package/
#package/ # We are using this name in the source hopefully doesn't come back to bite us.
*.egg-info/
.installed.cfg
*.egg
Expand Down
13 changes: 3 additions & 10 deletions res/pyinstaller/create_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,21 @@
'-n', 'MAPClient',
'--windowed',
'--noconfirm',
'--hidden-import', 'scipy',
'--hidden-import', 'scipy.interpolate',
'--hidden-import', 'numpy',
'--hidden-import', 'mapclientplugins',
'--hidden-import', 'opencmiss.utils',
'--hidden-import', 'opencmiss.zincwidgets',
f'--additional-hooks-dir=hooks',
]


print('[[[[[[[[[[[[[[[[')
print(collect_data_files('mapclient', includes=['*.png']))
images_dir = os.path.join('..', '..', 'src', 'mapclient', 'tools', 'pluginwizard', 'qt', 'images')
names = os.listdir(images_dir)
for name in names:
data = os.pathsep.join([os.path.join(os.path.abspath(images_dir), name), os.path.join('res', 'images')])
run_command.append(f'--add-data={data}')
print(names)
print(os.pathsep)
# for d in opencmiss.__path__:
# run_command.append(f'--path={d}')
#
# for d in mapclientplugins.__path__:
# run_command.append(f'--path={d}')

if platform.system() == 'Darwin':
pyside_dir = os.path.dirname(RefMod.__file__)
Expand All @@ -47,4 +41,3 @@

print('Running command: ', run_command)
PyInstaller.__main__.run(run_command)
# mapclient/application.py -n MAPClient --hidden-import opencmiss.zinc --windowed -i ../res/win/MAP-Client.ico --hidden-import opencmiss
3 changes: 3 additions & 0 deletions src/mapclient/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def windows_main(app_args):
if not window.check_application_setup():
window._show_options_dialog(current_tab=1)

window.load_packages()
window.load_plugins()

if app_args.workflow:
Expand Down Expand Up @@ -167,7 +168,9 @@ def non_gui_main(app_args):

wm = model.workflowManager()
pm = model.pluginManager()
pam = model.package_manager()

pam.load()
pm.load()
try:
wm.load(app_args.workflow)
Expand Down
7 changes: 7 additions & 0 deletions src/mapclient/core/mainapplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from mapclient.core.managers.workflowmanager import WorkflowManager
from mapclient.core.managers.undomanager import UndoManager
from mapclient.core.managers.packagemanager import PackageManager
from mapclient.core.managers.pluginmanager import PluginManager
from mapclient.core.managers.optionsmanager import OptionsManager
from mapclient.core.checks import runChecks
Expand All @@ -40,6 +41,7 @@ def __init__(self):
self._size = QtCore.QSize(600, 400)
self._pos = QtCore.QPoint(100, 150)
self._pluginManager = PluginManager()
self._package_manager = PackageManager()
self._workflowManager = WorkflowManager(self)
self._undoManager = UndoManager()
self._optionsManager = OptionsManager()
Expand Down Expand Up @@ -68,6 +70,9 @@ def workflowManager(self):
def pluginManager(self):
return self._pluginManager

def package_manager(self):
return self._package_manager

def optionsManager(self):
return self._optionsManager

Expand All @@ -84,6 +89,7 @@ def writeSettings(self):
self._pluginManager.writeSettings(settings)
self._workflowManager.writeSettings(settings)
self._optionsManager.writeSettings(settings)
self._package_manager.write_settings(settings)

def readSettings(self):
settings = QtCore.QSettings()
Expand All @@ -94,3 +100,4 @@ def readSettings(self):
self._pluginManager.readSettings(settings)
self._workflowManager.readSettings(settings)
self._optionsManager.readSettings(settings)
self._package_manager.read_settings(settings)
55 changes: 55 additions & 0 deletions src/mapclient/core/managers/packagemanager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import sys


"""
Class for managing external packages.
Adding package directories to the Python search path.
"""
class PackageManager(object):

def __init__(self):
self._directories = []
self._modified = False

def directories(self):
return self._directories

def set_directories(self, directories):
if self._directories != directories:
self._modified = True
self._directories = directories

def is_modified(self):
return self._modified

def load(self):
modified = False
for directory in self._directories:
if directory not in sys.path:
sys.path.append(directory)
modified = True

self._modified = False
return modified

def read_settings(self, settings):
self._directories = []
settings.beginGroup('Packages')
directory_count = settings.beginReadArray('directories')
for i in range(directory_count):
settings.setArrayIndex(i)
self._directories.append(settings.value('directory'))
settings.endArray()
settings.endGroup()

def write_settings(self, settings):
settings.beginGroup('Packages')
settings.beginWriteArray('directories')
directory_index = 0
for directory in self._directories:
settings.setArrayIndex(directory_index)
settings.setValue('directory', directory)
directory_index += 1
settings.endArray()
settings.endGroup()
28 changes: 26 additions & 2 deletions src/mapclient/view/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def _setup_menus(self):
self._action_Quit.setObjectName("action_Quit")
self._action_PluginManager = QtWidgets.QAction(self)
self._action_PluginManager.setObjectName("action_PluginManager")
self._action_PackageManager = QtWidgets.QAction(self)
self._action_PackageManager.setObjectName("action_PackageManager")
self._action_PMR = QtWidgets.QAction(self)
self._action_PMR.setObjectName("action_PMR")
self._action_RenamePlugin = QtWidgets.QAction(self)
Expand All @@ -113,6 +115,7 @@ def _setup_menus(self):
self._menu_File.addSeparator()
self._menu_File.addAction(self._action_Quit)
self._menu_Tools.addAction(self._action_PluginManager)
self._menu_Tools.addAction(self._action_PackageManager)
self._menu_Tools.addAction(self._action_PluginWizard)
self._menu_Tools.addAction(self._action_PMR)
self._menu_Tools.addAction(self._action_RenamePlugin)
Expand Down Expand Up @@ -149,6 +152,7 @@ def _re_translate_ui(self):
"Change global application options",
None, -1))
self._action_PluginManager.setText(QtWidgets.QApplication.translate("MainWindow", "Plugin &Manager", None, -1))
self._action_PackageManager.setText(QtWidgets.QApplication.translate("MainWindow", "Package Ma&nager", None, -1))
self._action_PMR.setText(QtWidgets.QApplication.translate("MainWindow", "&PMR", None, -1))
self._action_Annotation.setText(QtWidgets.QApplication.translate("MainWindow", "&Annotation", None, -1))
self._action_PluginWizard.setText(QtWidgets.QApplication.translate("MainWindow", "Plugin Wi&zard", None, -1))
Expand Down Expand Up @@ -189,6 +193,7 @@ def _make_connections(self):
self._action_LogInformation.triggered.connect(self._show_log_information_dialog)
self._action_Options.triggered.connect(self._show_options_dialog)
self._action_PluginManager.triggered.connect(self._show_plugin_manager_dialog)
self._action_PackageManager.triggered.connect(self._show_package_manager_dialog)
self._action_PluginWizard.triggered.connect(self._show_plugin_wizard_dialog)
self._action_PMR.triggered.connect(self._show_pmr_tool)
self._action_Annotation.triggered.connect(self._show_annotation_tool)
Expand All @@ -211,6 +216,10 @@ def setup_application():
def get_menu_bar(self):
return self._menu_bar

def load_packages(self):
pm = self._model.package_manager()
pm.load()

def load_plugins(self):
pm = self._model.pluginManager()

Expand Down Expand Up @@ -259,11 +268,12 @@ def current_widget(self):
def closeEvent(self, event):
self.quit_application()

def _maybe_restart_application(self):
def _maybe_restart_application(self, asker='plugins'):
QtWidgets.QMessageBox.warning(self,
'Change detected',
'A change in the plugins has been detected, you may have to restart the appplication to see the effect.',
f'A change in the {asker} has been detected, you may have to restart the appplication to see the effect.',
QtWidgets.QMessageBox.Ok)

def confirm_close(self):
# Check to see if the Workflow is in a saved state.
if self._model.workflowManager().isModified():
Expand Down Expand Up @@ -313,6 +323,20 @@ def _show_options_dialog(self, current_tab=0):
self._action_PMR.setEnabled(dlg.checkedOk(PMR_TOOL_STRING))
self._workflowWidget.applyOptions()

def _show_package_manager_dialog(self):
from mapclient.view.managers.package.packagemanagerdialog import PackageManagerDialog
pm = self._model.package_manager()

dlg = PackageManagerDialog(self)
dlg.set_directories(pm.directories())
dlg.setModal(True)
if dlg.exec_():
pm.set_directories(dlg.directories())
if pm.is_modified():
pm.load()
self._maybe_restart_application(asker='packages')


def _show_plugin_manager_dialog(self):
from mapclient.view.managers.plugins.pluginmanagerdialog import PluginManagerDialog
pm = self._model.pluginManager()
Expand Down
Empty file.
75 changes: 75 additions & 0 deletions src/mapclient/view/managers/package/packagemanagerdialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"""
MAP Client, a program to generate detailed musculoskeletal models for OpenSim.
Copyright (C) 2012 University of Auckland
This file is part of MAP Client. (http://launchpad.net/mapclient)
MAP Client is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MAP Client is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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

from PySide2 import QtWidgets
from mapclient.view.managers.package.ui.ui_packagemanagerdialog import Ui_PackageManagerDialog


class PackageManagerDialog(QtWidgets.QDialog):
"""
Dialog for managing the list of plugin directories.
"""

def __init__(self, parent=None):
QtWidgets.QDialog.__init__(self, parent)
self._ui = Ui_PackageManagerDialog()
self._ui.setupUi(self)
self._ui.removeButton.setEnabled(False)

self._make_connections()

def _make_connections(self):
self._ui.addButton.clicked.connect(self._add_directory_clicked)
self._ui.directoryListing.itemSelectionChanged.connect(self._directory_selection_changed)
self._ui.removeButton.clicked.connect(self._remove_button_clicked)

def _directory_selection_changed(self):
self._ui.removeButton.setEnabled(len(self._ui.directoryListing.selectedItems()) > 0)

def _remove_button_clicked(self):
for item in self._ui.directoryListing.selectedItems():
self._ui.directoryListing.takeItem(self._ui.directoryListing.row(item))

def _add_directory_clicked(self):
selected_items = self._ui.directoryListing.selectedItems()
last = ''
if selected_items:
last_selected_item = selected_items[-1]
last = last_selected_item
else:
last = self._ui.directoryListing.item(self._ui.directoryListing.count() - 1)

if last:
last = last.text()

directory = QtWidgets.QFileDialog.getExistingDirectory(self, caption='Select Package Directory', dir=last, options=QtWidgets.QFileDialog.ShowDirsOnly | QtWidgets.QFileDialog.DontResolveSymlinks | QtWidgets.QFileDialog.ReadOnly)
if len(directory) > 0:
self._ui.directoryListing.addItem(directory)

def set_directories(self, directories):
self._ui.directoryListing.addItems([directory for directory in directories if os.path.exists(directory)])

def directories(self):
directories = []
for index in range(self._ui.directoryListing.count()):
directories.append(self._ui.directoryListing.item(index).text())

return directories
Loading

0 comments on commit 3661346

Please sign in to comment.