diff --git a/qt/applications/workbench/workbench/plugins/editor.py b/qt/applications/workbench/workbench/plugins/editor.py index ee320b3611e2fa5b36aae6229418225f264008b5..5dd6bcd5612a43fe196c22f08d2b84065ff2891a 100644 --- a/qt/applications/workbench/workbench/plugins/editor.py +++ b/qt/applications/workbench/workbench/plugins/editor.py @@ -10,15 +10,15 @@ from __future__ import (absolute_import, unicode_literals) # system imports +from qtpy.QtCore import Qt +from qtpy.QtWidgets import QVBoxLayout # third-party library imports from mantidqt.utils.qt import add_actions, create_action from mantidqt.widgets.codeeditor.multifileinterpreter import MultiPythonFileInterpreter -from qtpy.QtCore import Qt -from qtpy.QtWidgets import QVBoxLayout - # local package imports from workbench.plugins.base import PluginWidget + # from mantidqt.utils.qt import toQSettings when readSettings/writeSettings are implemented @@ -53,7 +53,7 @@ class MultiFileEditor(PluginWidget): # attributes self.run_action = create_action(self, "Run", on_triggered=self.editors.execute_current, - shortcut="Ctrl+Return", + shortcut=("Ctrl+Return", "Ctrl+Enter"), shortcut_context=Qt.ApplicationShortcut) self.abort_action = create_action(self, "Abort", on_triggered=self.editors.abort_current) diff --git a/qt/python/mantidqt/utils/qt/__init__.py b/qt/python/mantidqt/utils/qt/__init__.py index dd491474b05b355d6c10ebae4b16cf2abfc6220d..9c1da5d4ae3db5f37ad8363827e29b57335b78f9 100644 --- a/qt/python/mantidqt/utils/qt/__init__.py +++ b/qt/python/mantidqt/utils/qt/__init__.py @@ -12,16 +12,16 @@ from __future__ import absolute_import # stdlib modules +import os.path as osp from contextlib import contextmanager from importlib import import_module -import os.path as osp # 3rd-party modules from qtpy import QT_VERSION -from qtpy.uic import loadUi, loadUiType +from qtpy.QtGui import QKeySequence from qtpy.QtWidgets import QAction, QMenu +from qtpy.uic import loadUi, loadUiType -# local modules from ...icons import get_icon LIB_SUFFIX = 'qt' + QT_VERSION[0] @@ -130,7 +130,12 @@ def create_action(parent, text, on_triggered=None, shortcut=None, if on_triggered is not None: action.triggered.connect(on_triggered) if shortcut is not None: - action.setShortcut(shortcut) + if isinstance(shortcut, tuple) or isinstance(shortcut, list): + qshortcuts = [QKeySequence(s) for s in shortcut] + action.setShortcuts(qshortcuts) + else: + action.setShortcut(shortcut) + if shortcut_context is not None: action.setShortcutContext(shortcut_context) if icon_name is not None: diff --git a/qt/python/mantidqt/utils/test/test_qt_utils.py b/qt/python/mantidqt/utils/test/test_qt_utils.py index b526580ec8a3d3fdded6201f9c4978b214f51e63..87ae0646f52cb54ffbe5c98c445880b1cd232bda 100644 --- a/qt/python/mantidqt/utils/test/test_qt_utils.py +++ b/qt/python/mantidqt/utils/test/test_qt_utils.py @@ -14,8 +14,10 @@ import unittest from qtpy.QtCore import QObject, Qt, Slot from qtpy.QtWidgets import QAction, QMenu, QToolBar + try: from qtpy.QtCore import SIGNAL + NEW_STYLE_SIGNAL = False except ImportError: NEW_STYLE_SIGNAL = True @@ -29,6 +31,7 @@ class CreateActionTest(GuiTest): def test_parent_and_name_only_required(self): class Parent(QObject): pass + parent = Parent() action = create_action(parent, "Test Action") self.assertTrue(isinstance(action, QAction)) @@ -44,6 +47,7 @@ class CreateActionTest(GuiTest): @Slot() def test_slot(self): pass + recv = Receiver() action = create_action(None, "Test Action", on_triggered=recv.test_slot) if NEW_STYLE_SIGNAL: @@ -55,6 +59,12 @@ class CreateActionTest(GuiTest): action = create_action(None, "Test Action", shortcut="Ctrl+S") self.assertEqual("Ctrl+S", action.shortcut()) + def test_multiple_shortcuts_are_set_if_given(self): + expected_shortcuts = ("Ctrl+S", "Ctrl+W") + action = create_action(None, "Test Action", shortcut=expected_shortcuts) + for expected, actual in zip(expected_shortcuts, action.shortcuts()): + self.assertEqual(expected, actual.toString()) + def test_shortcut_context_used_if_shortcut_given(self): action = create_action(None, "Test Action", shortcut="Ctrl+S", shortcut_context=Qt.ApplicationShortcut)