Skip to content

Commit af971f6

Browse files
committed
Tutorial: Process Esc key as a QAction
- Temporary and application-wide, so the cursor doesn't have to be in the popup
1 parent d783de3 commit af971f6

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/windows/views/tutorial.py

+13-18
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from PyQt5.QtCore import Qt, QPoint, QRectF, QEvent
3131
from PyQt5.QtGui import *
32-
from PyQt5.QtWidgets import QLabel, QWidget, QDockWidget, QVBoxLayout, QHBoxLayout, QPushButton, QToolButton, QCheckBox
32+
from PyQt5.QtWidgets import QLabel, QWidget, QDockWidget, QVBoxLayout, QHBoxLayout, QPushButton, QToolButton, QCheckBox, QAction
3333

3434
from classes.logger import log
3535
from classes.settings import get_settings
@@ -77,23 +77,6 @@ def checkbox_metrics_callback(self, state):
7777
# Disable metric sending
7878
s.set("send_metrics", False)
7979

80-
def keyPressEvent(self, event):
81-
""" Process key press events and match with known shortcuts"""
82-
# Detect the current KeySequence pressed (including modifier keys)
83-
key_value = event.key()
84-
modifiers = int(event.modifiers())
85-
86-
# Abort handling if the key sequence is invalid
87-
if (key_value <= 0 or key_value in
88-
[Qt.Key_Shift, Qt.Key_Alt, Qt.Key_Control, Qt.Key_Meta]):
89-
return
90-
91-
# A valid keysequence was detected
92-
key = QKeySequence(modifiers + key_value)
93-
if key == Qt.Key_Escape:
94-
# User hit Escape key, hide tutorial permanently
95-
self.manager.hide_tips(self.id, True)
96-
9780
def mouseReleaseEvent(self, event):
9881
"""Process click events on tutorial. Especially useful when tutorial messages are partially
9982
obscured or offscreen (i.e. on small screens). Just click any part of the tutorial, and it will
@@ -148,12 +131,20 @@ def __init__(self, id, text, arrow, manager, *args):
148131
hbox = QHBoxLayout()
149132
hbox.setContentsMargins(20, 10, 0, 0)
150133

134+
# Close action
135+
self.close_action = QAction(_("Hide Tutorial"))
136+
self.close_action.setShortcut(QKeySequence(Qt.Key_Escape))
137+
self.close_action.setShortcutContext(Qt.ApplicationShortcut)
138+
151139
# Create buttons
152140
self.btn_close_tips = QPushButton(self)
153141
self.btn_close_tips.setText(_("Hide Tutorial"))
142+
self.btn_close_tips.addAction(self.close_action)
143+
154144
self.btn_next_tip = QPushButton(self)
155145
self.btn_next_tip.setText(_("Next"))
156146
self.btn_next_tip.setStyleSheet("font-weight:bold;")
147+
157148
hbox.addWidget(self.btn_close_tips)
158149
hbox.addWidget(self.btn_next_tip)
159150
vbox.addLayout(hbox)
@@ -170,6 +161,10 @@ def __init__(self, id, text, arrow, manager, *args):
170161
self.setAttribute(Qt.WA_TranslucentBackground, True)
171162
self.setAttribute(Qt.WA_DeleteOnClose, True)
172163

164+
# Connect close action signal
165+
self.close_action.triggered.connect(
166+
functools.partial(self.manager.hide_tips, self.id, True))
167+
173168

174169
class TutorialManager(object):
175170
""" Manage and present a list of tutorial dialogs """

0 commit comments

Comments
 (0)