-
Notifications
You must be signed in to change notification settings - Fork 7
/
hotkeys.py
163 lines (139 loc) · 4.35 KB
/
hotkeys.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
__license__ = 'GPL v3'
__copyright__ = '2016, github.com/christineye'
__docformat__ = 'restructuredtext en'
from collections import OrderedDict
from PyQt5.Qt import QWidget, QVBoxLayout, QLabel, QLineEdit, QComboBox, QIntValidator, QHBoxLayout, QCheckBox
keycodes = OrderedDict([
("backspace", 8),
("tab", 9),
("enter", 13),
("caps lock", 20),
("escape", 27),
("space", 32),
("page up", 33),
("page down", 34),
("end", 35),
("home", 36),
("left arrow", 37),
("up arrow", 38),
("right arrow", 39),
("down arrow", 40),
("0", 48),
("1", 49),
("2", 50),
("3", 51),
("4", 52),
("5", 53),
("6", 54),
("7", 55),
("8", 56),
("9", 57),
("a", 65),
("b", 66),
("c", 67),
("d", 68),
("e", 69),
("f", 70),
("g", 71),
("h", 72),
("i", 73),
("j", 74),
("k", 75),
("l", 76),
("m", 77),
("n", 78),
("o", 79),
("p", 80),
("q", 81),
("r", 82),
("s", 83),
("t", 84),
("u", 85),
("v", 86),
("w", 87),
("x", 88),
("y", 89),
("z", 90),
("numpad 0", 96),
("numpad 1", 97),
("numpad 2", 98),
("numpad 3", 99),
("numpad 4", 100),
("numpad 5", 101),
("numpad 6", 102),
("numpad 7", 103),
("numpad 8", 104),
("numpad 9", 105),
("f1", 112),
("f2", 113),
("f3", 114),
("f4", 115),
("f5", 116),
("f6", 117),
("f7", 118),
("f8", 119),
("f9", 120),
("f10", 121),
("f11", 122),
("f12", 123),
(";", 186),
("=", 187),
(",", 188),
(".", 190),
("`", 192),
("[", 219),
("\\", 220),
("]", 221),
])
def setHotkeyDefault(prefs, configName, keycode, enabled = True, ctrl = False, alt = False, shift = False):
prefs.defaults[configName + '_hotkey_enabled'] = enabled
prefs.defaults[configName + '_hotkey_ctrl'] = ctrl
prefs.defaults[configName + '_hotkey_alt'] = alt
prefs.defaults[configName + '_hotkey_shift'] = shift
prefs.defaults[configName + '_hotkey_keycode'] = keycodes[keycode]
class HotkeyWidget(QWidget):
def __init__(self, prefs, configName, title):
QWidget.__init__(self)
self.l = QVBoxLayout()
self.setLayout(self.l)
self.configName = configName
self.hotkeyLayout = QHBoxLayout()
self.l.addLayout(self.hotkeyLayout)
enabledLabel = QLabel(title)
self.hotkeyLayout.addWidget(enabledLabel)
self.enabledBox = QCheckBox()
self.hotkeyLayout.addWidget(self.enabledBox)
self.enabledBox.setChecked(prefs[configName + '_hotkey_enabled'])
hotkeyLayout2 = QHBoxLayout()
self.l.addLayout(hotkeyLayout2)
ctrlLabel = QLabel("Ctrl")
self.ctrlBox = QCheckBox()
self.ctrlBox.setChecked(prefs[configName + '_hotkey_ctrl'])
ctrlLabel.setBuddy(self.ctrlBox)
hotkeyLayout2.addWidget(ctrlLabel)
hotkeyLayout2.addWidget(self.ctrlBox)
altLabel = QLabel("Alt")
self.altBox = QCheckBox()
self.altBox.setChecked(prefs[configName + '_hotkey_alt'])
altLabel.setBuddy(self.altBox)
hotkeyLayout2.addWidget(altLabel)
hotkeyLayout2.addWidget(self.altBox)
shiftLabel = QLabel("Shift")
self.shiftBox = QCheckBox()
self.shiftBox.setChecked(prefs[configName + '_hotkey_shift'])
shiftLabel.setBuddy(self.shiftBox)
hotkeyLayout2.addWidget(shiftLabel)
hotkeyLayout2.addWidget(self.shiftBox)
self.keycodeBox = QComboBox()
for key, value in keycodes.iteritems():
self.keycodeBox.addItem(key, value)
index = self.keycodeBox.findData(prefs[configName + '_hotkey_keycode'])
if index != -1:
self.keycodeBox.setCurrentIndex(index)
hotkeyLayout2.addWidget(self.keycodeBox)
def save_settings(self, prefs):
prefs[self.configName + '_hotkey_enabled'] = self.enabledBox.isChecked()
prefs[self.configName + '_hotkey_ctrl'] = self.ctrlBox.isChecked()
prefs[self.configName + '_hotkey_alt'] = self.altBox.isChecked()
prefs[self.configName + '_hotkey_shift'] = self.shiftBox.isChecked()
prefs[self.configName + '_hotkey_keycode'] = keycodes[unicode(self.keycodeBox.currentText())]