From 4cc402679f9f58340387ceb9a73ba7270341ef66 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 5 Sep 2023 22:20:04 +0200 Subject: [PATCH] Fix typo and move special popup menu class --- novelwriter/gui/sidebar.py | 28 +++++++++++++++------------- tests/test_gui/test_gui_guimain.py | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/novelwriter/gui/sidebar.py b/novelwriter/gui/sidebar.py index 034d83b0f..4b7b4e7bf 100644 --- a/novelwriter/gui/sidebar.py +++ b/novelwriter/gui/sidebar.py @@ -40,18 +40,6 @@ logger = logging.getLogger(__name__) -class PopRightMenu(QMenu): - - def event(self, event: QEvent): - """Overload the show event and move the menu popup location.""" - if event.type() == QEvent.Show: - parent = self.parent() - if isinstance(parent, QWidget): - offset = QPoint(parent.width(), parent.height() - self.height()) - self.move(parent.mapToGlobal(offset)) - return super(PopRightMenu, self).event(event) - - class GuiSideBar(QWidget): viewChangeRequested = pyqtSignal(nwView) @@ -104,7 +92,7 @@ def __init__(self, mainGui: GuiMain) -> None: self.tbSettings.setIconSize(iconSize) self.tbSettings.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonIconOnly) - self.mSettings = PopRightMenu(self.tbSettings) + self.mSettings = _PopRightMenu(self.tbSettings) self.mSettings.addAction(self.mainGui.mainMenu.aEditWordList) self.mSettings.addAction(self.mainGui.mainMenu.aProjectSettings) self.mSettings.addSeparator() @@ -171,3 +159,17 @@ def updateTheme(self) -> None: return # END Class GuiSideBar + + +class _PopRightMenu(QMenu): + + def event(self, event: QEvent): + """Overload the show event and move the menu popup location.""" + if event.type() == QEvent.Show: + parent = self.parent() + if isinstance(parent, QWidget): + offset = QPoint(parent.width(), parent.height() - self.height()) + self.move(parent.mapToGlobal(offset)) + return super(_PopRightMenu, self).event(event) + +# END Class _PopRightMenu diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index fa8900bd2..0a66ef135 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -595,7 +595,7 @@ def testGuiMain_Features(qtbot, nwGUI, projPath, mockRnd): # SideBar Menu # ============ - # Just make sure the custom event handler executes and don't fail + # Just make sure the custom event handler executes and doesn't fail nwGUI.sideBar.mSettings.show() nwGUI.sideBar.mSettings.hide()