Skip to content
Snippets Groups Projects
Unverified Commit 50f67a45 authored by Pete Peterson's avatar Pete Peterson Committed by GitHub
Browse files

Merge pull request #24469 from DTasev/add_ctrl_enter_as_codeeditor_execute_shortcut

Add Ctrl+Enter shortcut to execute code in the CodeEditor
parents 261c243f 28c35af5
No related branches found
No related tags found
No related merge requests found
...@@ -10,15 +10,15 @@ ...@@ -10,15 +10,15 @@
from __future__ import (absolute_import, unicode_literals) from __future__ import (absolute_import, unicode_literals)
# system imports # system imports
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QVBoxLayout
# third-party library imports # third-party library imports
from mantidqt.utils.qt import add_actions, create_action from mantidqt.utils.qt import add_actions, create_action
from mantidqt.widgets.codeeditor.multifileinterpreter import MultiPythonFileInterpreter from mantidqt.widgets.codeeditor.multifileinterpreter import MultiPythonFileInterpreter
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QVBoxLayout
# local package imports # local package imports
from workbench.plugins.base import PluginWidget from workbench.plugins.base import PluginWidget
# from mantidqt.utils.qt import toQSettings when readSettings/writeSettings are implemented # from mantidqt.utils.qt import toQSettings when readSettings/writeSettings are implemented
...@@ -53,7 +53,7 @@ class MultiFileEditor(PluginWidget): ...@@ -53,7 +53,7 @@ class MultiFileEditor(PluginWidget):
# attributes # attributes
self.run_action = create_action(self, "Run", self.run_action = create_action(self, "Run",
on_triggered=self.editors.execute_current, on_triggered=self.editors.execute_current,
shortcut="Ctrl+Return", shortcut=("Ctrl+Return", "Ctrl+Enter"),
shortcut_context=Qt.ApplicationShortcut) shortcut_context=Qt.ApplicationShortcut)
self.abort_action = create_action(self, "Abort", self.abort_action = create_action(self, "Abort",
on_triggered=self.editors.abort_current) on_triggered=self.editors.abort_current)
......
...@@ -12,16 +12,16 @@ ...@@ -12,16 +12,16 @@
from __future__ import absolute_import from __future__ import absolute_import
# stdlib modules # stdlib modules
import os.path as osp
from contextlib import contextmanager from contextlib import contextmanager
from importlib import import_module from importlib import import_module
import os.path as osp
# 3rd-party modules # 3rd-party modules
from qtpy import QT_VERSION from qtpy import QT_VERSION
from qtpy.uic import loadUi, loadUiType from qtpy.QtGui import QKeySequence
from qtpy.QtWidgets import QAction, QMenu from qtpy.QtWidgets import QAction, QMenu
from qtpy.uic import loadUi, loadUiType
# local modules
from ...icons import get_icon from ...icons import get_icon
LIB_SUFFIX = 'qt' + QT_VERSION[0] LIB_SUFFIX = 'qt' + QT_VERSION[0]
...@@ -130,7 +130,12 @@ def create_action(parent, text, on_triggered=None, shortcut=None, ...@@ -130,7 +130,12 @@ def create_action(parent, text, on_triggered=None, shortcut=None,
if on_triggered is not None: if on_triggered is not None:
action.triggered.connect(on_triggered) action.triggered.connect(on_triggered)
if shortcut is not None: 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: if shortcut_context is not None:
action.setShortcutContext(shortcut_context) action.setShortcutContext(shortcut_context)
if icon_name is not None: if icon_name is not None:
......
...@@ -14,8 +14,10 @@ import unittest ...@@ -14,8 +14,10 @@ import unittest
from qtpy.QtCore import QObject, Qt, Slot from qtpy.QtCore import QObject, Qt, Slot
from qtpy.QtWidgets import QAction, QMenu, QToolBar from qtpy.QtWidgets import QAction, QMenu, QToolBar
try: try:
from qtpy.QtCore import SIGNAL from qtpy.QtCore import SIGNAL
NEW_STYLE_SIGNAL = False NEW_STYLE_SIGNAL = False
except ImportError: except ImportError:
NEW_STYLE_SIGNAL = True NEW_STYLE_SIGNAL = True
...@@ -29,6 +31,7 @@ class CreateActionTest(GuiTest): ...@@ -29,6 +31,7 @@ class CreateActionTest(GuiTest):
def test_parent_and_name_only_required(self): def test_parent_and_name_only_required(self):
class Parent(QObject): class Parent(QObject):
pass pass
parent = Parent() parent = Parent()
action = create_action(parent, "Test Action") action = create_action(parent, "Test Action")
self.assertTrue(isinstance(action, QAction)) self.assertTrue(isinstance(action, QAction))
...@@ -44,6 +47,7 @@ class CreateActionTest(GuiTest): ...@@ -44,6 +47,7 @@ class CreateActionTest(GuiTest):
@Slot() @Slot()
def test_slot(self): def test_slot(self):
pass pass
recv = Receiver() recv = Receiver()
action = create_action(None, "Test Action", on_triggered=recv.test_slot) action = create_action(None, "Test Action", on_triggered=recv.test_slot)
if NEW_STYLE_SIGNAL: if NEW_STYLE_SIGNAL:
...@@ -55,6 +59,12 @@ class CreateActionTest(GuiTest): ...@@ -55,6 +59,12 @@ class CreateActionTest(GuiTest):
action = create_action(None, "Test Action", shortcut="Ctrl+S") action = create_action(None, "Test Action", shortcut="Ctrl+S")
self.assertEqual("Ctrl+S", action.shortcut()) 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): def test_shortcut_context_used_if_shortcut_given(self):
action = create_action(None, "Test Action", shortcut="Ctrl+S", action = create_action(None, "Test Action", shortcut="Ctrl+S",
shortcut_context=Qt.ApplicationShortcut) shortcut_context=Qt.ApplicationShortcut)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment