Skip to content

Commit bd56b93

Browse files
committed
Add 'test_shortcut_controls'
1 parent 1ea3aee commit bd56b93

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

qtapputils/managers/tests/test_shortcut_manager.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,62 @@ def test_bind_shortcut(widget):
378378
)
379379

380380

381+
def test_shortcut_controls(widget, qtbot):
382+
manager = ShortcutManager()
383+
384+
# Bind a shortcut, but don't activate it.
385+
manager.declare_shortcut(
386+
context='file', name='save', default_key_sequence='Ctrl+S'
387+
)
388+
shortcut_item = manager.bind_shortcut(
389+
context='file', name='save',
390+
callback=Mock(), parent=widget, activate=False
391+
)
392+
393+
assert isinstance(shortcut_item, ShortcutItem)
394+
assert shortcut_item.shortcut is None
395+
assert shortcut_item.enabled is False
396+
397+
qtbot.keyPress(widget, Qt.Key_S, modifier=Qt.ControlModifier)
398+
shortcut_item.callback.call_count == 0
399+
400+
# Activate the shortcut.
401+
manager.activate_shortcut('file', 'save')
402+
403+
assert shortcut_item.shortcut is not None
404+
assert shortcut_item.enabled is True
405+
406+
qtbot.keyPress(widget, Qt.Key_S, modifier=Qt.ControlModifier)
407+
shortcut_item.callback.call_count == 1
408+
409+
# Disable the shortcut.
410+
manager.enable_shortcut('file', 'save', enabled=False)
411+
412+
assert shortcut_item.shortcut is not None
413+
assert shortcut_item.enabled is False
414+
415+
qtbot.keyPress(widget, Qt.Key_S, modifier=Qt.ControlModifier)
416+
shortcut_item.callback.call_count == 1
417+
418+
# Enable the shortcut.
419+
manager.enable_shortcut('file', 'save', enabled=True)
420+
421+
assert shortcut_item.shortcut is not None
422+
assert shortcut_item.enabled is True
423+
424+
qtbot.keyPress(widget, Qt.Key_S, modifier=Qt.ControlModifier)
425+
shortcut_item.callback.call_count == 2
426+
427+
# Deactivate the shortcut.
428+
manager.deactivate_shortcut('file', 'save')
429+
430+
assert shortcut_item.shortcut is None
431+
assert shortcut_item.enabled is False
432+
433+
qtbot.keyPress(widget, Qt.Key_S, modifier=Qt.ControlModifier)
434+
shortcut_item.callback.call_count == 2
435+
436+
381437
def test_set_shortcut(widget, capsys):
382438
manager = ShortcutManager()
383439

0 commit comments

Comments
 (0)