diff --git a/nw/gui/__init__.py b/nw/gui/__init__.py index d8842bcc..48896ba1 100644 --- a/nw/gui/__init__.py +++ b/nw/gui/__init__.py @@ -13,6 +13,7 @@ from nw.gui.dialogs.docsplit import GuiDocSplit from nw.gui.dialogs.export import GuiExport from nw.gui.dialogs.itemeditor import GuiItemEditor from nw.gui.dialogs.projecteditor import GuiProjectEditor +from nw.gui.dialogs.projectload import GuiProjectLoad from nw.gui.dialogs.sessionlog import GuiSessionLogView from nw.gui.dialogs.timelineview import GuiTimeLineView @@ -40,6 +41,7 @@ __all__ = [ "GuiExport", "GuiItemEditor", "GuiProjectEditor", + "GuiProjectLoad", "GuiSessionLogView", "GuiTimeLineView", "GuiDocDetails", diff --git a/nw/gui/dialogs/__init__.py b/nw/gui/dialogs/__init__.py index a58b4982..49b10df3 100644 --- a/nw/gui/dialogs/__init__.py +++ b/nw/gui/dialogs/__init__.py @@ -6,6 +6,7 @@ from nw.gui.dialogs.docsplit import GuiDocSplit from nw.gui.dialogs.export import GuiExport from nw.gui.dialogs.itemeditor import GuiItemEditor from nw.gui.dialogs.projecteditor import GuiProjectEditor +from nw.gui.dialogs.projectload import GuiProjectLoad from nw.gui.dialogs.sessionlog import GuiSessionLogView from nw.gui.dialogs.timelineview import GuiTimeLineView @@ -16,6 +17,7 @@ __all__ = [ "GuiExport", "GuiItemEditor", "GuiProjectEditor", + "GuiProjectLoad", "GuiSessionLogView", "GuiTimeLineView", ] diff --git a/nw/gui/dialogs/projectload.py b/nw/gui/dialogs/projectload.py new file mode 100644 index 00000000..9b075fbc --- /dev/null +++ b/nw/gui/dialogs/projectload.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +"""novelWriter GUI Open Project + + novelWriter – GUI Open Project +================================ + New and open project dialog + + File History: + Created: 2020-02-26 [0.4.5] + +""" + +import logging +import nw + +from PyQt5.QtCore import Qt +from PyQt5.QtWidgets import ( + QDialog, QHBoxLayout, QVBoxLayout, QGridLayout, QPushButton, QListWidget, + QAbstractItemView +) + +logger = logging.getLogger(__name__) + +class GuiProjectLoad(QDialog): + + def __init__(self, theParent): + QDialog.__init__(self, theParent) + + logger.debug("Initialising GuiProjectLoad ...") + + self.mainConf = nw.CONFIG + self.theParent = theParent + self.sourceItem = None + + self.outerBox = QHBoxLayout() + self.innerBox = QVBoxLayout() + self.setWindowTitle("Manage Projects") + self.setLayout(self.outerBox) + + self.guiDeco = self.theParent.theTheme.loadDecoration("nwicon", (128, 128)) + + self.outerBox.addWidget(self.guiDeco, 0, Qt.AlignTop) + self.outerBox.addLayout(self.innerBox) + + self.projectForm = QGridLayout() + self.projectForm.setContentsMargins(0, 0, 0, 0) + + self.listBox = QListWidget() + self.listBox.setDragDropMode(QAbstractItemView.NoDragDrop) + + self.closeButton = QPushButton("Close") + self.closeButton.clicked.connect(self._doClose) + + self.projectForm.addWidget(self.listBox, 0, 0, 1, 3) + self.projectForm.addWidget(self.closeButton, 1, 2) + + self.innerBox.addLayout(self.projectForm) + + self.rejected.connect(self._doClose) + self.setModal(True) + self.show() + + self._populateList() + + logger.debug("GuiProjectLoad initialisation complete") + + return + + ## + # Buttons + ## + + def _doClose(self): + """Close the dialog window without doing anything. + """ + logger.verbose("GuiProjectLoad close button clicked") + self.close() + return + + ## + # Internal Functions + ## + + def _populateList(self): + return + +# END Class GuiProjectLoad diff --git a/nw/gui/icons.py b/nw/gui/icons.py index facb84d7..a6a68db0 100644 --- a/nw/gui/icons.py +++ b/nw/gui/icons.py @@ -45,10 +45,11 @@ class GuiIcons: } DECO_MAP = { - "export" : "export.svg", - "merge" : "merge.svg", - "settings" : "gear.svg", - "split" : "split.svg", + "nwicon" : ["icons", "novelWriter.svg"], + "export" : ["graphics", "export.svg"], + "merge" : ["graphics", "merge.svg"], + "settings" : ["graphics", "gear.svg"], + "split" : ["graphics", "split.svg"], } def __init__(self, theParent): @@ -67,6 +68,9 @@ class GuiIcons: return def initIcons(self, priPath): + """Load all icons listed in the icon map. Can be overridden by + the selected theme. + """ self.priPath = priPath self.secPath = self.mainConf.iconPath @@ -78,12 +82,19 @@ class GuiIcons: return def loadDecoration(self, decoKey, decoSize=None): + """Load graphical decoration element based on the decoration + map. This function always returns a QSwgWidget. + """ if decoKey not in self.DECO_MAP: logger.error("Decoration with name '%s' does not exist" % decoKey) return QSvgWidget() - svgPath = path.join(self.mainConf.graphPath, self.DECO_MAP[decoKey]) + svgPath = path.join( + self.mainConf.assetPath, + self.DECO_MAP[decoKey][0], + self.DECO_MAP[decoKey][1] + ) if not path.isfile(svgPath): logger.error("Decoration file '%s' not in assets folder" % self.DECO_MAP[decoKey]) return QSvgWidget() @@ -95,11 +106,17 @@ class GuiIcons: return svgDeco def getIcon(self, iconKey, iconSize=None): + """Return an icon from the icon buffer. If it doesn't exist, + return an empty icon. + """ if iconKey in self.qIcons: return self.qIcons[iconKey] return QIcon() def getPixmap(self, iconKey, iconSize): + """Return an icon from the icon buffer as a QPixmap. If it + doesn't exist, return an empty QPixmap. + """ if iconKey in self.qIcons: return self.qIcons[iconKey].pixmap(iconSize[0], iconSize[1], QIcon.Normal) return QPixmap() @@ -109,6 +126,11 @@ class GuiIcons: ## def _loadIcon(self, iconKey): + """Load an icon from the assets or theme folder, with a + preference for dark/light icons depending on theme type, if such + an icon exists. Prefer svg files over png files. Always returns + a QIcon. + """ if iconKey not in self.ICON_MAP: logger.error("Icon with name '%s' does not exist" % iconKey) diff --git a/nw/guimain.py b/nw/guimain.py index 2c0d15e9..96fc99b0 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -27,7 +27,7 @@ from nw.gui import ( GuiMainMenu, GuiMainStatus, GuiTheme, GuiDocTree, GuiDocEditor, GuiExport, GuiDocViewer, GuiDocDetails, GuiSearchBar, GuiNoticeBar, GuiDocViewDetails, GuiConfigEditor, GuiProjectEditor, GuiItemEditor, GuiTimeLineView, - GuiSessionLogView, GuiDocMerge, GuiDocSplit + GuiSessionLogView, GuiDocMerge, GuiDocSplit, GuiProjectLoad ) from nw.project import NWProject, NWDoc, NWItem, NWIndex, NWBackup from nw.tools import countWords @@ -64,7 +64,7 @@ class GuiMain(QMainWindow): self.resize(*self.mainConf.winGeometry) self._setWindowTitle() - self.setWindowIcon(QIcon(path.join(self.mainConf.appIcon))) + self.setWindowIcon(QIcon(self.mainConf.appIcon)) # Main GUI Elements self.statusBar = GuiMainStatus(self) @@ -183,6 +183,8 @@ class GuiMain(QMainWindow): if self.mainConf.cmdOpen is not None: logger.debug("Opening project from additional command line option") self.openProject(self.mainConf.cmdOpen) + else: + self.manageProjects() return @@ -204,6 +206,17 @@ class GuiMain(QMainWindow): # Project Actions ## + def manageProjects(self): + """ + """ + + if self.mainConf.showGUI: + dlgProj = GuiProjectLoad(self) + dlgProj.exec_() + + + return True + def newProject(self, projPath=None, forceNew=False): if self.hasProject: