From 10aeab24b57f8a07d98adc73c6407fc5988b346b Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Wed, 18 Jun 2025 09:51:36 -0400 Subject: [PATCH 1/3] fix: reorder menu registration to ensure it occurs after command registration --- src/app_model/_app.py | 6 +++--- tests/test_qt/test_qmainwindow.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/app_model/_app.py b/src/app_model/_app.py index 8df3e7aa..507ff3fc 100644 --- a/src/app_model/_app.py +++ b/src/app_model/_app.py @@ -311,12 +311,12 @@ def _register_action_obj(self, action: Action) -> DisposeCallable: """ # register commands disposers = [self.commands.register_action(action)] - # register menus - if dm := self.menus.append_action_menus(action): - disposers.append(dm) # register keybindings if dk := self.keybindings.register_action_keybindings(action): disposers.append(dk) + # register menus + if dm := self.menus.append_action_menus(action): + disposers.append(dm) # remember the action object as a whole. # note that commands.register_action will have raised an exception diff --git a/tests/test_qt/test_qmainwindow.py b/tests/test_qt/test_qmainwindow.py index 6ee2db73..6beb246a 100644 --- a/tests/test_qt/test_qmainwindow.py +++ b/tests/test_qt/test_qmainwindow.py @@ -1,8 +1,10 @@ from typing import TYPE_CHECKING from qtpy.QtCore import Qt +from qtpy.QtGui import QAction from app_model.backends.qt import QModelMainWindow, QModelToolBar +from app_model.types._action import Action if TYPE_CHECKING: from ..conftest import FullApp # noqa: TID252 @@ -27,3 +29,15 @@ def test_qmodel_main_window(qtbot, full_app: "FullApp"): ) assert isinstance(tb, QModelToolBar) win.addModelToolBar(full_app.Menus.EDIT, area=Qt.ToolBarArea.RightToolBarArea) + + full_app.register_action( + Action( + id="late-action", + title="Late Action", + keybindings=[{"primary": "Ctrl+L"}], + menus=[{"id": full_app.Menus.FILE}], + callback=lambda: None, + ) + ) + action = win.findChild(QAction, "late-action") + assert action.shortcut().toString() == "Meta+L" From c60b2a65fe59654d85de12fe9eba11c84b9e9d64 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Wed, 18 Jun 2025 12:56:21 -0400 Subject: [PATCH 2/3] fix test --- tests/test_qt/test_qmainwindow.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_qt/test_qmainwindow.py b/tests/test_qt/test_qmainwindow.py index 6beb246a..6703c3f6 100644 --- a/tests/test_qt/test_qmainwindow.py +++ b/tests/test_qt/test_qmainwindow.py @@ -1,16 +1,22 @@ +from __future__ import annotations + from typing import TYPE_CHECKING from qtpy.QtCore import Qt -from qtpy.QtGui import QAction +from qtpy.QtWidgets import QAction, QApplication from app_model.backends.qt import QModelMainWindow, QModelToolBar from app_model.types._action import Action if TYPE_CHECKING: + from pytestqt.qtbot import QtBot + from ..conftest import FullApp # noqa: TID252 -def test_qmodel_main_window(qtbot, full_app: "FullApp"): +def test_qmodel_main_window( + qtbot: QtBot, qapp: QApplication, full_app: FullApp +) -> None: win = QModelMainWindow(full_app) qtbot.addWidget(win) @@ -39,5 +45,6 @@ def test_qmodel_main_window(qtbot, full_app: "FullApp"): callback=lambda: None, ) ) - action = win.findChild(QAction, "late-action") + + action = qapp.findChild(QAction, "late-action") assert action.shortcut().toString() == "Meta+L" From 4da0fee94ec35b41ce355f7a631ffb481def2c8b Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Wed, 18 Jun 2025 12:58:42 -0400 Subject: [PATCH 3/3] change to shift --- tests/test_qt/test_qmainwindow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_qt/test_qmainwindow.py b/tests/test_qt/test_qmainwindow.py index 6703c3f6..a31b1374 100644 --- a/tests/test_qt/test_qmainwindow.py +++ b/tests/test_qt/test_qmainwindow.py @@ -40,11 +40,11 @@ def test_qmodel_main_window( Action( id="late-action", title="Late Action", - keybindings=[{"primary": "Ctrl+L"}], + keybindings=[{"primary": "Shift+L"}], menus=[{"id": full_app.Menus.FILE}], callback=lambda: None, ) ) action = qapp.findChild(QAction, "late-action") - assert action.shortcut().toString() == "Meta+L" + assert action.shortcut().toString() == "Shift+L"