Manipulating statuses now seem to work, and update correctly.

This commit is contained in:
Veronica K. B. Olsen
2019-05-19 21:55:50 +02:00
parent 540aa7fcbc
commit edb6c41788
9 changed files with 114 additions and 172 deletions
-111
View File
@@ -1,111 +0,0 @@
# -*- coding: utf-8 -*-
"""novelWriter GUI Document Tabs
novelWriter GUI Document Tabs
=================================
Class holding the document tab view
File History:
Created: 2018-09-29 [0.0.1]
"""
import logging
import nw
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QTabWidget, QWidget, QVBoxLayout
from nw.gui.doceditor import GuiDocEditor
from nw.gui.projecteditor import GuiProjectEditor
from nw.gui.aboutview import GuiAboutView
logger = logging.getLogger(__name__)
class GuiDocTabs(QTabWidget):
def __init__(self):
QTabWidget.__init__(self)
logger.debug("Initialising DocTabs ...")
self.mainConf = nw.CONFIG
self.tabList = []
self.resize(900,500)
self.setTabsClosable(True)
self.tabBar().tabCloseRequested.connect(self._doCloseTab)
self.createTab(None,nw.DOCTYPE_ABOUT)
logger.debug("DocTabs initialisation complete")
return
def createTab(self, theName=None, tabType=None):
if tabType == nw.DOCTYPE_ABOUT:
self._createTabAbout()
return True
elif tabType == nw.DOCTYPE_PROJECT:
self._createTabProject(theName)
return True
elif tabType == nw.DOCTYPE_DOC:
self._createTabDoc(theName)
return True
return False
#
# Internal Functions
#
def _createTabDoc(self, docName=None):
if docName is None:
tabName = "New Document"
else:
tabName = docName
thisTab = GuiDocEditor()
self.addTab(thisTab,tabName)
self.setCurrentWidget(thisTab)
return True
def _createTabProject(self, projectName=None):
"""Display or create the project settings page.
"""
for i in range(self.count()):
thisTab = self.widget(i)
if isinstance(thisTab, GuiProjectEditor):
self.setCurrentWidget(thisTab)
return True
if projectName is None:
tabName = "New Project"
else:
tabName = projectName
thisTab = GuiProjectEditor()
self.addTab(thisTab,tabName)
self.setCurrentWidget(thisTab)
return True
def _createTabAbout(self):
"""Display or create the About tab.
"""
for i in range(self.count()):
thisTab = self.widget(i)
if isinstance(thisTab, GuiAboutView):
self.setCurrentWidget(thisTab)
return True
thisTab = GuiAboutView()
self.addTab(thisTab,"About")
self.setCurrentWidget(thisTab)
return True
#
# Signals
#
def _doCloseTab(self, tabIdx):
logger.verbose("User requested tab %d to be closed." % tabIdx)
self.removeTab(tabIdx)
logger.verbose("Tab %d closed." % tabIdx)
return
# END Class GuiDocTabs
+7 -2
View File
@@ -259,10 +259,15 @@ class GuiDocTree(QTreeWidget):
tStatus = nwLabels.CLASS_FLAG[nwItem.itemClass]
if nwItem.itemType == nwItemType.FILE:
tStatus += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout]
iStatus = nwItem.itemStatus
if tClass == nwItemClass.NOVEL:
flagIcon = self.theParent.statusIcons[nwItem.itemStatus]
if iStatus is None:
iStatus = self.theProject.statusItems.checkEntry(iStatus)
flagIcon = self.theParent.statusIcons[iStatus]
else:
flagIcon = self.theParent.importIcons[nwItem.itemStatus]
if iStatus is None:
iStatus = self.theProject.importItems.checkEntry(iStatus)
flagIcon = self.theParent.importIcons[iStatus]
trItem.setText(self.C_NAME, tName)
trItem.setText(self.C_FLAGS,tStatus)
+2 -2
View File
@@ -55,12 +55,12 @@ class GuiItemEditor(QDialog):
self.editLayout = QComboBox()
if self.theItem.itemClass == nwItemClass.NOVEL:
for sLabel, sCol in self.theProject.statusItems:
for sLabel, _, _ in self.theProject.statusItems:
self.editStatus.addItem(
self.theParent.statusIcons[sLabel], sLabel, sLabel
)
else:
for sLabel, sCol in self.theProject.importItems:
for sLabel, _, _ in self.theProject.importItems:
self.editStatus.addItem(
self.theParent.importIcons[sLabel], sLabel, sLabel
)
+32 -26
View File
@@ -22,8 +22,7 @@ from PyQt5.QtWidgets import (
QWidget, QTabWidget, QDialogButtonBox, QListWidget, QListWidgetItem, QPushButton,
QColorDialog
)
from nw.enum import nwChanged
from nw.enum import nwAlert
logger = logging.getLogger(__name__)
@@ -46,6 +45,7 @@ class GuiProjectEditor(QDialog):
self.svgGradient = QSvgWidget(self.gradPath)
self.svgGradient.setFixedWidth(80)
self.theProject.countStatus()
self.tabMain = GuiProjectEditMain(self.theParent, self.theProject)
self.tabStatus = GuiProjectEditStatus(self.theParent, self.theProject.statusItems)
self.tabImport = GuiProjectEditStatus(self.theParent, self.theProject.importItems)
@@ -82,10 +82,10 @@ class GuiProjectEditor(QDialog):
self.theProject.setBookTitle(bookTitle)
self.theProject.setBookAuthors(bookAuthors)
statusCol, statusChange = self.tabStatus.getNewList()
importCol, importChange = self.tabImport.getNewList()
self.theProject.setStatusColours(statusCol, statusChange)
self.theProject.setImportColours(importCol, importChange)
statusCol = self.tabStatus.getNewList()
importCol = self.tabImport.getNewList()
self.theProject.setStatusColours(statusCol)
self.theProject.setImportColours(importCol)
self.close()
@@ -135,6 +135,7 @@ class GuiProjectEditStatus(QWidget):
self.theParent = theParent
self.theStatus = theStatus
self.colNames = []
self.colCounts = []
self.colChanged = False
self.mainBox = QHBoxLayout()
@@ -143,9 +144,10 @@ class GuiProjectEditStatus(QWidget):
self.listBox = QListWidget()
self.listBox.itemSelectionChanged.connect(self._selectedItem)
for iName, iCol in self.theStatus:
self._addItem(iName, iCol)
for iName, iCol, nUse in self.theStatus:
self._addItem("%s [%d]" % (iName, nUse), iCol)
self.colNames.append(iName)
self.colCounts.append(nUse)
self.editName = QLineEdit()
self.newButton = QPushButton("New")
@@ -182,12 +184,12 @@ class GuiProjectEditStatus(QWidget):
newList = []
for n in range(self.listBox.count()):
nItem = self.listBox.item(n)
nName = nItem.text()
nName = self._cleanLabel(nItem.text())
nImg = nItem.icon().pixmap(16,16).toImage()
nCol = QColor(nImg.pixel(7,7))
newList.append((nName,nCol.red(),nCol.green(),nCol.blue()))
return newList, self.colNames
return None, None
newList.append((nName,nCol.red(),nCol.green(),nCol.blue(),self.colNames[n]))
return newList
return None
##
# User Actions
@@ -206,32 +208,29 @@ class GuiProjectEditStatus(QWidget):
return
def _newItem(self):
newItem = self._addItem("New Item", (0, 0, 0))
newItem = self._addItem("New Item [0]", (0, 0, 0))
newItem.setBackground(QBrush(QColor(0,255,0,80)))
self.colNames.append(None)
self.colCounts.append(0)
self.colChanged = True
return
def _delItem(self):
selItem = self._getSelectedItem()
colDel = QBrush(QColor(255,0,0,80))
colNone = QBrush(QColor(0,0,0,0))
if selItem is not None:
sText = selItem.text()
iRow = self.listBox.row(selItem)
if sText == "** Delete **":
selItem.setBackground(colNone)
selItem.setText(self.colNames[iRow])
else:
selItem.setBackground(colDel)
selItem.setText("** Delete **")
iRow = self.listBox.row(selItem)
if self.colCounts[iRow] == 0:
self.listBox.takeItem(iRow)
self.colChanged = True
else:
self.theParent.makeAlert("Cannot delete status item that is in use.",nwAlert.ERROR)
return
def _saveItem(self):
logger.verbose("Item save button clicked")
selItem = self._getSelectedItem()
iRow = self.listBox.row(selItem)
if selItem is not None:
selItem.setText(self.editName.text().strip())
selItem.setText("%s [%d]" % (self.editName.text().strip(), self.colCounts[iRow]))
selItem.setIcon(self.colButton.icon())
self.colChanged = True
return
@@ -250,7 +249,7 @@ class GuiProjectEditStatus(QWidget):
logger.verbose("Item selected")
selItem = self._getSelectedItem()
if selItem is not None:
self.editName.setText(selItem.text())
self.editName.setText(self._cleanLabel(selItem.text()))
self.colButton.setIcon(selItem.icon())
return
@@ -266,4 +265,11 @@ class GuiProjectEditStatus(QWidget):
return selItem[0]
return None
def _cleanLabel(self, theText):
iPos = theText.rfind("[")
if iPos > 0:
return theText[:iPos-1]
else:
return theText
# END Class GuiProjectEditStatus
+2 -2
View File
@@ -396,7 +396,7 @@ class GuiMain(QMainWindow):
def _makeStatusIcons(self):
self.statusIcons = {}
for sLabel, sCol in self.theProject.statusItems:
for sLabel, sCol, _ in self.theProject.statusItems:
theIcon = QPixmap(32,32)
theIcon.fill(QColor(*sCol))
self.statusIcons[sLabel] = QIcon(theIcon)
@@ -404,7 +404,7 @@ class GuiMain(QMainWindow):
def _makeImportIcons(self):
self.importIcons = {}
for sLabel, sCol in self.theProject.importItems:
for sLabel, sCol, _ in self.theProject.importItems:
theIcon = QPixmap(32,32)
theIcon.fill(QColor(*sCol))
self.importIcons[sLabel] = QIcon(theIcon)