-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create basic package manager to allow for external packages to be added.
- Loading branch information
Showing
12 changed files
with
434 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
75 changes: 75 additions & 0 deletions
75
src/mapclient/view/managers/package/packagemanagerdialog.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.