Skip to content

Commit 384e892

Browse files
committed
Tabs: Simplify how its shortcuts are created
1 parent b7fb5da commit 384e892

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

spyderlib/guiconfig.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,17 @@ def set_shortcut(context, name, keystr):
9595
CONF.set('shortcuts', '%s/%s' % (context, name), keystr)
9696

9797

98+
def new_shortcut(keystr, parent, action):
99+
"""Define a new shortcut according to a keysequence string"""
100+
sc = QShortcut(QKeySequence(keystr), parent, action)
101+
sc.setContext(Qt.WidgetWithChildrenShortcut)
102+
return sc
103+
104+
98105
def create_shortcut(action, context, name, parent):
99-
"""Creates a QShortcut for a widget and returns its associated data"""
106+
"""Creates a Shortcut namedtuple for a widget"""
100107
keystr = get_shortcut(context, name)
101-
qsc = QShortcut(QKeySequence(keystr), parent, action)
102-
qsc.setContext(Qt.WidgetWithChildrenShortcut)
108+
qsc = new_shortcut(keystr, parent, action)
103109
sc = Shortcut(data=(qsc, name, keystr))
104110
return sc
105111

spyderlib/widgets/tabs.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
# pylint: disable=R0201
1313

1414
from spyderlib.qt.QtGui import (QTabWidget, QMenu, QDrag, QApplication,
15-
QTabBar, QShortcut, QKeySequence, QWidget,
16-
QHBoxLayout)
15+
QTabBar, QWidget, QHBoxLayout)
1716
from spyderlib.qt.QtCore import SIGNAL, Qt, QPoint, QMimeData, QByteArray
1817

19-
import os
2018
import os.path as osp
2119

2220
# Local imports
2321
from spyderlib.baseconfig import _
22+
from spyderlib.guiconfig import new_shortcut
2423
from spyderlib.utils.misc import get_common_path
2524
from spyderlib.utils.qthelpers import (add_actions, create_toolbutton,
2625
create_action, get_icon)
@@ -265,16 +264,13 @@ def __init__(self, parent, actions=None, menu=None,
265264
self.connect(tab_bar, SIGNAL('move_tab(QString,int,int)'),
266265
self.move_tab_from_another_tabwidget)
267266
self.setTabBar(tab_bar)
268-
def newsc(keystr, triggered):
269-
sc = QShortcut(QKeySequence(keystr), parent, triggered)
270-
sc.setContext(Qt.WidgetWithChildrenShortcut)
271-
return sc
272-
tabsc = newsc("Ctrl+Tab", lambda: self.tab_navigate(1))
273-
tabshiftsc = newsc("Shift+Ctrl+Tab", lambda: self.tab_navigate(-1))
274-
closesc1 = newsc("Ctrl+W", lambda: self.emit(SIGNAL("close_tab(int)"),
275-
self.currentIndex()))
276-
closesc2 = newsc("Ctrl+F4", lambda: self.emit(SIGNAL("close_tab(int)"),
277-
self.currentIndex()))
267+
268+
new_shortcut("Ctrl+Tab", parent, lambda: self.tab_navigate(1))
269+
new_shortcut("Shift+Ctrl+Tab", parent, lambda: self.tab_navigate(-1))
270+
new_shortcut("Ctrl+W", parent, lambda: self.emit(SIGNAL("close_tab(int)"),
271+
self.currentIndex()))
272+
new_shortcut("Ctrl+F4", parent, lambda: self.emit(SIGNAL("close_tab(int)"),
273+
self.currentIndex()))
278274

279275
def tab_navigate(self, delta=1):
280276
"""Ctrl+Tab"""

0 commit comments

Comments
 (0)