Commit 91055344 authored by Cage, Marshall Andrew's avatar Cage, Marshall Andrew
Browse files

Fix #6 plugin loading

Plugins weren't being held by their packages, just by their names.
I fixed this by mapping package names to plugin names and nice
names. The PreferenceManager has been updated to search for the
appropriate plugin name. Plugin real names can be duplicated in
different packages.

- Fix missing config file behaviour
- Remove misc debug prints
- Add folder path preference to document plugin
- Change PluginSelectDialog to show nice plugin names
- Add support for real *or* nice names in most PSD functions
parent df70a8d7
......@@ -37,7 +37,7 @@ class PluginSelectDialog(QDialog):
)
self.setWindowTitle("Select Plugin")
# PluginSelectDialog.updatePackageList()
PluginSelectDialog.updatePackageList()
PluginSelectDialog.updatePluginList()
PluginSelectDialog.ui.packageList.setCurrentRow(0)
PluginSelectDialog.__init = True
......@@ -47,7 +47,6 @@ class PluginSelectDialog(QDialog):
# Also create an entry in the pluginInfo list for each package's plugins
@staticmethod
def updatePackageList():
print(PluginSelectDialog.parent.packages)
PluginSelectDialog.packageInfo = sorted(
PluginSelectDialog.parent.packages)
PluginSelectDialog.ui.packageList.clear()
......@@ -55,8 +54,8 @@ class PluginSelectDialog(QDialog):
for p in PluginSelectDialog.packageInfo:
PluginSelectDialog.packageIndices[p.name] = len(
PluginSelectDialog.packageIndices)
PluginSelectDialog.pluginInfo[p.name] = []
PluginSelectDialog.ui.packageList.addItems(p.getName())
PluginSelectDialog.pluginInfo[p.name] = {}
PluginSelectDialog.ui.packageList.addItem(p.getName())
# Load all plugins and store them according to their package
@staticmethod
......@@ -86,7 +85,7 @@ class PluginSelectDialog(QDialog):
PluginSelectDialog.ui.pluginList.clear()
PluginSelectDialog.ui.pluginList.addItems(
[
PluginSelectDialog.pluginInfo[m].getName()
PluginSelectDialog.pluginInfo[package.name][m].getName()
for m in package.getPluginNames()
if m in PluginSelectDialog.pluginInfo[package.name]
]
......@@ -141,8 +140,6 @@ class PluginSelectDialog(QDialog):
@staticmethod
def getPackageNames(real=False):
if real:
print('realll')
print([p.name for p in PluginSelectDialog.packageInfo])
return [p.name for p in PluginSelectDialog.packageInfo]
else:
return [p.getName() for p in PluginSelectDialog.packageInfo]
......@@ -151,7 +148,6 @@ class PluginSelectDialog(QDialog):
# If you want the real names, get them from a package object
@staticmethod
def getPluginNames(package,real=False):
print(package)
if real and package in PluginSelectDialog.packageIndices:
return PluginSelectDialog.packageInfo[
PluginSelectDialog.packageIndices[package]
......
......@@ -26,19 +26,26 @@ class PreferenceManager(QDialog):
PreferenceManager.ui.treeWidget.currentItemChanged.connect(
PreferenceManager.updateForm
)
print('a')
for k in sorted(PSD.getPackageNames(True)):
print(k)
PreferenceManager.preferences[k] = {
'':PSD.getPackage(k).preferenceDict or {}
}
twi = QTreeWidgetItem()
twi.setText(0,k)
# this sub map maps the nice names back up to the real names
# for convenience. Should the same be done for packages?
# consequentially this means plugins cannot be called '_'
PreferenceManager.preferences[k]['_'] = {}
for m in sorted(PSD.getPluginNames(k,True)):
PreferenceManager.preferences[k][m] =\
PSD.getPluginInfo(k,m).getPreferenceDict()
plugin = PSD.getPluginInfo(k,m)
PreferenceManager.preferences[k][m] = (
plugin.getPreferenceDict())
PreferenceManager.preferences[k]['_'][plugin.getName()] = (
PreferenceManager.preferences[k][m])
child = QTreeWidgetItem()
child.setText(0,m)
child.setText(0,plugin.getName())
twi.addChild(child)
PreferenceManager.ui.treeWidget.addTopLevelItem(twi)
......@@ -77,8 +84,9 @@ class PreferenceManager(QDialog):
package = None
if child:
package = PreferenceManager.preferences[item.parent().text(0)]\
[item.text(0)]
package = (PreferenceManager.preferences[item.parent().text(0)]
['_']
[item.text(0)])
else:
package = PreferenceManager.preferences[item.text(0)]['']
PreferenceManager.ui.formWidget.setParent(None)
......@@ -160,8 +168,9 @@ class PreferenceManager(QDialog):
child = True if item.parent() else False
if child:
package = PreferenceManager.preferences[item.parent().text(0)]\
[item.text(0)]
package = (PreferenceManager.preferences[item.parent().text(0)]
['_']
[item.text(0)])
else:
package = PreferenceManager.preferences[item.text(0)]['']
......@@ -182,6 +191,8 @@ class PreferenceManager(QDialog):
prefs = ''
for p in PreferenceManager.preferences:
for s in PreferenceManager.preferences[p]:
if s == '_':
continue
for k in sorted(PreferenceManager.preferences[p][s].keys()):
params = PreferenceManager.preferences[p][s][k]
# print(params['type'])
......@@ -244,4 +255,4 @@ class PreferenceManager(QDialog):
if data['placeholder'] != '' else None,
'tooltip': data['tooltip']\
if data['tooltip'] != '' else None
}
\ No newline at end of file
}
......@@ -37,6 +37,7 @@ class ARCTool(QMainWindow):
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.makeConfig = False
self.checkFileSystem()
......@@ -124,6 +125,8 @@ class ARCTool(QMainWindow):
# Preference Dialog
self.preferenceDialog = ARCP.PreferenceManager(self)
self.ui.actionPreferences.triggered.connect(self.preferenceDialog.exec)
if self.makeConfig:
self.preferenceDialog.savePreferences()
# Import package file browser
self.ui.actionImport_Package.triggered.connect(self.openPackageArchive)
......@@ -541,13 +544,16 @@ class ARCTool(QMainWindow):
self.storagePath = os.path.join(self.storagePath, 'arctool')
os.makedirs(self.storagePath, 0o777, True)
os.makedirs(os.path.join(self.storagePath, "packages"), 0o777, True)
open(os.path.join(self.storagePath, "config"), 'a').close()
try:
open(os.path.join(self.storagePath, "config"), 'r').close()
except OSError:
self.makeConfig = True
sys.path.append(os.path.dirname(__file__))
# Add package directories so packages can include local Python plugins
sys.path.append(os.path.join(self.storagePath, "packages"))
sys.path.append(os.path.join(os.path.dirname(__file__), "packages"))
def loadPackages(self):
packagePaths = []
......@@ -573,9 +579,6 @@ class ARCTool(QMainWindow):
for m in package.getPluginNames():
self.plugins[m] = package
print(self.packages)
# ARCG.PluginSelectDialog.updatePluginList()
def generateReport(self):
self.ui.statusBar.showMessage("Generating Report...")
self.ui.exportReport.setEnabled(False)
......
from arctool import ARCTool
from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtCore import QUrl, Qt, QStandardPaths
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from arc.arcpreferences import PreferenceManager as PM
import arc.arcclasses as arcclasses
import arc.arcgui as arcgui
import pypandoc
......@@ -22,6 +23,17 @@ class Plugin(arcclasses.Plugin):
self.contexts = []
self.path = ''
self.preferenceDict = {
'defaultpath' : {
'label':'Default document path',
'placeholder':QStandardPaths.standardLocations(
QStandardPaths.DocumentsLocation)[0],
'default':QStandardPaths.standardLocations(
QStandardPaths.DocumentsLocation)[0],
'type':'string',
'tooltip':'Default path to document folder.'
},
}
#needed
def setupUi(self):
......@@ -64,7 +76,8 @@ class Plugin(arcclasses.Plugin):
def getPath(self):
path = QFileDialog.getOpenFileName(
None,"Choose Document",'',
None,"Choose Document",
PM.getPreference('Default Package','defaultpath',self.__name__),
("OpenDocument Text (*.odt);;OpenDocument XML (*.opml);;"
+ "Microsoft Word Document 2007/2010/2013 (*.docx);;"
+ "HTML (*.html);;LaTeX (*.latex);; EPUB (*.epub);;"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment