-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheatsheet.py
84 lines (64 loc) · 2.72 KB
/
cheatsheet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
"""Cheat Sheet
This module implements the cheat sheet widget, which shows help information
such as keyboard shortcuts, etc.
"""
from PyQt5.QtCore import QSettings, Qt, pyqtSignal
from PyQt5.QtGui import QKeySequence
from PyQt5.QtWidgets import QLabel, QLayout, QVBoxLayout, QWidget
class CheatSheet(QWidget):
"""Cheat sheet class.
Just a widget that holds help information.
"""
def __init__(self, parent=None):
"""Initialize the CheatSheet instance."""
super().__init__(parent=parent)
self.setWindowTitle('Help')
self.setAttribute(Qt.WA_ShowWithoutActivating)
self.setLayout(QVBoxLayout())
self.layout().setSizeConstraint(QLayout.SetFixedSize)
label = QLabel()
label.setAlignment(Qt.AlignLeft | Qt.AlignTop)
label.setText(
'Window Toggling Shortcuts:\n' +
self.shortcut_help_to_string(QKeySequence.HelpContents, 'Toggle help') +
self.shortcut_help_to_string('CTRL+R', 'Toggle racer list') +
self.shortcut_help_to_string('CTRL+F', 'Toggle field list') +
self.shortcut_help_to_string('CTRL+L', 'Toggle log') +
'\n' +
'Results Window Shortcuts:\n' +
self.shortcut_help_to_string('CTRL+S', 'Submit result(s)') +
self.shortcut_help_to_string('CTRL+A', 'Select all results') +
self.shortcut_help_to_string('CTRL+D', 'Deselect all results') +
'\n' +
'Miscellaneous:\n' +
self.shortcut_help_to_string('CTRL+T', 'Toggle reference/wall time shown') +
self.shortcut_help_to_string('CTRL+B', 'Launch race builder'))
self.layout().addWidget(label)
self.read_settings()
def shortcut_help_to_string(self, shortcut, help_text):
"""Formats a shortcut string and help text."""
return (QKeySequence.toString(QKeySequence(shortcut), QKeySequence.NativeText) +
'\t' + help_text + '\n')
def hideEvent(self, event): #pylint: disable=invalid-name
"""Handle hide event."""
del event
self.write_settings()
self.visibleChanged.emit(False)
def read_settings(self):
"""Read settings."""
group_name = self.__class__.__name__
settings = QSettings()
settings.beginGroup(group_name)
if settings.contains('pos'):
self.move(settings.value('pos'))
settings.endGroup()
def write_settings(self):
"""Write settings."""
group_name = self.__class__.__name__
settings = QSettings()
settings.beginGroup(group_name)
settings.setValue('pos', self.pos())
settings.endGroup()
# Signals.
visibleChanged = pyqtSignal(bool)