Skip to content

Commit a95379f

Browse files
authored
fix: order of menu registration to come after keybindings registration (#249)
* fix: reorder menu registration to ensure it occurs after command registration * fix test * change to shift
1 parent c69647e commit a95379f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/app_model/_app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,12 @@ def _register_action_obj(self, action: Action) -> DisposeCallable:
311311
"""
312312
# register commands
313313
disposers = [self.commands.register_action(action)]
314-
# register menus
315-
if dm := self.menus.append_action_menus(action):
316-
disposers.append(dm)
317314
# register keybindings
318315
if dk := self.keybindings.register_action_keybindings(action):
319316
disposers.append(dk)
317+
# register menus
318+
if dm := self.menus.append_action_menus(action):
319+
disposers.append(dm)
320320

321321
# remember the action object as a whole.
322322
# note that commands.register_action will have raised an exception

tests/test_qt/test_qmainwindow.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1+
from __future__ import annotations
2+
13
from typing import TYPE_CHECKING
24

35
from qtpy.QtCore import Qt
6+
from qtpy.QtWidgets import QAction, QApplication
47

58
from app_model.backends.qt import QModelMainWindow, QModelToolBar
9+
from app_model.types._action import Action
610

711
if TYPE_CHECKING:
12+
from pytestqt.qtbot import QtBot
13+
814
from ..conftest import FullApp # noqa: TID252
915

1016

11-
def test_qmodel_main_window(qtbot, full_app: "FullApp") -> None:
17+
def test_qmodel_main_window(
18+
qtbot: QtBot, qapp: QApplication, full_app: FullApp
19+
) -> None:
1220
win = QModelMainWindow(full_app)
1321
qtbot.addWidget(win)
1422

@@ -27,3 +35,16 @@ def test_qmodel_main_window(qtbot, full_app: "FullApp") -> None:
2735
)
2836
assert isinstance(tb, QModelToolBar)
2937
win.addModelToolBar(full_app.Menus.EDIT, area=Qt.ToolBarArea.RightToolBarArea)
38+
39+
full_app.register_action(
40+
Action(
41+
id="late-action",
42+
title="Late Action",
43+
keybindings=[{"primary": "Shift+L"}],
44+
menus=[{"id": full_app.Menus.FILE}],
45+
callback=lambda: None,
46+
)
47+
)
48+
49+
action = qapp.findChild(QAction, "late-action")
50+
assert action.shortcut().toString() == "Shift+L"

0 commit comments

Comments
 (0)