From 46bb8e5bccf2704f3db3055d609a81b2b1f4827e Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Mon, 6 Jun 2022 22:03:42 +0200 Subject: [PATCH] Populate the add button menu in the project widget --- novelwriter/core/index.py | 5 - novelwriter/gui/projtree.py | 158 +++++++++++++----- sample/nwProject.nwx | 10 +- ...> coreProject_NewFileFolder_nwProject.nwx} | 30 ++-- tests/test_core/test_core_index.py | 3 - tests/test_dialogs/test_dlg_docmerge.py | 3 +- tests/test_dialogs/test_dlg_docsplit.py | 3 +- tests/test_dialogs/test_dlg_itemeditor.py | 5 +- tests/test_gui/test_gui_guimain.py | 9 +- tests/test_gui/test_gui_projtree.py | 40 +++-- 10 files changed, 180 insertions(+), 86 deletions(-) rename tests/reference/{coreProject_NewFile_nwProject.nwx => coreProject_NewFileFolder_nwProject.nwx} (76%) diff --git a/novelwriter/core/index.py b/novelwriter/core/index.py index f86de8c2..ee9ea089 100644 --- a/novelwriter/core/index.py +++ b/novelwriter/core/index.py @@ -502,11 +502,6 @@ class NWIndex: """ return self._itemIndex.mainItemHeader(tHandle) - def getHandleHeaderIntLevel(self, tHandle): - """Get the integer header level of the first header of a handle. - """ - return H_LEVEL.get(self._itemIndex.mainItemHeader(tHandle), 0) - def getTableOfContents(self, maxDepth, skipExcl=True): """Generate a table of contents up to a maximum depth. """ diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index 7286f87f..2e58a61d 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -37,13 +37,13 @@ from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import ( QTreeWidget, QTreeWidgetItem, QAbstractItemView, QMenu, QAction, QFrame, QDialog, QHeaderView, QWidget, QVBoxLayout, QToolBar, QLabel, QToolButton, - QSizePolicy + QSizePolicy, QInputDialog ) from novelwriter.core import NWDoc from novelwriter.enum import nwDocMode, nwItemType, nwItemClass, nwItemLayout, nwAlert -from novelwriter.common import minmax from novelwriter.dialogs.itemeditor import GuiItemEditor +from novelwriter.constants import trConst, nwLabels logger = logging.getLogger(__name__) @@ -82,6 +82,8 @@ class GuiProjectWiew(QWidget): self.setLayout(self.outerBox) + # Connect Signals + # Function Mappings self.newTreeItem = self.projTree.newTreeItem self.revealNewTreeItem = self.projTree.revealNewTreeItem @@ -139,12 +141,19 @@ class GuiProjectWiew(QWidget): class GuiProjectToolBar(QToolBar): + ADD_PLAIN = 0 + ADD_CHAP = 1 + ADD_SCENE = 2 + ADD_NOTE = 3 + ADD_FOLDER = 4 + def __init__(self, theWidget): QTreeWidget.__init__(self, theWidget) logger.debug("Initialising GuiProjectToolBar ...") self.mainConf = novelwriter.CONFIG + self.theWidget = theWidget self.theParent = theWidget.theParent self.theProject = theWidget.theParent.theProject self.theTheme = theWidget.theParent.theTheme @@ -157,14 +166,49 @@ class GuiProjectToolBar(QToolBar): self.setContentsMargins(0, 0, 0, 0) self.setStyleSheet("QToolBar {border: 0px;}") - # Novel Selector + # Tree Label self.projLabel = QLabel(self.tr("Project")) self.projLabel.setContentsMargins(0, 0, mPx, 0) self.projLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) - # Itemss Menu + # Items Menu + self.mItems = QMenu() + + self.aAddEmpty = self.mItems.addAction(self.tr("Plain Document")) + self.aAddEmpty.setIcon(self.theTheme.getIcon("proj_document")) + self.aAddEmpty.triggered.connect(lambda: self._forwardNewItem(self.ADD_PLAIN)) + + self.aAddChap = self.mItems.addAction(self.tr("Chapter Document")) + self.aAddChap.setIcon(self.theTheme.getIcon("proj_chapter")) + self.aAddChap.triggered.connect(lambda: self._forwardNewItem(self.ADD_CHAP)) + + self.aAddScene = self.mItems.addAction(self.tr("Scene Document")) + self.aAddScene.setIcon(self.theTheme.getIcon("proj_scene")) + self.aAddScene.triggered.connect(lambda: self._forwardNewItem(self.ADD_SCENE)) + + self.aAddNote = self.mItems.addAction(self.tr("Project Note")) + self.aAddNote.setIcon(self.theTheme.getIcon("proj_note")) + self.aAddNote.triggered.connect(lambda: self._forwardNewItem(self.ADD_NOTE)) + + self.aAddFolder = self.mItems.addAction(self.tr("Folder")) + self.aAddFolder.setIcon(self.theTheme.getIcon("proj_folder")) + self.aAddFolder.triggered.connect(lambda: self._forwardNewItem(self.ADD_FOLDER)) + + self.mAddRoot = self.mItems.addMenu(self.tr("Root Folder")) + self._addRootFolderEntry(nwItemClass.NOVEL) + self._addRootFolderEntry(nwItemClass.ARCHIVE) + self.mAddRoot.addSeparator() + self._addRootFolderEntry(nwItemClass.PLOT) + self._addRootFolderEntry(nwItemClass.CHARACTER) + self._addRootFolderEntry(nwItemClass.WORLD) + self._addRootFolderEntry(nwItemClass.ARCHIVE) + self._addRootFolderEntry(nwItemClass.OBJECT) + self._addRootFolderEntry(nwItemClass.ENTITY) + self._addRootFolderEntry(nwItemClass.CUSTOM) + self.tbItems = QToolButton(self) self.tbItems.setIcon(self.theTheme.getIcon("add")) + self.tbItems.setMenu(self.mItems) self.tbItems.setPopupMode(QToolButton.InstantPopup) # Settings Menu @@ -182,6 +226,45 @@ class GuiProjectToolBar(QToolBar): return + ## + # Private Slots + ## + + @pyqtSlot(Enum) + def _forwardNewRootFolder(self, itemClass): + """Forward the request for a new root folder to the tree. + """ + self.theWidget.projTree.newTreeItem(nwItemType.ROOT, itemClass) + return + + @pyqtSlot(int) + def _forwardNewItem(self, type): + """Forward the request for a new item of a given type. + """ + if type == self.ADD_PLAIN: + self.theWidget.projTree.newTreeItem(nwItemType.FILE, hLevel=0, isNote=False) + elif type == self.ADD_CHAP: + self.theWidget.projTree.newTreeItem(nwItemType.FILE, hLevel=2, isNote=False) + elif type == self.ADD_SCENE: + self.theWidget.projTree.newTreeItem(nwItemType.FILE, hLevel=3, isNote=False) + elif type == self.ADD_NOTE: + self.theWidget.projTree.newTreeItem(nwItemType.FILE, hLevel=1, isNote=True) + elif type == self.ADD_FOLDER: + self.theWidget.projTree.newTreeItem(nwItemType.FOLDER) + return + + ## + # Internal Functions + ## + + def _addRootFolderEntry(self, itemClass): + """Add a menu entry for a root folder of a given class. + """ + aNew = self.mAddRoot.addAction(trConst(nwLabels.CLASS_NAME[itemClass])) + aNew.setIcon(self.theTheme.getIcon(nwLabels.CLASS_ICON[itemClass])) + aNew.triggered.connect(lambda: self._forwardNewRootFolder(itemClass)) + self.mAddRoot.addAction(aNew) + # END Class GuiProjectToolBar @@ -291,7 +374,7 @@ class GuiProjectTree(QTreeWidget): self._timeChanged = 0 return - def newTreeItem(self, itemType, itemClass=None): + def newTreeItem(self, itemType, itemClass=None, hLevel=1, isNote=False): """Add new item to the tree, with a given itemType (and itemClass if Root), and attach it to the selected handle. Also make sure the item is added in a place it can be added, and that @@ -334,52 +417,49 @@ class GuiProjectTree(QTreeWidget): ), nwAlert.ERROR) return False + # Ask for label + if itemType == nwItemType.FILE: + if isNote: + newLabel = self.tr("New Note") + elif hLevel == 2: + newLabel = self.tr("New Chapter") + elif hLevel == 3: + newLabel = self.tr("New Scene") + else: + newLabel = self.tr("New Document") + else: + newLabel = self.tr("New Folder") + + newLabel, dlgOk = QInputDialog.getText(self, "", self.tr("Label:"), text=newLabel) + if not dlgOk: + logger.info("New item creation cancelled by user") + return False + # Add the file or folder if itemType == nwItemType.FILE: - if pItem.isNovelLike(): - tHandle = self.theProject.newFile(self.tr("New Document"), sHandle) - else: - tHandle = self.theProject.newFile(self.tr("New Note"), sHandle) - elif itemType == nwItemType.FOLDER: - tHandle = self.theProject.newFolder(self.tr("New Folder"), sHandle) + tHandle = self.theProject.newFile(newLabel, sHandle) + else: + tHandle = self.theProject.newFolder(newLabel, sHandle) else: logger.error("Failed to add new item") return False - # If there is no handle set, return here. This is a bug + # If there is no handle set, return here. This is a bug. if tHandle is None: # pragma: no cover + logger.error("Internal error") return True - # Add the new item to the tree and open the editor dialog - self.revealNewTreeItem(tHandle, nHandle) - self.editTreeItem(tHandle) - # Handle new file creation - nwItem = self.theProject.tree[tHandle] - if nwItem.itemType != nwItemType.FILE: - return True + if itemType == nwItemType.FILE and hLevel > 0: + if self.theProject.writeNewFile(tHandle, hLevel, not isNote): + # If successful, update word count + wC = self.theProject.index.getCounts(tHandle)[1] + self.propagateCount(tHandle, wC) + self.theWidget.wordCountsChanged.emit() - # This is a new file, so let's add some content - newDoc = NWDoc(self.theProject, tHandle) - if not newDoc.readDocument(): - if nwItem.itemLayout == nwItemLayout.DOCUMENT: - iLvl = self.theProject.index.getHandleHeaderIntLevel(sHandle) - hLvl = "#"*minmax(iLvl + 1, 2, 4) - newText = f"{hLvl} {nwItem.itemName}\n\n" - else: - newText = f"# {nwItem.itemName}\n\n" - - pIndex = self.theProject.index - - # Save the text and index it - newDoc.writeDocument(newText) - pIndex.scanText(tHandle, newText) - - # Get Word Counts - _, wC, _ = pIndex.getCounts(tHandle) - self.propagateCount(tHandle, wC) - self.theWidget.wordCountsChanged.emit() + # Add the new item to the project tree + self.revealNewTreeItem(tHandle, nHandle) return True diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 9f3a6587..4dd6396a 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,13 +1,13 @@ - + Sample Project Sample Project Jane Smith Jay Doh - 1334 - 225 - 67746 + 1342 + 227 + 68090 False @@ -15,7 +15,7 @@ True None True - a520879ca0b45 + 636b6aa9b697b 636b6aa9b697b 1363 954 diff --git a/tests/reference/coreProject_NewFile_nwProject.nwx b/tests/reference/coreProject_NewFileFolder_nwProject.nwx similarity index 76% rename from tests/reference/coreProject_NewFile_nwProject.nwx rename to tests/reference/coreProject_NewFileFolder_nwProject.nwx index 19a2f4bf..4235e9bb 100644 --- a/tests/reference/coreProject_NewFile_nwProject.nwx +++ b/tests/reference/coreProject_NewFileFolder_nwProject.nwx @@ -1,5 +1,5 @@ - + New Project New Novel @@ -16,9 +16,9 @@ True None None - 0 - 0 - 0 + 2 + 1 + 1 %title% @@ -28,19 +28,19 @@
- New + New Note Draft Finished - New + New Minor Major Main
- + Novel @@ -73,13 +73,17 @@ New Scene - - - Hello + + + Stuff - - - Jane + + + Hello + + + + Jane
diff --git a/tests/test_core/test_core_index.py b/tests/test_core/test_core_index.py index 3d40a9df..8f126e56 100644 --- a/tests/test_core/test_core_index.py +++ b/tests/test_core/test_core_index.py @@ -232,9 +232,6 @@ def testCoreIndex_CheckThese(mockGUI, fncDir, mockRnd): assert theIndex.getHandleHeaderLevel(cHandle) == "H1" assert theIndex.getHandleHeaderLevel(nHandle) == "H1" - assert theIndex.getHandleHeaderIntLevel(cHandle) == 1 - assert theIndex.getHandleHeaderIntLevel(nHandle) == 1 - assert theIndex.getHandleHeaderIntLevel("stuff") == 0 # Zero Items assert theIndex.checkThese([], cItem) == [] diff --git a/tests/test_dialogs/test_dlg_docmerge.py b/tests/test_dialogs/test_dlg_docmerge.py index ce5c68d4..f796f864 100644 --- a/tests/test_dialogs/test_dlg_docmerge.py +++ b/tests/test_dialogs/test_dlg_docmerge.py @@ -25,7 +25,7 @@ import pytest from mock import causeOSError from tools import getGuiItem, readFile, writeFile, buildTestProject -from PyQt5.QtWidgets import QAction, QMessageBox, QDialog +from PyQt5.QtWidgets import QAction, QMessageBox, QDialog, QInputDialog from novelwriter.enum import nwItemType, nwWidget from novelwriter.dialogs import GuiDocMerge, GuiItemEditor @@ -39,6 +39,7 @@ def testDlgMerge_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): # Block message box monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok) + monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True)) # Create a new project buildTestProject(nwGUI, fncProj) diff --git a/tests/test_dialogs/test_dlg_docsplit.py b/tests/test_dialogs/test_dlg_docsplit.py index 0e3174c7..080be8ab 100644 --- a/tests/test_dialogs/test_dlg_docsplit.py +++ b/tests/test_dialogs/test_dlg_docsplit.py @@ -25,7 +25,7 @@ import pytest from mock import causeOSError from tools import getGuiItem, readFile, writeFile, buildTestProject -from PyQt5.QtWidgets import QAction, QMessageBox, QDialog +from PyQt5.QtWidgets import QAction, QMessageBox, QDialog, QInputDialog from novelwriter.enum import nwItemType, nwWidget from novelwriter.dialogs import GuiDocSplit, GuiItemEditor @@ -40,6 +40,7 @@ def testDlgSplit_Main(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): # Block message box monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Ok) + monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True)) # Create a new project buildTestProject(nwGUI, fncProj) diff --git a/tests/test_dialogs/test_dlg_itemeditor.py b/tests/test_dialogs/test_dlg_itemeditor.py index 501d1e3b..53426df7 100644 --- a/tests/test_dialogs/test_dlg_itemeditor.py +++ b/tests/test_dialogs/test_dlg_itemeditor.py @@ -23,7 +23,7 @@ import pytest from tools import getGuiItem, buildTestProject -from PyQt5.QtWidgets import QAction, QDialog, QMessageBox +from PyQt5.QtWidgets import QAction, QDialog, QMessageBox, QInputDialog from novelwriter.enum import nwItemLayout, nwItemType from novelwriter.dialogs import GuiItemEditor @@ -154,6 +154,7 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): # Block message box monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) + monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True)) # Create Project and Open Document buildTestProject(nwGUI, fncProj) @@ -165,7 +166,7 @@ def testDlgItemEditor_Note(qtbot, monkeypatch, nwGUI, fncProj, mockRnd): # Create Note nwGUI.treeView.projTree.clearSelection() nwGUI.treeView.projTree._getTreeItem("000000000000a").setSelected(True) - nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None) + nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True) # Open Note assert nwGUI.openDocument("0000000000010") diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index 78c2af66..6085c59b 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -26,7 +26,7 @@ from shutil import copyfile from tools import cmpFiles, buildTestProject, XML_IGNORE, writeFile from PyQt5.QtCore import Qt -from PyQt5.QtWidgets import QMessageBox, QDialog +from PyQt5.QtWidgets import QMessageBox, QDialog, QInputDialog from novelwriter.gui import GuiDocEditor, GuiNovelTree, GuiOutline from novelwriter.enum import nwItemType, nwWidget @@ -173,6 +173,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock monkeypatch.setattr(GuiItemEditor, "result", lambda *a: QDialog.Accepted) monkeypatch.setattr(GuiProjectTree, "hasFocus", lambda *a: True) monkeypatch.setattr(GuiDocEditor, "hasFocus", lambda *a: True) + monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True)) # Create new, save, close project buildTestProject(nwGUI, fncProj) @@ -241,7 +242,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock nwGUI.switchFocus(nwWidget.TREE) nwGUI.treeView.projTree.clearSelection() nwGUI.treeView.projTree._getTreeItem("000000000000a").setSelected(True) - nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None) + nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True) assert nwGUI.openSelectedItem() # Type something into the document @@ -263,7 +264,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock nwGUI.switchFocus(nwWidget.TREE) nwGUI.treeView.projTree.clearSelection() nwGUI.treeView.projTree._getTreeItem("0000000000009").setSelected(True) - nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None) + nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True) assert nwGUI.openSelectedItem() # Type something into the document @@ -285,7 +286,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, fncProj, refDir, outDir, mock nwGUI.switchFocus(nwWidget.TREE) nwGUI.treeView.projTree.clearSelection() nwGUI.treeView.projTree._getTreeItem("000000000000b").setSelected(True) - nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None) + nwGUI.treeView.projTree.newTreeItem(nwItemType.FILE, None, isNote=True) assert nwGUI.openSelectedItem() # Add Some Text diff --git a/tests/test_gui/test_gui_projtree.py b/tests/test_gui/test_gui_projtree.py index 7b66f305..81c9a801 100644 --- a/tests/test_gui/test_gui_projtree.py +++ b/tests/test_gui/test_gui_projtree.py @@ -24,9 +24,8 @@ import os from tools import buildTestProject -from PyQt5.QtWidgets import QAction, QMessageBox +from PyQt5.QtWidgets import QAction, QMessageBox, QInputDialog -from novelwriter.guimain import GuiMain from novelwriter.gui.projtree import GuiProjectTree from novelwriter.enum import nwItemType, nwItemClass @@ -40,7 +39,7 @@ def testGuiProjTree_NewItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd) monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) - monkeypatch.setattr(GuiMain, "editItem", lambda *a: None) + monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True)) nwTree = nwGUI.treeView @@ -89,22 +88,31 @@ def testGuiProjTree_NewItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd) assert nwGUI.theProject.tree["0000000000012"].itemRoot == "0000000000008" assert nwGUI.theProject.tree["0000000000012"].itemClass == nwItemClass.NOVEL - # Add a new file next to the other new file + # Add a new chapter next to the other new file nwTree.setSelectedHandle("0000000000012") - assert nwTree.newTreeItem(nwItemType.FILE) is True + assert nwTree.newTreeItem(nwItemType.FILE, hLevel=2) is True assert nwGUI.theProject.tree["0000000000013"].itemParent == "0000000000011" assert nwGUI.theProject.tree["0000000000013"].itemRoot == "0000000000008" assert nwGUI.theProject.tree["0000000000013"].itemClass == nwItemClass.NOVEL assert nwGUI.openDocument("0000000000013") - assert nwGUI.docEditor.getText() == "## New Document\n\n" + assert nwGUI.docEditor.getText() == "## New Chapter\n\n" + + # Add a new scene next to the other new file + nwTree.setSelectedHandle("0000000000012") + assert nwTree.newTreeItem(nwItemType.FILE, hLevel=3) is True + assert nwGUI.theProject.tree["0000000000014"].itemParent == "0000000000011" + assert nwGUI.theProject.tree["0000000000014"].itemRoot == "0000000000008" + assert nwGUI.theProject.tree["0000000000014"].itemClass == nwItemClass.NOVEL + assert nwGUI.openDocument("0000000000014") + assert nwGUI.docEditor.getText() == "### New Scene\n\n" # Add a new file to the characters folder nwTree.setSelectedHandle("000000000000a") - assert nwTree.newTreeItem(nwItemType.FILE) is True - assert nwGUI.theProject.tree["0000000000014"].itemParent == "000000000000a" - assert nwGUI.theProject.tree["0000000000014"].itemRoot == "000000000000a" - assert nwGUI.theProject.tree["0000000000014"].itemClass == nwItemClass.CHARACTER - assert nwGUI.openDocument("0000000000014") + assert nwTree.newTreeItem(nwItemType.FILE, hLevel=1, isNote=True) is True + assert nwGUI.theProject.tree["0000000000015"].itemParent == "000000000000a" + assert nwGUI.theProject.tree["0000000000015"].itemRoot == "000000000000a" + assert nwGUI.theProject.tree["0000000000015"].itemClass == nwItemClass.CHARACTER + assert nwGUI.openDocument("0000000000015") assert nwGUI.docEditor.getText() == "# New Note\n\n" # Make sure the sibling folder bug trap works @@ -115,6 +123,12 @@ def testGuiProjTree_NewItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockRnd) assert "Internal error" in caplog.text nwGUI.theProject.tree["0000000000013"].setParent("0000000000011") + # Cancel during creation + with monkeypatch.context() as mp: + mp.setattr(QInputDialog, "getText", lambda *a, **k: ("", False)) + nwTree.setSelectedHandle("0000000000013") + assert nwTree.newTreeItem(nwItemType.FILE) is False + # Get the trash folder nwTree.projTree._addTrashRoot() trashHandle = nwGUI.theProject.trashFolder() @@ -148,7 +162,7 @@ def testGuiProjTree_MoveItems(qtbot, monkeypatch, nwGUI, fncDir, mockRnd): monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) - monkeypatch.setattr(GuiMain, "editItem", lambda *a: None) + monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True)) nwTree = nwGUI.treeView @@ -272,7 +286,7 @@ def testGuiProjTree_DeleteItems(qtbot, caplog, monkeypatch, nwGUI, fncDir, mockR monkeypatch.setattr(QMessageBox, "critical", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "question", lambda *a: QMessageBox.Yes) monkeypatch.setattr(QMessageBox, "information", lambda *a: QMessageBox.Yes) - monkeypatch.setattr(GuiMain, "editItem", lambda *a: None) + monkeypatch.setattr(QInputDialog, "getText", lambda *a, text: (text, True)) nwTree = nwGUI.treeView