Clean up signals and passing variables

This commit is contained in:
Veronica Berglyd Olsen
2024-03-17 15:02:42 +01:00
parent add499af89
commit b156eee209
7 changed files with 132 additions and 127 deletions
+22 -24
View File
@@ -259,7 +259,7 @@ class GuiDocEditor(QPlainTextEdit):
self._doReplace = False self._doReplace = False
self.setDocumentChanged(False) self.setDocumentChanged(False)
self.docHeader.setTitleFromHandle(self._docHandle) self.docHeader.clearHeader()
self.docFooter.setHandle(self._docHandle) self.docFooter.setHandle(self._docHandle)
self.docToolBar.setVisible(False) self.docToolBar.setVisible(False)
@@ -363,7 +363,7 @@ class GuiDocEditor(QPlainTextEdit):
# which makes it read only. # which makes it read only.
if self._docHandle: if self._docHandle:
self._qDocument.syntaxHighlighter.rehighlight() self._qDocument.syntaxHighlighter.rehighlight()
self.docHeader.setTitleFromHandle(self._docHandle) self.docHeader.setHandle(self._docHandle)
else: else:
self.clearEditor() self.clearEditor()
@@ -408,8 +408,8 @@ class GuiDocEditor(QPlainTextEdit):
elif isinstance(tLine, int): elif isinstance(tLine, int):
self.setCursorLine(tLine) self.setCursorLine(tLine)
self.docHeader.setTitleFromHandle(self._docHandle) self.docHeader.setHandle(tHandle)
self.docFooter.setHandle(self._docHandle) self.docFooter.setHandle(tHandle)
# This is a hack to fix invisible cursor on an empty document # This is a hack to fix invisible cursor on an empty document
if self._qDocument.characterCount() <= 1: if self._qDocument.characterCount() <= 1:
@@ -991,8 +991,8 @@ class GuiDocEditor(QPlainTextEdit):
"""Called when an item label is changed to check if the document """Called when an item label is changed to check if the document
title bar needs updating, title bar needs updating,
""" """
if tHandle == self._docHandle: if tHandle and tHandle == self._docHandle:
self.docHeader.setTitleFromHandle(self._docHandle) self.docHeader.setHandle(tHandle)
self.docFooter.updateInfo() self.docFooter.updateInfo()
self.updateDocMargins() self.updateDocMargins()
return return
@@ -2909,6 +2909,20 @@ class GuiDocEditHeader(QWidget):
# Methods # Methods
## ##
def clearHeader(self) -> None:
"""Clear the header."""
self._docHandle = None
self._docOutline = {}
self.itemTitle.setText("")
self.outlineMenu.clear()
self.tbButton.setVisible(False)
self.searchButton.setVisible(False)
self.outlineButton.setVisible(False)
self.closeButton.setVisible(False)
self.minmaxButton.setVisible(False)
return
def setOutline(self, data: dict[int, str]) -> None: def setOutline(self, data: dict[int, str]) -> None:
"""Set the document outline dataset.""" """Set the document outline dataset."""
if data != self._docOutline: if data != self._docOutline:
@@ -2962,21 +2976,11 @@ class GuiDocEditHeader(QWidget):
return return
def setTitleFromHandle(self, tHandle: str | None) -> None: def setHandle(self, tHandle: str) -> None:
"""Set the document title from the handle, or alternatively, set """Set the document title from the handle, or alternatively, set
the whole document path within the project. the whole document path within the project.
""" """
self._docHandle = tHandle self._docHandle = tHandle
if tHandle is None:
self.itemTitle.setText("")
self.tbButton.setVisible(False)
self.searchButton.setVisible(False)
self.outlineButton.setVisible(False)
self.closeButton.setVisible(False)
self.minmaxButton.setVisible(False)
self.outlineMenu.clear()
self._docOutline = {}
return
if CONFIG.showFullPath: if CONFIG.showFullPath:
self.itemTitle.setText(f" {nwUnicode.U_RSAQUO} ".join(reversed( self.itemTitle.setText(f" {nwUnicode.U_RSAQUO} ".join(reversed(
@@ -3011,14 +3015,8 @@ class GuiDocEditHeader(QWidget):
@pyqtSlot() @pyqtSlot()
def _closeDocument(self) -> None: def _closeDocument(self) -> None:
"""Trigger the close editor on the main window.""" """Trigger the close editor on the main window."""
self.clearHeader()
self.closeDocumentRequest.emit() self.closeDocumentRequest.emit()
self.tbButton.setVisible(False)
self.searchButton.setVisible(False)
self.outlineButton.setVisible(False)
self.closeButton.setVisible(False)
self.minmaxButton.setVisible(False)
self.outlineMenu.clear()
self._docOutline = {}
return return
@pyqtSlot(int) @pyqtSlot(int)
+41 -46
View File
@@ -29,7 +29,6 @@ from __future__ import annotations
import logging import logging
from enum import Enum from enum import Enum
from typing import TYPE_CHECKING
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QPoint, QSize, Qt, QUrl from PyQt5.QtCore import pyqtSignal, pyqtSlot, QPoint, QSize, Qt, QUrl
from PyQt5.QtGui import ( from PyQt5.QtGui import (
@@ -48,9 +47,6 @@ from novelwriter.constants import nwUnicode
from novelwriter.core.tohtml import ToHtml from novelwriter.core.tohtml import ToHtml
from novelwriter.extensions.eventfilters import WheelEventFilter from novelwriter.extensions.eventfilters import WheelEventFilter
if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -58,17 +54,16 @@ class GuiDocViewer(QTextBrowser):
documentLoaded = pyqtSignal(str) documentLoaded = pyqtSignal(str)
loadDocumentTagRequest = pyqtSignal(str, Enum) loadDocumentTagRequest = pyqtSignal(str, Enum)
closeDocumentRequest = pyqtSignal()
reloadDocumentRequest = pyqtSignal()
togglePanelVisibility = pyqtSignal() togglePanelVisibility = pyqtSignal()
requestProjectItemSelected = pyqtSignal(str, bool) requestProjectItemSelected = pyqtSignal(str, bool)
def __init__(self, mainGui: GuiMain) -> None: def __init__(self, parent: QWidget) -> None:
super().__init__(parent=mainGui) super().__init__(parent=parent)
logger.debug("Create: GuiDocViewer") logger.debug("Create: GuiDocViewer")
# Class Variables
self.mainGui = mainGui
# Internal Variables # Internal Variables
self._docHandle = None self._docHandle = None
@@ -128,7 +123,7 @@ class GuiDocViewer(QTextBrowser):
self.clear() self.clear()
self.setSearchPaths([""]) self.setSearchPaths([""])
self._docHandle = None self._docHandle = None
self.docHeader.setTitleFromHandle(self._docHandle) self.docHeader.clearHeader()
return return
def updateTheme(self) -> None: def updateTheme(self) -> None:
@@ -184,8 +179,7 @@ class GuiDocViewer(QTextBrowser):
self.setTabStopDistance(CONFIG.getTabWidth()) self.setTabStopDistance(CONFIG.getTabWidth())
# If we have a document open, we should reload it in case the font changed # If we have a document open, we should reload it in case the font changed
if self._docHandle is not None: self.reloadText()
self.reloadText()
return return
@@ -239,7 +233,7 @@ class GuiDocViewer(QTextBrowser):
self._docHandle = tHandle self._docHandle = tHandle
SHARED.project.data.setLastHandle(tHandle, "viewer") SHARED.project.data.setLastHandle(tHandle, "viewer")
self.docHeader.setTitleFromHandle(self._docHandle) self.docHeader.setHandle(tHandle)
self.docHeader.setOutline({ self.docHeader.setOutline({
sTitle: hItem.title sTitle: hItem.title
for sTitle, hItem in SHARED.project.index.iterItemHeadings(tHandle) for sTitle, hItem in SHARED.project.index.iterItemHeadings(tHandle)
@@ -337,8 +331,8 @@ class GuiDocViewer(QTextBrowser):
@pyqtSlot(str) @pyqtSlot(str)
def updateDocInfo(self, tHandle: str) -> None: def updateDocInfo(self, tHandle: str) -> None:
"""Update the header title bar if needed.""" """Update the header title bar if needed."""
if tHandle == self._docHandle: if tHandle and tHandle == self._docHandle:
self.docHeader.setTitleFromHandle(self._docHandle) self.docHeader.setHandle(tHandle)
self.updateDocMargins() self.updateDocMargins()
return return
@@ -631,7 +625,6 @@ class GuiDocViewHeader(QWidget):
logger.debug("Create: GuiDocViewHeader") logger.debug("Create: GuiDocViewHeader")
self.docViewer = docViewer self.docViewer = docViewer
self.mainGui = docViewer.mainGui
# Internal Variables # Internal Variables
self._docHandle = None self._docHandle = None
@@ -646,18 +639,18 @@ class GuiDocViewHeader(QWidget):
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
# Title Label # Title Label
self.docTitle = QLabel() self.itemTitle = QLabel()
self.docTitle.setText("") self.itemTitle.setText("")
self.docTitle.setIndent(0) self.itemTitle.setIndent(0)
self.docTitle.setMargin(0) self.itemTitle.setMargin(0)
self.docTitle.setContentsMargins(0, 0, 0, 0) self.itemTitle.setContentsMargins(0, 0, 0, 0)
self.docTitle.setAutoFillBackground(True) self.itemTitle.setAutoFillBackground(True)
self.docTitle.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop) self.itemTitle.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop)
self.docTitle.setFixedHeight(fPx) self.itemTitle.setFixedHeight(fPx)
lblFont = self.docTitle.font() lblFont = self.itemTitle.font()
lblFont.setPointSizeF(0.9*SHARED.theme.fontPointSize) lblFont.setPointSizeF(0.9*SHARED.theme.fontPointSize)
self.docTitle.setFont(lblFont) self.itemTitle.setFont(lblFont)
# Other Widgets # Other Widgets
self.outlineMenu = QMenu(self) self.outlineMenu = QMenu(self)
@@ -715,7 +708,7 @@ class GuiDocViewHeader(QWidget):
self.outerBox.addWidget(self.backButton, 0) self.outerBox.addWidget(self.backButton, 0)
self.outerBox.addWidget(self.forwardButton, 0) self.outerBox.addWidget(self.forwardButton, 0)
self.outerBox.addWidget(self.outlineButton, 0) self.outerBox.addWidget(self.outlineButton, 0)
self.outerBox.addWidget(self.docTitle, 1) self.outerBox.addWidget(self.itemTitle, 1)
self.outerBox.addSpacing(fPx + hSp) self.outerBox.addSpacing(fPx + hSp)
self.outerBox.addWidget(self.refreshButton, 0) self.outerBox.addWidget(self.refreshButton, 0)
self.outerBox.addWidget(self.closeButton, 0) self.outerBox.addWidget(self.closeButton, 0)
@@ -739,6 +732,20 @@ class GuiDocViewHeader(QWidget):
# Methods # Methods
## ##
def clearHeader(self) -> None:
"""Clear the header."""
self._docHandle = None
self._docOutline = {}
self.itemTitle.setText("")
self.outlineMenu.clear()
self.backButton.setVisible(False)
self.forwardButton.setVisible(False)
self.outlineButton.setVisible(False)
self.closeButton.setVisible(False)
self.refreshButton.setVisible(False)
return
def setOutline(self, data: dict[int, str]) -> None: def setOutline(self, data: dict[int, str]) -> None:
"""Set the document outline dataset.""" """Set the document outline dataset."""
if data != self._docOutline: if data != self._docOutline:
@@ -785,31 +792,21 @@ class GuiDocViewHeader(QWidget):
palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.WindowText, SHARED.theme.colText)
palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText) palette.setColor(QPalette.ColorRole.Text, SHARED.theme.colText)
self.setPalette(palette) self.setPalette(palette)
self.docTitle.setPalette(palette) self.itemTitle.setPalette(palette)
return return
def setTitleFromHandle(self, tHandle: str | None) -> None: def setHandle(self, tHandle: str) -> None:
"""Sets the document title from the handle, or alternatively, """Sets the document title from the handle, or alternatively,
set the whole document path. set the whole document path.
""" """
self._docHandle = tHandle self._docHandle = tHandle
if tHandle is None:
self.docTitle.setText("")
self.backButton.setVisible(False)
self.forwardButton.setVisible(False)
self.outlineButton.setVisible(False)
self.closeButton.setVisible(False)
self.refreshButton.setVisible(False)
self.outlineMenu.clear()
self._docOutline = {}
return
if CONFIG.showFullPath: if CONFIG.showFullPath:
self.docTitle.setText(f" {nwUnicode.U_RSAQUO} ".join(reversed( self.itemTitle.setText(f" {nwUnicode.U_RSAQUO} ".join(reversed(
[name for name in SHARED.project.tree.getItemPath(tHandle, asName=True)] [name for name in SHARED.project.tree.getItemPath(tHandle, asName=True)]
))) )))
else: else:
self.docTitle.setText(i.itemName if (i := SHARED.project.tree[tHandle]) else "") self.itemTitle.setText(i.itemName if (i := SHARED.project.tree[tHandle]) else "")
self.backButton.setVisible(True) self.backButton.setVisible(True)
self.forwardButton.setVisible(True) self.forwardButton.setVisible(True)
@@ -832,15 +829,14 @@ class GuiDocViewHeader(QWidget):
@pyqtSlot() @pyqtSlot()
def _closeDocument(self) -> None: def _closeDocument(self) -> None:
"""Trigger the close editor/viewer on the main window.""" """Trigger the close editor/viewer on the main window."""
self.mainGui.closeDocViewer() self.clearHeader()
self.docViewer.closeDocumentRequest.emit()
return return
@pyqtSlot() @pyqtSlot()
def _refreshDocument(self) -> None: def _refreshDocument(self) -> None:
"""Reload the content of the document.""" """Reload the content of the document."""
if self.docViewer.docHandle == self.mainGui.docEditor.docHandle: self.docViewer.reloadDocumentRequest.emit()
self.mainGui.saveDocument()
self.docViewer.reloadText()
return return
## ##
@@ -871,7 +867,6 @@ class GuiDocViewFooter(QWidget):
logger.debug("Create: GuiDocViewFooter") logger.debug("Create: GuiDocViewFooter")
self.docViewer = docViewer self.docViewer = docViewer
self.mainGui = docViewer.mainGui
# Internal Variables # Internal Variables
self._docHandle = None self._docHandle = None
+3 -3
View File
@@ -196,12 +196,12 @@ class GuiMainMenu(QMenuBar):
# Document > Open # Document > Open
self.aOpenDoc = self.docuMenu.addAction(self.tr("Open Document")) self.aOpenDoc = self.docuMenu.addAction(self.tr("Open Document"))
self.aOpenDoc.setShortcut("Ctrl+O") self.aOpenDoc.setShortcut("Ctrl+O")
self.aOpenDoc.triggered.connect(lambda: self.mainGui.openSelectedItem()) self.aOpenDoc.triggered.connect(self.mainGui.openSelectedItem)
# Document > Save # Document > Save
self.aSaveDoc = self.docuMenu.addAction(self.tr("Save Document")) self.aSaveDoc = self.docuMenu.addAction(self.tr("Save Document"))
self.aSaveDoc.setShortcut("Ctrl+S") self.aSaveDoc.setShortcut("Ctrl+S")
self.aSaveDoc.triggered.connect(lambda: self.mainGui.saveDocument()) self.aSaveDoc.triggered.connect(self.mainGui.saveDocument)
# Document > Close # Document > Close
self.aCloseDoc = self.docuMenu.addAction(self.tr("Close Document")) self.aCloseDoc = self.docuMenu.addAction(self.tr("Close Document"))
@@ -219,7 +219,7 @@ class GuiMainMenu(QMenuBar):
# Document > Close Preview # Document > Close Preview
self.aCloseView = self.docuMenu.addAction(self.tr("Close Document View")) self.aCloseView = self.docuMenu.addAction(self.tr("Close Document View"))
self.aCloseView.setShortcut("Ctrl+Shift+R") self.aCloseView.setShortcut("Ctrl+Shift+R")
self.aCloseView.triggered.connect(lambda: self.mainGui.closeDocViewer()) self.aCloseView.triggered.connect(self.mainGui.closeDocViewer)
# Document > Separator # Document > Separator
self.docuMenu.addSeparator() self.docuMenu.addSeparator()
+49 -36
View File
@@ -278,6 +278,8 @@ class GuiMain(QMainWindow):
self.docViewer.documentLoaded.connect(self.docViewerPanel.updateHandle) self.docViewer.documentLoaded.connect(self.docViewerPanel.updateHandle)
self.docViewer.loadDocumentTagRequest.connect(self._followTag) self.docViewer.loadDocumentTagRequest.connect(self._followTag)
self.docViewer.closeDocumentRequest.connect(self.closeDocViewer)
self.docViewer.reloadDocumentRequest.connect(self._reloadViewer)
self.docViewer.togglePanelVisibility.connect(self._toggleViewerPanelVisibility) self.docViewer.togglePanelVisibility.connect(self._toggleViewerPanelVisibility)
self.docViewer.requestProjectItemSelected.connect(self.projView.setSelectedHandle) self.docViewer.requestProjectItemSelected.connect(self.projView.setSelectedHandle)
@@ -401,7 +403,7 @@ class GuiMain(QMainWindow):
if saveOK: if saveOK:
self.closeDocument() self.closeDocument()
self.docViewer.clearNavHistory() self.docViewer.clearNavHistory()
self.closeDocViewer(byUser=False) self.closeViewerPanel(byUser=False)
self.docViewerPanel.closeProjectTasks() self.docViewerPanel.closeProjectTasks()
self.outlineView.closeProjectTasks() self.outlineView.closeProjectTasks()
@@ -604,13 +606,12 @@ class GuiMain(QMainWindow):
return False return False
def saveDocument(self) -> bool: @pyqtSlot()
def saveDocument(self) -> None:
"""Save the current documents.""" """Save the current documents."""
if not SHARED.hasProject: if SHARED.hasProject:
logger.error("No project open") self.docEditor.saveText()
return False return
self.docEditor.saveText()
return True
def viewDocument(self, tHandle: str | None = None, sTitle: str | None = None) -> bool: def viewDocument(self, tHandle: str | None = None, sTitle: str | None = None) -> bool:
"""Load a document for viewing in the view panel.""" """Load a document for viewing in the view panel."""
@@ -640,7 +641,8 @@ class GuiMain(QMainWindow):
self._changeView(nwView.EDITOR) self._changeView(nwView.EDITOR)
logger.debug("Viewing document with handle '%s'", tHandle) logger.debug("Viewing document with handle '%s'", tHandle)
if self.docViewer.loadText(tHandle): updateHistory = tHandle != self.docViewer.docHandle
if self.docViewer.loadText(tHandle, updateHistory=updateHistory):
if not self.splitView.isVisible(): if not self.splitView.isVisible():
cursorVisible = self.docEditor.cursorIsVisible() cursorVisible = self.docEditor.cursorIsVisible()
bPos = self.splitMain.sizes() bPos = self.splitMain.sizes()
@@ -713,37 +715,32 @@ class GuiMain(QMainWindow):
# Tree Item Actions # Tree Item Actions
## ##
def openSelectedItem(self) -> bool: @pyqtSlot()
def openSelectedItem(self) -> None:
"""Open the selected item from the tree that is currently """Open the selected item from the tree that is currently
active. It is not checked that the item is actually a document. active. It is not checked that the item is actually a document.
That should be handled by the openDocument function. That should be handled by the openDocument function.
""" """
if not SHARED.hasProject: if SHARED.hasProject:
logger.error("No project open") tHandle = None
return False sTitle = None
tLine = None
tHandle = None if self.projView.treeHasFocus():
sTitle = None tHandle = self.projView.getSelectedHandle()
tLine = None elif self.novelView.treeHasFocus():
if self.projView.treeHasFocus(): tHandle, sTitle = self.novelView.getSelectedHandle()
tHandle = self.projView.getSelectedHandle() elif self.outlineView.treeHasFocus():
elif self.novelView.treeHasFocus(): tHandle, sTitle = self.outlineView.getSelectedHandle()
tHandle, sTitle = self.novelView.getSelectedHandle() else:
elif self.outlineView.treeHasFocus(): logger.warning("No item selected")
tHandle, sTitle = self.outlineView.getSelectedHandle() return False
else: if tHandle is not None and sTitle is not None:
logger.warning("No item selected") hItem = SHARED.project.index.getItemHeading(tHandle, sTitle)
return False if hItem is not None:
tLine = hItem.line
if tHandle is not None and sTitle is not None: if tHandle is not None:
hItem = SHARED.project.index.getItemHeading(tHandle, sTitle) self.openDocument(tHandle, tLine=tLine, changeFocus=False, doScroll=False)
if hItem is not None: return
tLine = hItem.line
if tHandle is not None:
self.openDocument(tHandle, tLine=tLine, changeFocus=False, doScroll=False)
return True
def editItemLabel(self, tHandle: str | None = None) -> bool: def editItemLabel(self, tHandle: str | None = None) -> bool:
"""Open the edit item dialog.""" """Open the edit item dialog."""
@@ -943,7 +940,7 @@ class GuiMain(QMainWindow):
return True return True
def closeDocViewer(self, byUser: bool = True) -> bool: def closeViewerPanel(self, byUser: bool = True) -> bool:
"""Close the document view panel.""" """Close the document view panel."""
self.docViewer.clearViewer() self.docViewer.clearViewer()
if byUser: if byUser:
@@ -991,6 +988,13 @@ class GuiMain(QMainWindow):
SHARED.project.data.setLastHandle(None, "editor") SHARED.project.data.setLastHandle(None, "editor")
return return
@pyqtSlot()
def closeDocViewer(self) -> None:
"""Close the document viewer."""
self.closeViewerPanel()
SHARED.project.data.setLastHandle(None, "viewer")
return
@pyqtSlot() @pyqtSlot()
def toggleFocusMode(self) -> None: def toggleFocusMode(self) -> None:
"""Handle toggle focus mode. The Main GUI Focus Mode hides tree, """Handle toggle focus mode. The Main GUI Focus Mode hides tree,
@@ -1154,6 +1158,15 @@ class GuiMain(QMainWindow):
self.viewDocument(tHandle=tHandle, sTitle=sTitle) self.viewDocument(tHandle=tHandle, sTitle=sTitle)
return return
@pyqtSlot()
def _reloadViewer(self) -> None:
"""Reload the document in the viewer."""
if self.docEditor.docChanged and self.docEditor.docHandle == self.docViewer.docHandle:
# If the two panels have the same document, save any changes in the editor
self.saveDocument()
self.docViewer.reloadText()
return
@pyqtSlot(nwView) @pyqtSlot(nwView)
def _changeView(self, view: nwView) -> None: def _changeView(self, view: nwView) -> None:
"""Handle the requested change of view from the GuiViewBar.""" """Handle the requested change of view from the GuiViewBar."""
+6 -6
View File
@@ -47,7 +47,7 @@ def testGuiEditor_Init(qtbot, nwGUI, projPath, ipsumText, mockRnd):
assert nwGUI.openDocument(C.hSceneDoc) assert nwGUI.openDocument(C.hSceneDoc)
nwGUI.docEditor.setPlainText("### Lorem Ipsum\n\n%s" % ipsumText[0]) nwGUI.docEditor.setPlainText("### Lorem Ipsum\n\n%s" % ipsumText[0])
assert nwGUI.saveDocument() nwGUI.saveDocument()
# Check Defaults # Check Defaults
qDoc = nwGUI.docEditor.document() qDoc = nwGUI.docEditor.document()
@@ -122,7 +122,7 @@ def testGuiEditor_LoadText(qtbot, nwGUI, projPath, ipsumText, mockRnd):
longText = "### Lorem Ipsum\n\n%s" % "\n\n".join(ipsumText*20) longText = "### Lorem Ipsum\n\n%s" % "\n\n".join(ipsumText*20)
nwGUI.docEditor.replaceText(longText) nwGUI.docEditor.replaceText(longText)
assert nwGUI.saveDocument() is True nwGUI.saveDocument()
assert nwGUI.closeDocument() is True assert nwGUI.closeDocument() is True
# Invalid handle # Invalid handle
@@ -138,7 +138,7 @@ def testGuiEditor_LoadText(qtbot, nwGUI, projPath, ipsumText, mockRnd):
# Load empty document # Load empty document
nwGUI.docEditor.replaceText("") nwGUI.docEditor.replaceText("")
assert nwGUI.saveDocument() is True nwGUI.saveDocument()
assert nwGUI.docEditor.loadText(C.hSceneDoc) is True assert nwGUI.docEditor.loadText(C.hSceneDoc) is True
assert nwGUI.docEditor.toPlainText() == "" assert nwGUI.docEditor.toPlainText() == ""
@@ -1484,7 +1484,7 @@ def testGuiEditor_Tags(qtbot, nwGUI, projPath, ipsumText, mockRnd):
cHandle = SHARED.project.newFile("Jane Doe", C.hCharRoot) cHandle = SHARED.project.newFile("Jane Doe", C.hCharRoot)
assert nwGUI.openDocument(cHandle) is True assert nwGUI.openDocument(cHandle) is True
nwGUI.docEditor.replaceText(text) nwGUI.docEditor.replaceText(text)
assert nwGUI.saveDocument() is True nwGUI.saveDocument()
assert nwGUI.projView.projTree.revealNewTreeItem(cHandle) assert nwGUI.projView.projTree.revealNewTreeItem(cHandle)
nwGUI.docEditor.updateTagHighLighting() nwGUI.docEditor.updateTagHighLighting()
@@ -1514,7 +1514,7 @@ def testGuiEditor_Tags(qtbot, nwGUI, projPath, ipsumText, mockRnd):
assert nwGUI.docViewer._docHandle is None assert nwGUI.docViewer._docHandle is None
assert nwGUI.docEditor._processTag(follow=True) is nwTrinary.POSITIVE assert nwGUI.docEditor._processTag(follow=True) is nwTrinary.POSITIVE
assert nwGUI.docViewer._docHandle == cHandle assert nwGUI.docViewer._docHandle == cHandle
assert nwGUI.closeDocViewer() is True assert nwGUI.closeViewerPanel() is True
assert nwGUI.docViewer._docHandle is None assert nwGUI.docViewer._docHandle is None
# On Unknown Tag, Create It # On Unknown Tag, Create It
@@ -1553,7 +1553,7 @@ def testGuiEditor_Completer(qtbot, nwGUI, projPath, mockRnd):
cHandle = SHARED.project.newFile("People", C.hCharRoot) cHandle = SHARED.project.newFile("People", C.hCharRoot)
assert nwGUI.openDocument(cHandle) is True assert nwGUI.openDocument(cHandle) is True
nwGUI.docEditor.replaceText(text) nwGUI.docEditor.replaceText(text)
assert nwGUI.saveDocument() is True nwGUI.saveDocument()
assert nwGUI.projView.projTree.revealNewTreeItem(cHandle) assert nwGUI.projView.projTree.revealNewTreeItem(cHandle)
docEditor = nwGUI.docEditor docEditor = nwGUI.docEditor
+2 -2
View File
@@ -185,12 +185,12 @@ def testGuiViewer_Main(qtbot, monkeypatch, nwGUI, prjLipsum):
nwItem.setName("Test Title") # type: ignore nwItem.setName("Test Title") # type: ignore
assert nwItem.itemName == "Test Title" # type: ignore assert nwItem.itemName == "Test Title" # type: ignore
docViewer.updateDocInfo("4c4f28287af27") docViewer.updateDocInfo("4c4f28287af27")
assert docViewer.docHeader.docTitle.text() == "Characters \u203a Test Title" assert docViewer.docHeader.itemTitle.text() == "Characters \u203a Test Title"
# Title without full path # Title without full path
CONFIG.showFullPath = False CONFIG.showFullPath = False
docViewer.updateDocInfo("4c4f28287af27") docViewer.updateDocInfo("4c4f28287af27")
assert docViewer.docHeader.docTitle.text() == "Test Title" assert docViewer.docHeader.itemTitle.text() == "Test Title"
CONFIG.showFullPath = True CONFIG.showFullPath = True
# Document footer show/hide synopsis # Document footer show/hide synopsis
+9 -10
View File
@@ -52,10 +52,8 @@ def testGuiMain_ProjectBlocker(nwGUI):
assert nwGUI.closeDocument() is False assert nwGUI.closeDocument() is False
assert nwGUI.openDocument(None) is False assert nwGUI.openDocument(None) is False
assert nwGUI.openNextDocument(None) is False assert nwGUI.openNextDocument(None) is False
assert nwGUI.saveDocument() is False
assert nwGUI.viewDocument(None) is False assert nwGUI.viewDocument(None) is False
assert nwGUI.importDocument() is False assert nwGUI.importDocument() is False
assert nwGUI.openSelectedItem() is False
assert nwGUI.editItemLabel() is False assert nwGUI.editItemLabel() is False
assert nwGUI.rebuildIndex() is False assert nwGUI.rebuildIndex() is False
@@ -109,7 +107,8 @@ def testGuiMain_ProjectTreeItems(qtbot, monkeypatch, nwGUI, projPath, mockRnd):
buildTestProject(nwGUI, projPath) buildTestProject(nwGUI, projPath)
sHandle = "000000000000f" sHandle = "000000000000f"
assert nwGUI.openSelectedItem() is False nwGUI.openSelectedItem()
assert nwGUI.docEditor.docHandle is None
# Project Tree has focus # Project Tree has focus
nwGUI._changeView(nwView.PROJECT) nwGUI._changeView(nwView.PROJECT)
@@ -238,7 +237,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
nwGUI.projView.projTree.clearSelection() nwGUI.projView.projTree.clearSelection()
nwGUI.projView.projTree._getTreeItem(C.hCharRoot).setSelected(True) nwGUI.projView.projTree._getTreeItem(C.hCharRoot).setSelected(True)
nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True) nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True)
assert nwGUI.openSelectedItem() nwGUI.openSelectedItem()
# Text Editor # Text Editor
# =========== # ===========
@@ -265,7 +264,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
nwGUI.projView.projTree.clearSelection() nwGUI.projView.projTree.clearSelection()
nwGUI.projView.projTree._getTreeItem(C.hPlotRoot).setSelected(True) nwGUI.projView.projTree._getTreeItem(C.hPlotRoot).setSelected(True)
nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True) nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True)
assert nwGUI.openSelectedItem() nwGUI.openSelectedItem()
# Type something into the document # Type something into the document
nwGUI.switchFocus(nwWidget.EDITOR) nwGUI.switchFocus(nwWidget.EDITOR)
@@ -287,7 +286,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
nwGUI.projView.projTree.clearSelection() nwGUI.projView.projTree.clearSelection()
nwGUI.projView.projTree._getTreeItem(C.hWorldRoot).setSelected(True) nwGUI.projView.projTree._getTreeItem(C.hWorldRoot).setSelected(True)
nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True) nwGUI.projView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True)
assert nwGUI.openSelectedItem() nwGUI.openSelectedItem()
# Add Some Text # Add Some Text
docEditor.replaceText("Hello World!") docEditor.replaceText("Hello World!")
@@ -319,7 +318,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
nwGUI.projView.projTree._getTreeItem(C.hNovelRoot).setExpanded(True) nwGUI.projView.projTree._getTreeItem(C.hNovelRoot).setExpanded(True)
nwGUI.projView.projTree._getTreeItem(C.hChapterDir).setExpanded(True) nwGUI.projView.projTree._getTreeItem(C.hChapterDir).setExpanded(True)
nwGUI.projView.projTree._getTreeItem(C.hSceneDoc).setSelected(True) nwGUI.projView.projTree._getTreeItem(C.hSceneDoc).setSelected(True)
assert nwGUI.openSelectedItem() nwGUI.openSelectedItem()
# Type something into the document # Type something into the document
nwGUI.switchFocus(nwWidget.EDITOR) nwGUI.switchFocus(nwWidget.EDITOR)
@@ -524,8 +523,8 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
# Save the document # Save the document
assert docEditor.docChanged assert docEditor.docChanged
assert nwGUI.saveDocument() nwGUI.saveDocument()
assert not docEditor.docChanged assert docEditor.docChanged is False
nwGUI.rebuildIndex() nwGUI.rebuildIndex()
# Open and view the edited document # Open and view the edited document
@@ -533,7 +532,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
assert nwGUI.openDocument(C.hSceneDoc) assert nwGUI.openDocument(C.hSceneDoc)
assert nwGUI.viewDocument(C.hSceneDoc) assert nwGUI.viewDocument(C.hSceneDoc)
assert nwGUI.saveProject() assert nwGUI.saveProject()
assert nwGUI.closeDocViewer() assert nwGUI.closeViewerPanel()
# Check the files # Check the files
projFile = projPath / "nwProject.nwx" projFile = projPath / "nwProject.nwx"