diff --git a/nw/gui/docdetails.py b/nw/gui/docdetails.py index 9851d590..c8b6a078 100644 --- a/nw/gui/docdetails.py +++ b/nw/gui/docdetails.py @@ -35,6 +35,7 @@ class GuiDocDetails(QFrame): logger.debug("Initialising DocDetails ...") self.mainConf = nw.CONFIG self.debugGUI = self.mainConf.debugGUI + self.theParent = theParent self.theProject = theProject self.mainBox = QGridLayout(self) @@ -70,11 +71,11 @@ class GuiDocDetails(QFrame): colTwo = [""]*4 else: itemStatus = nwItem.itemStatus - if itemStatus < 0 or itemStatus >= len(self.theProject.statusLabels): + if itemStatus < 0 or itemStatus >= len(self.theParent.statusLabels): itemStatus = 0 colTwo = [ nwItem.itemName, - self.theProject.statusLabels[itemStatus], + self.theParent.statusLabels[itemStatus], nwLabels.CLASS_NAME[nwItem.itemClass], nwLabels.LAYOUT_NAME[nwItem.itemLayout], ] diff --git a/nw/gui/doctree.py b/nw/gui/doctree.py index 859ff0c9..4ef921f2 100644 --- a/nw/gui/doctree.py +++ b/nw/gui/doctree.py @@ -252,12 +252,12 @@ class GuiDocTree(QTreeWidget): if nwItem.itemType == nwItemType.FILE: tStatus += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout] nStatus = nwItem.itemStatus - if nStatus < 0 or nStatus >= len(self.theProject.statusIcons): + if nStatus < 0 or nStatus >= len(self.theParent.statusIcons): nStatus = 0 trItem.setText(self.C_NAME,tName) trItem.setText(self.C_FLAGS,tStatus) - trItem.setIcon(self.C_FLAGS,self.theProject.statusIcons[nStatus]) + trItem.setIcon(self.C_FLAGS,self.theParent.statusIcons[nStatus]) return diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index e0b6693b..aef80173 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -15,7 +15,7 @@ import nw from os import path from PyQt5.QtWidgets import QWidget, QMainWindow, QVBoxLayout, QFrame, QSplitter, QFileDialog, QStackedWidget, QShortcut, QMessageBox -from PyQt5.QtGui import QIcon +from PyQt5.QtGui import QIcon, QPixmap, QColor from PyQt5.QtCore import Qt, QTimer from nw.gui.doctree import GuiDocTree @@ -57,6 +57,10 @@ class GuiMain(QMainWindow): self.mainMenu = GuiMainMenu(self, self.theProject) self.statusBar = GuiMainStatus(self) + # Minor Gui Elements + self.statusIcons = [] + self.statusLabels = [] + # Assemble Main Window self.stackPane = QStackedWidget() self.stackNone = self.stackPane.addWidget(QWidget()) @@ -82,7 +86,7 @@ class GuiMain(QMainWindow): self.treeView.itemSelectionChanged.connect(self._treeSingleClick) self.treeView.itemDoubleClicked.connect(self._treeDoubleClick) self.treeView.buildTree() - QShortcut(Qt.Key_Return, self.treeView, context=Qt.WidgetShortcut, activated=self._treeKeyPressReturn) + self._makeStatusIcons() # Set Main Window Elements self.setMenuBar(self.mainMenu) @@ -106,6 +110,13 @@ class GuiMain(QMainWindow): self.asDocTimer.timeout.connect(self._autoSaveDocument) self.asDocTimer.start() + # Keyboard Shortcuts + QShortcut(Qt.Key_Return, self.treeView, context=Qt.WidgetShortcut, activated=self._treeKeyPressReturn) + + # Forward Functions + self.setStatus = self.statusBar.setStatus + self.setProjectStatus = self.statusBar.setProjectStatus + if self.mainConf.showGUI: self.show() @@ -162,6 +173,7 @@ class GuiMain(QMainWindow): self.treeView.buildTree() self.mainMenu.updateRecentProjects() self._setWindowTitle(self.theProject.projName) + self._makeStatusIcons() return True def saveProject(self): @@ -340,6 +352,16 @@ class GuiMain(QMainWindow): return False return True + def _makeStatusIcons(self): + self.statusIcons = [] + self.statusLabels = [] + for sLabel, sR, sG, sB in self.theProject.statusCols: + theIcon = QPixmap(32,32) + theIcon.fill(QColor(sR,sG,sB)) + self.statusIcons.append(QIcon(theIcon)) + self.statusLabels.append(sLabel) + return + ## # Events ## diff --git a/nw/project/project.py b/nw/project/project.py index 1ba4685a..11090f2f 100644 --- a/nw/project/project.py +++ b/nw/project/project.py @@ -19,8 +19,6 @@ from hashlib import sha256 from datetime import datetime from time import time -from PyQt5.QtGui import QIcon, QPixmap, QColor - from nw.enum import nwItemType, nwItemClass, nwItemLayout from nw.project.item import NWItem @@ -31,8 +29,8 @@ class NWProject(): def __init__(self, theParent): # Internal - self.mainConf = nw.CONFIG self.theParent = theParent + self.mainConf = self.theParent.mainConf self.projChanged = None # Project Settings @@ -46,8 +44,6 @@ class NWProject(): self.bookTitle = None self.bookAuthors = None self.statusCols = None - self.statusIcons = None - self.statusLabels = None self.clearProject() @@ -108,7 +104,7 @@ class NWProject(): hChapt = self.newFolder("New Chapter", nwItemClass.NOVEL, hNovel) hScene = self.newFile("New Scene", nwItemClass.NOVEL, hChapt) - return + return True def clearProject(self): @@ -124,16 +120,12 @@ class NWProject(): self.projName = "" self.bookTitle = "" self.bookAuthors = [] - self.statusCols = [ ("New", 100,100,100), ("Note", 200, 50, 0), ("Draft", 200,150, 0), ("Finished", 50,200, 0), ] - self.statusIcons = [] - self.statusLabels = [] - self._makeStatusIcons() return @@ -195,9 +187,8 @@ class NWProject(): nwItem.setFromTag(xValue.tag,xValue.text) self._appendItem(tHandle,pHandle,nwItem) - self._makeStatusIcons() self.mainConf.setRecent(self.projPath) - self.theParent.statusBar.setStatus("Opened Project: %s" % self.projName) + self.theParent.setStatus("Opened Project: %s" % self.projName) self._scanProjectFolder() self.setProjectChanged(False) @@ -258,7 +249,7 @@ class NWProject(): return False self.mainConf.setRecent(self.projPath) - self.theParent.statusBar.setStatus("Saved Project: %s" % self.projName) + self.theParent.setStatus("Saved Project: %s" % self.projName) self.setProjectChanged(False) return True @@ -301,7 +292,7 @@ class NWProject(): def setProjectChanged(self, bValue): self.projChanged = bValue - self.theParent.statusBar.setProjectStatus(self.projChanged) + self.theParent.setProjectStatus(self.projChanged) return ## @@ -411,16 +402,6 @@ class NWProject(): return - def _makeStatusIcons(self): - self.statusIcons = [] - self.statusLabels = [] - for sLabel, sR, sG, sB in self.statusCols: - theIcon = QPixmap(32,32) - theIcon.fill(QColor(sR,sG,sB)) - self.statusIcons.append(QIcon(theIcon)) - self.statusLabels.append(sLabel) - return - def _makeHandle(self, addSeed=""): newSeed = str(time()) + addSeed logger.verbose("Generating handle with seed '%s'" % newSeed)