Merge branch 'dev' into project_details
This commit is contained in:
+18
-5
@@ -316,7 +316,6 @@ class GuiDocEditor(QTextEdit):
|
||||
self.lastEdit = time()
|
||||
self._runCounter()
|
||||
self.wcTimer.start()
|
||||
self.setDocumentChanged(False)
|
||||
self.theHandle = tHandle
|
||||
|
||||
self.setReadOnly(False)
|
||||
@@ -341,6 +340,9 @@ class GuiDocEditor(QTextEdit):
|
||||
self.docFooter.updateLineCount()
|
||||
self.lengthLast = self.qDocument.characterCount()
|
||||
|
||||
qApp.processEvents()
|
||||
self.setDocumentChanged(False)
|
||||
|
||||
qApp.restoreOverrideCursor()
|
||||
|
||||
return True
|
||||
@@ -373,8 +375,8 @@ class GuiDocEditor(QTextEdit):
|
||||
|
||||
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
|
||||
self.setPlainText(theText)
|
||||
self.setDocumentChanged(True)
|
||||
self.updateDocMargins()
|
||||
self.setDocumentChanged(True)
|
||||
qApp.restoreOverrideCursor()
|
||||
|
||||
return True
|
||||
@@ -450,11 +452,17 @@ class GuiDocEditor(QTextEdit):
|
||||
lM = max(cM, fH)
|
||||
self.setViewportMargins(tM, uM, tM, lM)
|
||||
|
||||
docChanged = self.docChanged
|
||||
if self.mainConf.scrollPastEnd:
|
||||
docFrame = self.qDocument.rootFrame().frameFormat()
|
||||
docFrame.setBottomMargin(max(0, 0.6*(wH - uM - lM - 4*tB)))
|
||||
self.qDocument.rootFrame().setFrameFormat(docFrame)
|
||||
|
||||
# This is needed as the setFrameFormat function itself will
|
||||
# trigger the contetsChanged signal which sets docChanged, so we
|
||||
# set it back to whatever it was before.
|
||||
self.setDocumentChanged(docChanged)
|
||||
|
||||
return
|
||||
|
||||
def updateDocInfo(self, tHandle):
|
||||
@@ -895,12 +903,13 @@ class GuiDocEditor(QTextEdit):
|
||||
##
|
||||
|
||||
@pyqtSlot(int, int, int)
|
||||
def _docChange(self, thePos, charsRemoved, charsAdded):
|
||||
def _docChange(self, thePos, chrRem, chrAdd):
|
||||
"""Triggered by QTextDocument->contentsChanged. This also
|
||||
triggers the syntax highlighter.
|
||||
"""
|
||||
self.lastEdit = time()
|
||||
self.lastFind = None
|
||||
|
||||
if self.qDocument.characterCount() > nwConst.MAX_DOCSIZE:
|
||||
self.theParent.makeAlert((
|
||||
"The document has grown too big and you cannot add more text to it. "
|
||||
@@ -908,12 +917,16 @@ class GuiDocEditor(QTextEdit):
|
||||
) % (nwConst.MAX_DOCSIZE/1.0e6), nwAlert.ERROR)
|
||||
self.undo()
|
||||
return
|
||||
|
||||
if not self.docChanged:
|
||||
self.setDocumentChanged(True)
|
||||
self.setDocumentChanged(chrRem != 0 or chrAdd != 0)
|
||||
|
||||
if not self.wcTimer.isActive():
|
||||
self.wcTimer.start()
|
||||
if self.doReplace and charsAdded == 1:
|
||||
|
||||
if self.doReplace and chrAdd == 1:
|
||||
self._docAutoReplace(self.qDocument.findBlock(thePos))
|
||||
|
||||
return
|
||||
|
||||
@pyqtSlot("QPoint")
|
||||
|
||||
+57
-34
@@ -28,13 +28,14 @@
|
||||
import nw
|
||||
import logging
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialog, QVBoxLayout, QGridLayout, QLineEdit, QComboBox, QLabel,
|
||||
QDialogButtonBox
|
||||
)
|
||||
|
||||
from nw.gui.custom import QSwitch
|
||||
from nw.constants import nwLabels, nwItemLayout, nwItemClass, nwItemType
|
||||
from nw.constants import nwLabels, nwItemLayout, nwItemType, nwLists
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -50,23 +51,29 @@ class GuiItemEditor(QDialog):
|
||||
self.theProject = theProject
|
||||
self.theParent = theParent
|
||||
|
||||
self.outerBox = QVBoxLayout()
|
||||
##
|
||||
# Build GUI
|
||||
##
|
||||
|
||||
self.theItem = self.theProject.projTree[tHandle]
|
||||
if self.theItem is None:
|
||||
self._doClose()
|
||||
|
||||
self.setWindowTitle("Item Settings")
|
||||
self.setLayout(self.outerBox)
|
||||
|
||||
mVd = self.mainConf.pxInt(220)
|
||||
mSp = self.mainConf.pxInt(16)
|
||||
vSp = self.mainConf.pxInt(4)
|
||||
|
||||
# Item Label
|
||||
self.editName = QLineEdit()
|
||||
self.editName.setMinimumWidth(self.mainConf.pxInt(220))
|
||||
self.editName.setMaxLength(self.mainConf.pxInt(200))
|
||||
self.editName.setMinimumWidth(mVd)
|
||||
self.editName.setMaxLength(200)
|
||||
|
||||
# Item Status
|
||||
self.editStatus = QComboBox()
|
||||
if self.theItem.itemClass == nwItemClass.NOVEL:
|
||||
self.editStatus.setMinimumWidth(mVd)
|
||||
if self.theItem.itemClass in nwLists.CLS_NOVEL:
|
||||
for sLabel, _, _ in self.theProject.statusItems:
|
||||
self.editStatus.addItem(
|
||||
self.theParent.statusIcons[sLabel], sLabel, sLabel
|
||||
@@ -79,24 +86,24 @@ class GuiItemEditor(QDialog):
|
||||
|
||||
# Item Layout
|
||||
self.editLayout = QComboBox()
|
||||
self.validLayouts = []
|
||||
self.editLayout.setMinimumWidth(mVd)
|
||||
validLayouts = []
|
||||
if self.theItem.itemType == nwItemType.FILE:
|
||||
if self.theItem.itemClass == nwItemClass.NOVEL:
|
||||
self.validLayouts.append(nwItemLayout.TITLE)
|
||||
self.validLayouts.append(nwItemLayout.BOOK)
|
||||
self.validLayouts.append(nwItemLayout.PAGE)
|
||||
self.validLayouts.append(nwItemLayout.PARTITION)
|
||||
self.validLayouts.append(nwItemLayout.UNNUMBERED)
|
||||
self.validLayouts.append(nwItemLayout.CHAPTER)
|
||||
self.validLayouts.append(nwItemLayout.SCENE)
|
||||
self.validLayouts.append(nwItemLayout.NOTE)
|
||||
else:
|
||||
self.validLayouts.append(nwItemLayout.NOTE)
|
||||
if self.theItem.itemClass in nwLists.CLS_NOVEL:
|
||||
validLayouts.append(nwItemLayout.TITLE)
|
||||
validLayouts.append(nwItemLayout.BOOK)
|
||||
validLayouts.append(nwItemLayout.PAGE)
|
||||
validLayouts.append(nwItemLayout.PARTITION)
|
||||
validLayouts.append(nwItemLayout.UNNUMBERED)
|
||||
validLayouts.append(nwItemLayout.CHAPTER)
|
||||
validLayouts.append(nwItemLayout.SCENE)
|
||||
validLayouts.append(nwItemLayout.NOTE)
|
||||
else:
|
||||
self.validLayouts.append(nwItemLayout.NO_LAYOUT)
|
||||
validLayouts.append(nwItemLayout.NO_LAYOUT)
|
||||
self.editLayout.setEnabled(False)
|
||||
|
||||
for itemLayout in nwItemLayout:
|
||||
if itemLayout in self.validLayouts:
|
||||
if itemLayout in validLayouts:
|
||||
self.editLayout.addItem(nwLabels.LAYOUT_NAME[itemLayout], itemLayout)
|
||||
|
||||
# Export Switch
|
||||
@@ -109,23 +116,30 @@ class GuiItemEditor(QDialog):
|
||||
self.editExport.setEnabled(False)
|
||||
self.editExport.setChecked(False)
|
||||
|
||||
self.editName.setText(self.theItem.itemName)
|
||||
statusIdx = self.editStatus.findData(self.theItem.itemStatus)
|
||||
if statusIdx != -1:
|
||||
self.editStatus.setCurrentIndex(statusIdx)
|
||||
layoutIdx = self.editLayout.findData(self.theItem.itemLayout)
|
||||
if layoutIdx != -1:
|
||||
self.editLayout.setCurrentIndex(layoutIdx)
|
||||
|
||||
# Buttons
|
||||
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
|
||||
self.buttonBox.accepted.connect(self._doSave)
|
||||
self.buttonBox.rejected.connect(self._doClose)
|
||||
|
||||
# Assemble
|
||||
# Set Current Values
|
||||
self.editName.setText(self.theItem.itemName)
|
||||
self.editName.selectAll()
|
||||
|
||||
statusIdx = self.editStatus.findData(self.theItem.itemStatus)
|
||||
if statusIdx != -1:
|
||||
self.editStatus.setCurrentIndex(statusIdx)
|
||||
|
||||
layoutIdx = self.editLayout.findData(self.theItem.itemLayout)
|
||||
if layoutIdx != -1:
|
||||
self.editLayout.setCurrentIndex(layoutIdx)
|
||||
|
||||
##
|
||||
# Assemble
|
||||
##
|
||||
|
||||
self.mainForm = QGridLayout()
|
||||
self.mainForm.setVerticalSpacing(self.mainConf.pxInt(4))
|
||||
self.mainForm.setHorizontalSpacing(self.mainConf.pxInt(16))
|
||||
self.mainForm.setVerticalSpacing(vSp)
|
||||
self.mainForm.setHorizontalSpacing(mSp)
|
||||
self.mainForm.addWidget(QLabel("Label"), 0, 0, 1, 1)
|
||||
self.mainForm.addWidget(self.editName, 0, 1, 1, 2)
|
||||
self.mainForm.addWidget(QLabel("Status"), 1, 0, 1, 1)
|
||||
@@ -134,20 +148,28 @@ class GuiItemEditor(QDialog):
|
||||
self.mainForm.addWidget(self.editLayout, 2, 1, 1, 2)
|
||||
self.mainForm.addWidget(self.textExport, 3, 0, 1, 2)
|
||||
self.mainForm.addWidget(self.editExport, 3, 2, 1, 1)
|
||||
self.mainForm.setColumnStretch(0, 0)
|
||||
self.mainForm.setColumnStretch(1, 1)
|
||||
self.mainForm.setColumnStretch(2, 0)
|
||||
|
||||
self.outerBox.setSpacing(self.mainConf.pxInt(16))
|
||||
self.outerBox = QVBoxLayout()
|
||||
self.outerBox.setSpacing(mSp)
|
||||
self.outerBox.addLayout(self.mainForm)
|
||||
self.outerBox.addStretch(1)
|
||||
self.outerBox.addWidget(self.buttonBox)
|
||||
self.setLayout(self.outerBox)
|
||||
|
||||
self.rejected.connect(self._doClose)
|
||||
self.editName.selectAll()
|
||||
|
||||
logger.debug("GuiItemEditor initialisation complete")
|
||||
|
||||
return
|
||||
|
||||
##
|
||||
# Slots
|
||||
##
|
||||
|
||||
@pyqtSlot()
|
||||
def _doSave(self):
|
||||
"""Save the setting to the item.
|
||||
"""
|
||||
@@ -170,10 +192,11 @@ class GuiItemEditor(QDialog):
|
||||
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def _doClose(self):
|
||||
"""Close the dialog without saving the settings.
|
||||
"""
|
||||
logger.verbose("ItemEditor close button clicked")
|
||||
logger.verbose("ItemEditor cancel button clicked")
|
||||
self.close()
|
||||
return
|
||||
|
||||
|
||||
+7
-13
@@ -553,36 +553,30 @@ class GuiProjectTree(QTreeWidget):
|
||||
the project tree. Does not trigger a tree change as the data is
|
||||
already coming from the project tree.
|
||||
"""
|
||||
trItem = self._getTreeItem(tHandle)
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
tName = nwItem.itemName
|
||||
tClass = nwItem.itemClass
|
||||
tHandle = nwItem.itemHandle
|
||||
trItem = self._getTreeItem(tHandle)
|
||||
nwItem = self.theProject.projTree[tHandle]
|
||||
|
||||
expIcon = QIcon()
|
||||
|
||||
stClass = nwLabels.CLASS_FLAG[nwItem.itemClass]
|
||||
stLayout = ""
|
||||
stFlags = nwLabels.CLASS_FLAG[nwItem.itemClass]
|
||||
if nwItem.itemType == nwItemType.FILE:
|
||||
stLayout = "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout]
|
||||
stFlags += "."+nwLabels.LAYOUT_FLAG[nwItem.itemLayout]
|
||||
if nwItem.isExported:
|
||||
expIcon = self.theTheme.getIcon("check")
|
||||
else:
|
||||
expIcon = self.theTheme.getIcon("cross")
|
||||
tStatus = stClass+stLayout
|
||||
|
||||
iStatus = nwItem.itemStatus
|
||||
if tClass == nwItemClass.NOVEL:
|
||||
if nwItem.itemClass == nwItemClass.NOVEL:
|
||||
iStatus = self.theProject.statusItems.checkEntry(iStatus) # Make sure it's valid
|
||||
flagIcon = self.theParent.statusIcons[iStatus]
|
||||
else:
|
||||
iStatus = self.theProject.importItems.checkEntry(iStatus) # Make sure it's valid
|
||||
flagIcon = self.theParent.importIcons[iStatus]
|
||||
|
||||
trItem.setText(self.C_NAME, tName)
|
||||
trItem.setText(self.C_NAME, nwItem.itemName)
|
||||
trItem.setIcon(self.C_EXPORT, expIcon)
|
||||
trItem.setText(self.C_FLAGS, tStatus)
|
||||
trItem.setIcon(self.C_FLAGS, flagIcon)
|
||||
trItem.setText(self.C_FLAGS, stFlags)
|
||||
|
||||
return
|
||||
|
||||
|
||||
+2
-17
@@ -51,9 +51,6 @@ class GuiMainStatus(QStatusBar):
|
||||
self.theTheme = theParent.theTheme
|
||||
self.refTime = None
|
||||
|
||||
self.projWords = 0
|
||||
self.sessWords = 0
|
||||
|
||||
colNone = QColor(*self.theTheme.statNone)
|
||||
colTrue = QColor(*self.theTheme.statUnsaved)
|
||||
colFalse = QColor(*self.theTheme.statSaved)
|
||||
@@ -182,26 +179,14 @@ class GuiMainStatus(QStatusBar):
|
||||
def setStats(self, pWC, sWC):
|
||||
"""Set the current project statistics.
|
||||
"""
|
||||
self.projWords = pWC
|
||||
self.sessWords = sWC
|
||||
self._updateStats()
|
||||
self.statsText.setText(f"Words: {pWC:n} ({sWC:+n})")
|
||||
self.statsText.setToolTip("Project word count (session change)")
|
||||
return
|
||||
|
||||
##
|
||||
# Internal Functions
|
||||
##
|
||||
|
||||
def _updateStats(self):
|
||||
"""Update statistics.
|
||||
"""
|
||||
self.statsText.setToolTip(
|
||||
"Project word count (session change)"
|
||||
)
|
||||
self.statsText.setText(
|
||||
f"Words: {self.projWords:n} ({self.sessWords:+n})"
|
||||
)
|
||||
return
|
||||
|
||||
def _updateTime(self):
|
||||
"""Update the session clock.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user