Added the main dialog class for project management, and made some changes to the icon class.

This commit is contained in:
Veronica K. B. Olsen
2020-02-26 15:30:08 +01:00
parent cce65a6e93
commit 6867f38637
5 changed files with 133 additions and 7 deletions
+2
View File
@@ -13,6 +13,7 @@ from nw.gui.dialogs.docsplit import GuiDocSplit
from nw.gui.dialogs.export import GuiExport from nw.gui.dialogs.export import GuiExport
from nw.gui.dialogs.itemeditor import GuiItemEditor from nw.gui.dialogs.itemeditor import GuiItemEditor
from nw.gui.dialogs.projecteditor import GuiProjectEditor 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.sessionlog import GuiSessionLogView
from nw.gui.dialogs.timelineview import GuiTimeLineView from nw.gui.dialogs.timelineview import GuiTimeLineView
@@ -40,6 +41,7 @@ __all__ = [
"GuiExport", "GuiExport",
"GuiItemEditor", "GuiItemEditor",
"GuiProjectEditor", "GuiProjectEditor",
"GuiProjectLoad",
"GuiSessionLogView", "GuiSessionLogView",
"GuiTimeLineView", "GuiTimeLineView",
"GuiDocDetails", "GuiDocDetails",
+2
View File
@@ -6,6 +6,7 @@ from nw.gui.dialogs.docsplit import GuiDocSplit
from nw.gui.dialogs.export import GuiExport from nw.gui.dialogs.export import GuiExport
from nw.gui.dialogs.itemeditor import GuiItemEditor from nw.gui.dialogs.itemeditor import GuiItemEditor
from nw.gui.dialogs.projecteditor import GuiProjectEditor 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.sessionlog import GuiSessionLogView
from nw.gui.dialogs.timelineview import GuiTimeLineView from nw.gui.dialogs.timelineview import GuiTimeLineView
@@ -16,6 +17,7 @@ __all__ = [
"GuiExport", "GuiExport",
"GuiItemEditor", "GuiItemEditor",
"GuiProjectEditor", "GuiProjectEditor",
"GuiProjectLoad",
"GuiSessionLogView", "GuiSessionLogView",
"GuiTimeLineView", "GuiTimeLineView",
] ]
+87
View File
@@ -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
+27 -5
View File
@@ -45,10 +45,11 @@ class GuiIcons:
} }
DECO_MAP = { DECO_MAP = {
"export" : "export.svg", "nwicon" : ["icons", "novelWriter.svg"],
"merge" : "merge.svg", "export" : ["graphics", "export.svg"],
"settings" : "gear.svg", "merge" : ["graphics", "merge.svg"],
"split" : "split.svg", "settings" : ["graphics", "gear.svg"],
"split" : ["graphics", "split.svg"],
} }
def __init__(self, theParent): def __init__(self, theParent):
@@ -67,6 +68,9 @@ class GuiIcons:
return return
def initIcons(self, priPath): def initIcons(self, priPath):
"""Load all icons listed in the icon map. Can be overridden by
the selected theme.
"""
self.priPath = priPath self.priPath = priPath
self.secPath = self.mainConf.iconPath self.secPath = self.mainConf.iconPath
@@ -78,12 +82,19 @@ class GuiIcons:
return return
def loadDecoration(self, decoKey, decoSize=None): 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: if decoKey not in self.DECO_MAP:
logger.error("Decoration with name '%s' does not exist" % decoKey) logger.error("Decoration with name '%s' does not exist" % decoKey)
return QSvgWidget() 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): if not path.isfile(svgPath):
logger.error("Decoration file '%s' not in assets folder" % self.DECO_MAP[decoKey]) logger.error("Decoration file '%s' not in assets folder" % self.DECO_MAP[decoKey])
return QSvgWidget() return QSvgWidget()
@@ -95,11 +106,17 @@ class GuiIcons:
return svgDeco return svgDeco
def getIcon(self, iconKey, iconSize=None): 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: if iconKey in self.qIcons:
return self.qIcons[iconKey] return self.qIcons[iconKey]
return QIcon() return QIcon()
def getPixmap(self, iconKey, iconSize): 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: if iconKey in self.qIcons:
return self.qIcons[iconKey].pixmap(iconSize[0], iconSize[1], QIcon.Normal) return self.qIcons[iconKey].pixmap(iconSize[0], iconSize[1], QIcon.Normal)
return QPixmap() return QPixmap()
@@ -109,6 +126,11 @@ class GuiIcons:
## ##
def _loadIcon(self, iconKey): 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: if iconKey not in self.ICON_MAP:
logger.error("Icon with name '%s' does not exist" % iconKey) logger.error("Icon with name '%s' does not exist" % iconKey)
+15 -2
View File
@@ -27,7 +27,7 @@ from nw.gui import (
GuiMainMenu, GuiMainStatus, GuiTheme, GuiDocTree, GuiDocEditor, GuiExport, GuiMainMenu, GuiMainStatus, GuiTheme, GuiDocTree, GuiDocEditor, GuiExport,
GuiDocViewer, GuiDocDetails, GuiSearchBar, GuiNoticeBar, GuiDocViewDetails, GuiDocViewer, GuiDocDetails, GuiSearchBar, GuiNoticeBar, GuiDocViewDetails,
GuiConfigEditor, GuiProjectEditor, GuiItemEditor, GuiTimeLineView, GuiConfigEditor, GuiProjectEditor, GuiItemEditor, GuiTimeLineView,
GuiSessionLogView, GuiDocMerge, GuiDocSplit GuiSessionLogView, GuiDocMerge, GuiDocSplit, GuiProjectLoad
) )
from nw.project import NWProject, NWDoc, NWItem, NWIndex, NWBackup from nw.project import NWProject, NWDoc, NWItem, NWIndex, NWBackup
from nw.tools import countWords from nw.tools import countWords
@@ -64,7 +64,7 @@ class GuiMain(QMainWindow):
self.resize(*self.mainConf.winGeometry) self.resize(*self.mainConf.winGeometry)
self._setWindowTitle() self._setWindowTitle()
self.setWindowIcon(QIcon(path.join(self.mainConf.appIcon))) self.setWindowIcon(QIcon(self.mainConf.appIcon))
# Main GUI Elements # Main GUI Elements
self.statusBar = GuiMainStatus(self) self.statusBar = GuiMainStatus(self)
@@ -183,6 +183,8 @@ class GuiMain(QMainWindow):
if self.mainConf.cmdOpen is not None: if self.mainConf.cmdOpen is not None:
logger.debug("Opening project from additional command line option") logger.debug("Opening project from additional command line option")
self.openProject(self.mainConf.cmdOpen) self.openProject(self.mainConf.cmdOpen)
else:
self.manageProjects()
return return
@@ -204,6 +206,17 @@ class GuiMain(QMainWindow):
# Project Actions # Project Actions
## ##
def manageProjects(self):
"""
"""
if self.mainConf.showGUI:
dlgProj = GuiProjectLoad(self)
dlgProj.exec_()
return True
def newProject(self, projPath=None, forceNew=False): def newProject(self, projPath=None, forceNew=False):
if self.hasProject: if self.hasProject: