ScreenMagnifier 1.11.0.post8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ScreenMagnifier might be problematic. Click here for more details.

Files changed (117) hide show
  1. ScreenMagnifier/__init__.py +68 -0
  2. ScreenMagnifier/__main__.py +17 -0
  3. ScreenMagnifier/advancedoverlay.py +593 -0
  4. ScreenMagnifier/advancedpanel.py +521 -0
  5. ScreenMagnifier/analysiscontroller.py +533 -0
  6. ScreenMagnifier/analysisserver.py +404 -0
  7. ScreenMagnifier/colordetector/__init__.py +28 -0
  8. ScreenMagnifier/colordetector/colordetector.py +570 -0
  9. ScreenMagnifier/colordetector/core.py +434 -0
  10. ScreenMagnifier/colordetector/main.py +23 -0
  11. ScreenMagnifier/colordetector/mainwindow.py +182 -0
  12. ScreenMagnifier/colorpanel.py +424 -0
  13. ScreenMagnifier/colorswatches/__init__.py +16 -0
  14. ScreenMagnifier/colorswatches/colorswatches.py +316 -0
  15. ScreenMagnifier/colorswatches/main.py +23 -0
  16. ScreenMagnifier/colorswatches/mainwindow.py +60 -0
  17. ScreenMagnifier/controlpanel.py +234 -0
  18. ScreenMagnifier/detectionpanel.py +790 -0
  19. ScreenMagnifier/facedetector/__init__.py +24 -0
  20. ScreenMagnifier/facedetector/core.py +314 -0
  21. ScreenMagnifier/facedetector/facedetector.py +288 -0
  22. ScreenMagnifier/facedetector/main.py +23 -0
  23. ScreenMagnifier/facedetector/mainwindow.py +122 -0
  24. ScreenMagnifier/facedetector/models/__init__.py +4 -0
  25. ScreenMagnifier/facepointer.py +1121 -0
  26. ScreenMagnifier/features.py +50 -0
  27. ScreenMagnifier/hotkeys/__init__.py +16 -0
  28. ScreenMagnifier/hotkeys/hotkeys.py +379 -0
  29. ScreenMagnifier/hotkeys/main.py +23 -0
  30. ScreenMagnifier/hotkeys/mainwindow.py +56 -0
  31. ScreenMagnifier/imagefilters/__init__.py +24 -0
  32. ScreenMagnifier/imagefilters/core.py +172 -0
  33. ScreenMagnifier/imagefilters/imagefilters.py +220 -0
  34. ScreenMagnifier/imagefilters/main.py +23 -0
  35. ScreenMagnifier/imagefilters/mainwindow.py +120 -0
  36. ScreenMagnifier/magnifierview/__init__.py +16 -0
  37. ScreenMagnifier/magnifierview/magnifierview.py +1249 -0
  38. ScreenMagnifier/magnifierview/main.py +23 -0
  39. ScreenMagnifier/magnifierview/mainwindow.py +91 -0
  40. ScreenMagnifier/main.py +157 -0
  41. ScreenMagnifier/mainwindow.py +1368 -0
  42. ScreenMagnifier/mousecatcher/__init__.py +16 -0
  43. ScreenMagnifier/mousecatcher/main.py +23 -0
  44. ScreenMagnifier/mousecatcher/mainwindow.py +78 -0
  45. ScreenMagnifier/mousecatcher/mousecatcher.py +251 -0
  46. ScreenMagnifier/mousemove.py +259 -0
  47. ScreenMagnifier/netprotocol/__init__.py +25 -0
  48. ScreenMagnifier/netprotocol/main.py +23 -0
  49. ScreenMagnifier/netprotocol/mainwindow.py +91 -0
  50. ScreenMagnifier/netprotocol/netprotocol.py +372 -0
  51. ScreenMagnifier/netprotocol/wire.py +189 -0
  52. ScreenMagnifier/regionselector/__init__.py +16 -0
  53. ScreenMagnifier/regionselector/main.py +23 -0
  54. ScreenMagnifier/regionselector/mainwindow.py +70 -0
  55. ScreenMagnifier/regionselector/regionselector.py +549 -0
  56. ScreenMagnifier/remoteclient.py +636 -0
  57. ScreenMagnifier/resources/icon-128.png +0 -0
  58. ScreenMagnifier/resources/icon-16.png +0 -0
  59. ScreenMagnifier/resources/icon-24.png +0 -0
  60. ScreenMagnifier/resources/icon-256.png +0 -0
  61. ScreenMagnifier/resources/icon-32.png +0 -0
  62. ScreenMagnifier/resources/icon-48.png +0 -0
  63. ScreenMagnifier/resources/icon-512.png +0 -0
  64. ScreenMagnifier/resources/icon-64.png +0 -0
  65. ScreenMagnifier/resources/icon.icns +0 -0
  66. ScreenMagnifier/resources/icon.ico +0 -0
  67. ScreenMagnifier/screengrabber/__init__.py +16 -0
  68. ScreenMagnifier/screengrabber/main.py +23 -0
  69. ScreenMagnifier/screengrabber/mainwindow.py +79 -0
  70. ScreenMagnifier/screengrabber/screengrabber.py +558 -0
  71. ScreenMagnifier/server.py +150 -0
  72. ScreenMagnifier/serverpanel.py +379 -0
  73. ScreenMagnifier/shortcuteditor/__init__.py +16 -0
  74. ScreenMagnifier/shortcuteditor/main.py +23 -0
  75. ScreenMagnifier/shortcuteditor/mainwindow.py +54 -0
  76. ScreenMagnifier/shortcuteditor/shortcuteditor.py +411 -0
  77. ScreenMagnifier/shortcuts.py +118 -0
  78. ScreenMagnifier/shortcutspanel.py +140 -0
  79. ScreenMagnifier/support.py +127 -0
  80. ScreenMagnifier/translations/ar.json +387 -0
  81. ScreenMagnifier/translations/de.json +387 -0
  82. ScreenMagnifier/translations/es.json +387 -0
  83. ScreenMagnifier/translations/fr.json +387 -0
  84. ScreenMagnifier/translations/it.json +387 -0
  85. ScreenMagnifier/translations/ja.json +387 -0
  86. ScreenMagnifier/translations/ko.json +387 -0
  87. ScreenMagnifier/translations/pt_BR.json +387 -0
  88. ScreenMagnifier/translations/ru.json +387 -0
  89. ScreenMagnifier/translations/tr.json +387 -0
  90. ScreenMagnifier/translations/zh_CN.json +387 -0
  91. ScreenMagnifier/translator/__init__.py +16 -0
  92. ScreenMagnifier/translator/main.py +23 -0
  93. ScreenMagnifier/translator/mainwindow.py +62 -0
  94. ScreenMagnifier/translator/translator.py +284 -0
  95. ScreenMagnifier/upscaler/__init__.py +24 -0
  96. ScreenMagnifier/upscaler/core.py +315 -0
  97. ScreenMagnifier/upscaler/main.py +23 -0
  98. ScreenMagnifier/upscaler/mainwindow.py +128 -0
  99. ScreenMagnifier/upscaler/models/FSRCNN-small_x2.pb +0 -0
  100. ScreenMagnifier/upscaler/models/FSRCNN-small_x3.pb +0 -0
  101. ScreenMagnifier/upscaler/models/FSRCNN-small_x4.pb +0 -0
  102. ScreenMagnifier/upscaler/models/FSRCNN_x2.pb +0 -0
  103. ScreenMagnifier/upscaler/models/FSRCNN_x3.pb +0 -0
  104. ScreenMagnifier/upscaler/models/FSRCNN_x4.pb +0 -0
  105. ScreenMagnifier/upscaler/models/LICENSE-FSRCNN +201 -0
  106. ScreenMagnifier/upscaler/models/__init__.py +4 -0
  107. ScreenMagnifier/upscaler/upscaler.py +285 -0
  108. ScreenMagnifier/wincheck.py +65 -0
  109. ScreenMagnifier/zoomoverlay/__init__.py +16 -0
  110. ScreenMagnifier/zoomoverlay/main.py +23 -0
  111. ScreenMagnifier/zoomoverlay/mainwindow.py +99 -0
  112. ScreenMagnifier/zoomoverlay/zoomoverlay.py +1779 -0
  113. screenmagnifier-1.11.0.post8.dist-info/METADATA +591 -0
  114. screenmagnifier-1.11.0.post8.dist-info/RECORD +117 -0
  115. screenmagnifier-1.11.0.post8.dist-info/WHEEL +5 -0
  116. screenmagnifier-1.11.0.post8.dist-info/entry_points.txt +5 -0
  117. screenmagnifier-1.11.0.post8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,411 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ShortcutEditorWidget: edit the keyboard shortcuts of an application.
4
+ - Actions are grouped (e.g. "Magnifier", "Zoomer", "Colors") and can be filtered by name or key.
5
+ - Two scopes: 'window' (active while the application window has focus, primary + alternate shortcut) and 'global'
6
+ (system-wide hotkeys, one shortcut, with a registration status).
7
+ - Conflicts are flagged live: the same key twice in one scope is an error (red); a window shortcut equal to a global
8
+ hotkey is a warning (orange: the global hotkey takes the key everywhere).
9
+ - Click a field and press the keys to record; per-row reset / clear, resetAll().
10
+ - recordingChanged(bool) lets the owner suspend global hotkeys while one is being recorded.
11
+ """
12
+ from ManyQt.QtWidgets import QWidget, QVBoxLayout, QGridLayout, QLabel, QLineEdit, QPushButton, QKeySequenceEdit
13
+ from ManyQt.QtCore import Qt, QEvent, pyqtSignal, pyqtSlot, pyqtProperty
14
+ from ManyQt.QtGui import QKeySequence
15
+
16
+ STYLE = """
17
+ QLabel[role="group"] { color: #9AA3B8; font-size: 10px; font-weight: bold; letter-spacing: 1px; padding-top: 10px; }
18
+ QLabel[role="scope"] { color: #7C8498; font-size: 9px; }
19
+ QLabel[role="ok"] { color: #4CC38A; } QLabel[role="bad"] { color: #F2555A; } QLabel[role="hint"] { color: #7C8498; }
20
+ QKeySequenceEdit[conflict="error"] QLineEdit { border: 1px solid #F2555A; }
21
+ QKeySequenceEdit[conflict="warning"] QLineEdit { border: 1px solid #F0A030; }
22
+ QPushButton[role="small"] { padding: 2px 6px; }
23
+ """ # type: str
24
+
25
+
26
+ def normalize(sequence):
27
+ """
28
+ :param sequence: (str | QKeySequence) Any spelling ('ctrl+alt+p', QKeySequence...).
29
+ :return: (str | unicode | QString) First chord in Qt portable text ('Ctrl+Alt+P'), '' for none.
30
+ """
31
+ seq = QKeySequence(sequence) if not isinstance(sequence, QKeySequence) else sequence # type: QKeySequence
32
+ if seq.isEmpty():
33
+ return ''
34
+ return u'{}'.format(seq.toString(QKeySequence.PortableText)).split(', ')[0]
35
+
36
+
37
+ class ShortcutEditorWidget(QWidget):
38
+ """
39
+ ShortcutEditorWidget class.
40
+ """
41
+ shortcutChanged = pyqtSignal('QString', 'QString', int, 'QString') # type: pyqtSignal # name, scope, slot, keys
42
+ recordingChanged = pyqtSignal(bool) # type: pyqtSignal
43
+ conflictsChanged = pyqtSignal(int) # type: pyqtSignal # number of errors
44
+
45
+ def __init__(self, *args, **kwargs):
46
+ """
47
+ :param actions: (list[dict]) {'name', 'label', 'group', 'scope': 'window' | 'global', 'defaults': [str, ...],
48
+ 'values': [str, ...]} - window actions have 2 slots (primary, alternate), global ones 1.
49
+ :param filterText: (str | unicode | QString) Initial filter.
50
+ :param shortcutChanged: callable | None
51
+ :param recordingChanged: callable | None
52
+ :param args: any
53
+ :param kwargs: any
54
+ """
55
+ actions = kwargs.pop('actions', []) # type: list
56
+ filterText = kwargs.pop('filterText', '') # type: str
57
+ shortcutChanged = kwargs.pop('shortcutChanged', None) # type: callable | None
58
+ recordingChanged = kwargs.pop('recordingChanged', None) # type: callable | None
59
+ super(ShortcutEditorWidget, self).__init__(*args, **kwargs)
60
+ for signal, slot in ((self.shortcutChanged, shortcutChanged), (self.recordingChanged, recordingChanged)):
61
+ if callable(slot):
62
+ signal.connect(slot)
63
+ self.__m_actions = [] # type: list
64
+ self.__m_rows = {} # type: dict # (scope, name) -> {'edits': [...], 'status': QLabel, 'widgets': [...]}
65
+ self.__m_groups = {} # type: dict # group -> header QLabel
66
+ self.__m_filterText = u'{}'.format(filterText) # type: str
67
+ self.__m_recording = False # type: bool
68
+ self.setStyleSheet(STYLE)
69
+ layout = QVBoxLayout(self) # type: QVBoxLayout
70
+ layout.setContentsMargins(0, 0, 0, 0)
71
+ self.__m_filter = QLineEdit(self.__m_filterText) # type: QLineEdit
72
+ self.__m_filter.setPlaceholderText(self.tr(u'Search a feature or a key...'))
73
+ self.__m_filter.setClearButtonEnabled(True)
74
+ self.__m_filter.textChanged.connect(self.setFilterText)
75
+ layout.addWidget(self.__m_filter)
76
+ self.__m_grid = QGridLayout() # type: QGridLayout
77
+ self.__m_grid.setHorizontalSpacing(6)
78
+ self.__m_grid.setVerticalSpacing(3)
79
+ self.__m_grid.setColumnStretch(0, 1)
80
+ layout.addLayout(self.__m_grid)
81
+ self.__m_summary = QLabel() # type: QLabel
82
+ self.__m_summary.setProperty('role', 'hint')
83
+ self.__m_summary.setWordWrap(True)
84
+ layout.addWidget(self.__m_summary)
85
+ self.setActions(actions)
86
+
87
+ # ---------- Building ----------
88
+ def _recorder(self, scope, name, slot):
89
+ """
90
+ :param scope: str | unicode | QString
91
+ :param name: str | unicode | QString
92
+ :param slot: int
93
+ :return: QKeySequenceEdit
94
+ """
95
+ edit = QKeySequenceEdit() # type: QKeySequenceEdit
96
+ edit.setMinimumWidth(96)
97
+ edit.installEventFilter(self)
98
+ for inner in edit.findChildren(QLineEdit): # Focus goes to an internal line edit.
99
+ inner.installEventFilter(self)
100
+ edit.editingFinished.connect(lambda s=scope, n=name, i=slot, e=edit: self._recorded(s, n, i, e))
101
+ return edit
102
+
103
+ def _button(self, text, tip, slot):
104
+ """
105
+ :param text: str | unicode | QString
106
+ :param tip: str | unicode | QString
107
+ :param slot: callable
108
+ :return: QPushButton
109
+ """
110
+ b = QPushButton(text) # type: QPushButton
111
+ b.setProperty('role', 'small')
112
+ b.setToolTip(tip)
113
+ b.setFocusPolicy(Qt.NoFocus)
114
+ b.clicked.connect(slot)
115
+ return b
116
+
117
+ def _build(self):
118
+ """
119
+ :return:
120
+ """
121
+ while self.__m_grid.count():
122
+ item = self.__m_grid.takeAt(0)
123
+ if item.widget() is not None:
124
+ item.widget().deleteLater()
125
+ self.__m_rows, self.__m_groups = {}, {}
126
+ row = 0 # type: int
127
+ for a in self.__m_actions:
128
+ group = u'{}'.format(a.get('group', '')) # type: str
129
+ if group not in self.__m_groups:
130
+ header = QLabel(group.upper()) # type: QLabel
131
+ header.setProperty('role', 'group')
132
+ self.__m_grid.addWidget(header, row, 0, 1, 5)
133
+ self.__m_groups[group] = header
134
+ row += 1
135
+ scope, name = u'{}'.format(a.get('scope', 'window')), u'{}'.format(a['name']) # type: str, str
136
+ label = QLabel(u'{}'.format(a.get('label', name))) # type: QLabel
137
+ label.setWordWrap(True)
138
+ scopeLabel = QLabel(self.tr(u'everywhere') if scope == 'global' else self.tr(u'in the window')) # type: QLabel
139
+ scopeLabel.setProperty('role', 'scope')
140
+ left = QWidget() # type: QWidget
141
+ box = QVBoxLayout(left) # type: QVBoxLayout
142
+ box.setContentsMargins(0, 0, 0, 0)
143
+ box.setSpacing(0)
144
+ box.addWidget(label)
145
+ box.addWidget(scopeLabel)
146
+ slots = 1 if scope == 'global' else 2 # type: int
147
+ edits = [self._recorder(scope, name, i) for i in range(slots)] # type: list
148
+ values = list(a.get('values', [])) + [''] * slots # type: list
149
+ for i, e in enumerate(edits):
150
+ e.setKeySequence(QKeySequence(values[i]))
151
+ e.setToolTip(self.tr(u'Click, then press the keys. Default: {}').format(
152
+ ' / '.join(d for d in a.get('defaults', []) if d) or self.tr(u'none')))
153
+ status = QLabel() # type: QLabel
154
+ status.setFixedWidth(14)
155
+ reset = self._button('\u21ba', self.tr(u'Back to the default'), lambda c=False, s=scope, n=name: self.resetShortcut(s, n))
156
+ clear = self._button('\u2715', self.tr(u'Remove the shortcut(s)'), lambda c=False, s=scope, n=name: self.clearShortcut(s, n))
157
+ self.__m_grid.addWidget(left, row, 0)
158
+ self.__m_grid.addWidget(edits[0], row, 1)
159
+ if slots > 1:
160
+ self.__m_grid.addWidget(edits[1], row, 2)
161
+ self.__m_grid.addWidget(status, row, 3)
162
+ tools = QWidget() # type: QWidget
163
+ t = QVBoxLayout(tools) # type: QVBoxLayout
164
+ t.setContentsMargins(0, 0, 0, 0)
165
+ t.setSpacing(2)
166
+ t.addWidget(reset)
167
+ t.addWidget(clear)
168
+ self.__m_grid.addWidget(tools, row, 4)
169
+ self.__m_rows[(scope, name)] = {'action': a, 'edits': edits, 'status': status,
170
+ 'widgets': [left] + edits + [status, tools], 'group': group}
171
+ row += 1
172
+ self._applyFilter()
173
+ self._checkConflicts()
174
+
175
+ # ---------- Logic ----------
176
+ def _recorded(self, scope, name, slot, edit):
177
+ """
178
+ :param scope: str | unicode | QString
179
+ :param name: str | unicode | QString
180
+ :param slot: int
181
+ :param edit: QKeySequenceEdit
182
+ :return:
183
+ """
184
+ seq = normalize(edit.keySequence()) # type: str # One chord only.
185
+ edit.blockSignals(True)
186
+ edit.setKeySequence(QKeySequence(seq))
187
+ edit.blockSignals(False)
188
+ edit.clearFocus()
189
+ self._store(scope, name, slot, seq)
190
+
191
+ def _store(self, scope, name, slot, seq):
192
+ """
193
+ :param scope: str | unicode | QString
194
+ :param name: str | unicode | QString
195
+ :param slot: int
196
+ :param seq: str | unicode | QString
197
+ :return:
198
+ """
199
+ a = self.__m_rows[(scope, name)]['action'] # type: dict
200
+ values = (list(a.get('values', [])) + ['', ''])[:len(self.__m_rows[(scope, name)]['edits'])] # type: list
201
+ if values[slot] == seq:
202
+ self._checkConflicts()
203
+ return
204
+ values[slot] = seq
205
+ a['values'] = values
206
+ self._checkConflicts()
207
+ self.shortcutChanged.emit(name, scope, slot, seq)
208
+
209
+ def _checkConflicts(self):
210
+ """
211
+ Mark every key used twice: same scope = error, window vs global = warning.
212
+ :return:
213
+ """
214
+ uses = {} # type: dict # key -> [(scope, name, label)]
215
+ for (scope, name), r in self.__m_rows.items():
216
+ for v in r['action'].get('values', []):
217
+ if v:
218
+ uses.setdefault(normalize(v), []).append((scope, name, r['action'].get('label', name)))
219
+ errors = warnings = 0 # type: int
220
+ for (scope, name), r in self.__m_rows.items():
221
+ for e in r['edits']:
222
+ key = normalize(e.keySequence()) # type: str
223
+ others = [u for u in uses.get(key, []) if (u[0], u[1]) != (scope, name)] if key else [] # type: list
224
+ level = '' # type: str
225
+ if any(o[0] == scope for o in others):
226
+ level = 'error'
227
+ elif others:
228
+ level = 'warning'
229
+ e.setProperty('conflict', level)
230
+ e.setToolTip(self.tr(u'{} is also used by: {}').format(key, ', '.join(o[2] for o in others)) if others
231
+ else self.tr(u'Click, then press the keys. Default: {}').format(
232
+ ' / '.join(d for d in r['action'].get('defaults', []) if d) or self.tr(u'none')))
233
+ e.style().unpolish(e)
234
+ e.style().polish(e)
235
+ for inner in e.findChildren(QLineEdit):
236
+ inner.style().unpolish(inner)
237
+ inner.style().polish(inner)
238
+ errors += level == 'error'
239
+ warnings += level == 'warning'
240
+ self.__m_summary.setText(
241
+ (self.tr(u'{} conflict(s): the same keys are used twice in one scope (red).').format(errors // 2 or errors)
242
+ if errors else self.tr(u'No conflicts.')) +
243
+ (self.tr(u' Orange: a window shortcut equal to a global hotkey - the global hotkey takes it.')
244
+ if warnings else ''))
245
+ self.conflictsChanged.emit(errors)
246
+
247
+ def _applyFilter(self):
248
+ """
249
+ :return:
250
+ """
251
+ text = self.__m_filterText.strip().lower() # type: str
252
+ shown = {} # type: dict
253
+ for (scope, name), r in self.__m_rows.items():
254
+ a = r['action'] # type: dict
255
+ haystack = ' '.join([u'{}'.format(a.get('label', '')), u'{}'.format(a.get('group', '')), name] + list(a.get('values', [])))
256
+ visible = not text or text in haystack.lower() # type: bool
257
+ for w in r['widgets']:
258
+ w.setVisible(visible)
259
+ shown[r['group']] = shown.get(r['group'], False) or visible
260
+ for group, header in self.__m_groups.items():
261
+ header.setVisible(shown.get(group, False))
262
+
263
+ # ---------- Qt overrides ----------
264
+ def eventFilter(self, obj, e):
265
+ """
266
+ :param obj: QObject
267
+ :param e: QEvent
268
+ :return: bool
269
+ """
270
+ if e.type() in (QEvent.FocusIn, QEvent.FocusOut) and (
271
+ isinstance(obj, QKeySequenceEdit) or isinstance(obj.parent(), QKeySequenceEdit)):
272
+ recording = e.type() == QEvent.FocusIn # type: bool
273
+ if recording != self.__m_recording:
274
+ self.__m_recording = recording # type: bool
275
+ self.recordingChanged.emit(recording)
276
+ return super(ShortcutEditorWidget, self).eventFilter(obj, e)
277
+
278
+ # ---------- Public API ----------
279
+ def getActions(self):
280
+ """
281
+ :return: (list[dict]) With the current values.
282
+ """
283
+ return [dict(a) for a in self.__m_actions]
284
+
285
+ @pyqtSlot(list)
286
+ def setActions(self, actions):
287
+ """
288
+ :param actions: list[dict]
289
+ :return:
290
+ """
291
+ self.__m_actions = [dict(a, values=list(a.get('values', a.get('defaults', [])))) for a in (actions or [])]
292
+ self._build()
293
+
294
+ def valuesOf(self, scope, name):
295
+ """
296
+ :param scope: str | unicode | QString
297
+ :param name: str | unicode | QString
298
+ :return: (list[str | unicode | QString]) Values (primary, alternate...).
299
+ """
300
+ r = self.__m_rows.get((u'{}'.format(scope), u'{}'.format(name)))
301
+ return list(r['action'].get('values', [])) if r else []
302
+
303
+ def updateShortcut(self, scope, name, values):
304
+ """
305
+ Show values set elsewhere (no shortcutChanged).
306
+ :param scope: str | unicode | QString
307
+ :param name: str | unicode | QString
308
+ :param values: list[str | unicode | QString]
309
+ :return:
310
+ """
311
+ r = self.__m_rows.get((u'{}'.format(scope), u'{}'.format(name)))
312
+ if r is None:
313
+ return
314
+ r['action']['values'] = list(values)
315
+ for i, e in enumerate(r['edits']):
316
+ if not e.hasFocus():
317
+ e.blockSignals(True)
318
+ e.setKeySequence(QKeySequence((list(values) + ['', ''])[i]))
319
+ e.blockSignals(False)
320
+ self._checkConflicts()
321
+
322
+ def resetShortcut(self, scope, name):
323
+ """
324
+ :param scope: str | unicode | QString
325
+ :param name: str | unicode | QString
326
+ :return:
327
+ """
328
+ r = self.__m_rows.get((u'{}'.format(scope), u'{}'.format(name)))
329
+ if r is None:
330
+ return
331
+ defaults = list(r['action'].get('defaults', [])) + ['', ''] # type: list
332
+ for i, e in enumerate(r['edits']):
333
+ e.blockSignals(True)
334
+ e.setKeySequence(QKeySequence(defaults[i]))
335
+ e.blockSignals(False)
336
+ self._store(u'{}'.format(scope), u'{}'.format(name), i, normalize(defaults[i]))
337
+
338
+ def clearShortcut(self, scope, name):
339
+ """
340
+ :param scope: str | unicode | QString
341
+ :param name: str | unicode | QString
342
+ :return:
343
+ """
344
+ r = self.__m_rows.get((u'{}'.format(scope), u'{}'.format(name)))
345
+ if r is None:
346
+ return
347
+ for i, e in enumerate(r['edits']):
348
+ e.blockSignals(True)
349
+ e.clear()
350
+ e.blockSignals(False)
351
+ self._store(u'{}'.format(scope), u'{}'.format(name), i, '')
352
+
353
+ @pyqtSlot()
354
+ def resetAll(self):
355
+ """
356
+ :return:
357
+ """
358
+ for scope, name in list(self.__m_rows):
359
+ self.resetShortcut(scope, name)
360
+
361
+ def setStatus(self, name, state, tip=''):
362
+ """
363
+ Registration status of a global hotkey.
364
+ :param name: str | unicode | QString
365
+ :param state: (bool | None) True registered, False refused, None unknown / unbound.
366
+ :param tip: str | unicode | QString
367
+ :return: None
368
+ """
369
+ r = self.__m_rows.get(('global', u'{}'.format(name)))
370
+ if r is None:
371
+ return
372
+ s = r['status'] # type: QLabel
373
+ s.setText({True: '\u2713', False: '\u2717'}.get(state, ''))
374
+ s.setProperty('role', {True: 'ok', False: 'bad'}.get(state, 'hint'))
375
+ s.setToolTip(tip)
376
+ s.style().unpolish(s)
377
+ s.style().polish(s)
378
+
379
+ def conflictCount(self):
380
+ """
381
+ :return: (int) Number of shortcut fields in a same-scope conflict.
382
+ """
383
+ return sum(1 for r in self.__m_rows.values() for e in r['edits'] if e.property('conflict') == 'error')
384
+
385
+ def isRecording(self):
386
+ """
387
+ :return: bool
388
+ """
389
+ return self.__m_recording
390
+
391
+ def getFilterText(self):
392
+ """
393
+ :return: str | unicode | QString
394
+ """
395
+ return self.__m_filterText
396
+
397
+ @pyqtSlot('QString')
398
+ @pyqtSlot(str)
399
+ def setFilterText(self, filterText):
400
+ """
401
+ :param filterText: str | unicode | QString
402
+ :return:
403
+ """
404
+ self.__m_filterText = filterText # type: str
405
+ if self.__m_filter.text() != self.__m_filterText:
406
+ self.__m_filter.setText(self.__m_filterText)
407
+ self._applyFilter()
408
+
409
+ # ---------- Properties ----------
410
+ actions = pyqtProperty(list, fget=getActions, fset=setActions) # type: pyqtProperty
411
+ filterText = pyqtProperty('QString', fget=getFilterText, fset=setFilterText) # type: pyqtProperty
@@ -0,0 +1,118 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Keyboard shortcuts of every feature - the single registry used by the window actions, the zoomer's global hotkeys
4
+ and the Shortcuts tab.
5
+ Scopes:
6
+ window : active while the Screen Magnifier window has focus; a primary and an alternate shortcut.
7
+ global : system-wide hotkeys (also in other applications and games), one shortcut each; saved by the zoomer
8
+ controller (AdvancedOverlayController.setHotkey()).
9
+ """
10
+ from ManyQt.QtCore import QObject, QSettings, pyqtSignal, pyqtSlot
11
+
12
+ SHORTCUTS = [ # (scope, name, group, label, defaults)
13
+ ('window', 'selectRegion', 'Magnifier', 'Select a region', ('Ctrl+R', '')),
14
+ ('window', 'followCursor', 'Magnifier', 'Follow the mouse cursor', ('F', '')),
15
+ ('window', 'freeze', 'Magnifier', 'Freeze / unfreeze', ('Space', '')),
16
+ ('window', 'viewZoomIn', 'Magnifier', 'Zoom in', ('+', '=')),
17
+ ('window', 'viewZoomOut', 'Magnifier', 'Zoom out', ('-', '')),
18
+ ('window', 'viewFit', 'Magnifier', 'Fit the region', ('0', '')),
19
+ ('window', 'saveSnapshot', 'Magnifier', 'Save the zoomed image', ('Ctrl+S', '')),
20
+ ('window', 'copySnapshot', 'Magnifier', 'Copy the zoomed image', ('Ctrl+C', '')),
21
+ ('global', 'toggle', 'Zoomer', 'Show / hide the zoomer', ('Ctrl+Alt+Z',)),
22
+ ('global', 'zoomIn', 'Zoomer', 'Zoomer: zoom in', ('Ctrl+Alt+=',)),
23
+ ('global', 'zoomOut', 'Zoomer', 'Zoomer: zoom out', ('Ctrl+Alt+-',)),
24
+ ('global', 'pinTarget', 'Zoomer', 'Pin the zoomer target at the mouse', ('Ctrl+Alt+X',)),
25
+ ('global', 'cycleTarget', 'Zoomer', 'Cycle the zoomer target', ('Ctrl+Alt+C',)),
26
+ ('global', 'copyZoomerColor', 'Colors', 'Copy the zoomer color code', ('Ctrl+Alt+K',)),
27
+ ('global', 'screenPicker', 'Colors', 'Screen color picker: start / copy', ('Ctrl+Alt+P',)),
28
+ ('global', 'facePointer', 'Faces', 'Face pointer: on / off', ('Ctrl+Alt+F',)),
29
+ ('window', 'screenPickerWindow', 'Colors', 'Screen color picker', ('Ctrl+Shift+P', '')),
30
+ ('window', 'eyedropper', 'Colors', 'Eyedropper on the magnifier on / off', ('I', '')),
31
+ ('window', 'stopEyedropper', 'Colors', 'Stop the eyedropper', ('Esc', '')),
32
+ ('window', 'copyHoveredColor', 'Colors', 'Copy the color under the mouse', ('C', '')),
33
+ ('window', 'pinOnTop', 'Window', 'Keep the window on top', ('T', '')),
34
+ ('window', 'toggleSidePanel', 'Window', 'Show / hide the side panel', ('Ctrl+,', '')),
35
+ ('window', 'quit', 'Window', 'Quit', ('Ctrl+Q', '')),
36
+ ] # type: list[tuple]
37
+
38
+ HOTKEY_ACTIONS = [(name, label, defaults[0]) for scope, name, group, label, defaults in SHORTCUTS
39
+ if scope == 'global'] # type: list[tuple[str, str, str]] # For the zoomer controller.
40
+
41
+
42
+ def shortcutInfo(scope, name):
43
+ """
44
+ :param scope: str | unicode | QString
45
+ :param name: str | unicode | QString
46
+ :return: (tuple | None) Registry entry.
47
+ """
48
+ return next((s for s in SHORTCUTS if s[0] == scope and s[1] == name), None)
49
+
50
+
51
+ def defaultsOf(scope, name):
52
+ """
53
+ :param scope: str | unicode | QString
54
+ :param name: str | unicode | QString
55
+ :return: (list[str | unicode | QString]) Default sequences.
56
+ """
57
+ info = shortcutInfo(scope, name)
58
+ return list(info[4]) if info else []
59
+
60
+
61
+ class ShortcutStore(QObject):
62
+ """
63
+ ShortcutStore class: saved window shortcuts (primary | alternate) of every registry action.
64
+ """
65
+ changed = pyqtSignal('QString') # type: pyqtSignal # window shortcut name
66
+
67
+ def __init__(self, *args, **kwargs):
68
+ """
69
+ :param settings: (QSettings | None) None = ScreenMagnifier / Shortcuts.
70
+ :param args: any
71
+ :param kwargs: any
72
+ """
73
+ settings = kwargs.pop('settings', None) # type: QSettings | None
74
+ super(ShortcutStore, self).__init__(*args, **kwargs)
75
+ self.__m_settings = settings if settings is not None else QSettings('ScreenMagnifier', 'Shortcuts')
76
+
77
+ def get(self, name):
78
+ """
79
+ :param name: str | unicode | QString
80
+ :return: (list[str | unicode | QString]) [primary, alternate] ('' = none).
81
+ """
82
+ defaults = (defaultsOf('window', name) + ['', ''])[:2] # type: list
83
+ saved = self.__m_settings.value('window/' + u'{}'.format(name), None)
84
+ if saved is None:
85
+ return defaults
86
+ return (u'{}'.format(saved).split('|') + ['', ''])[:2]
87
+
88
+ def sequences(self, name):
89
+ """
90
+ :param name: str | unicode | QString
91
+ :return: (list[str | unicode | QString]) Non-empty sequences, for QAction.setShortcuts().
92
+ """
93
+ return [s for s in self.get(name) if s]
94
+
95
+ def set(self, name, slot, sequence):
96
+ """
97
+ :param name: str | unicode | QString
98
+ :param slot: (int) 0 primary, 1 alternate.
99
+ :param sequence: (str | unicode | QString) Qt portable text, '' = none.
100
+ :return:
101
+ """
102
+ values = self.get(name) # type: list
103
+ values[int(slot)] = u'{}'.format(sequence)
104
+ if values == (defaultsOf('window', name) + ['', ''])[:2]:
105
+ self.__m_settings.remove('window/' + u'{}'.format(name)) # Default: nothing saved, future defaults apply.
106
+ else:
107
+ self.__m_settings.setValue('window/' + u'{}'.format(name), '|'.join(values))
108
+ self.changed.emit(u'{}'.format(name))
109
+
110
+ @pyqtSlot('QString')
111
+ @pyqtSlot(str)
112
+ def reset(self, name):
113
+ """
114
+ :param name: str | unicode | QString
115
+ :return:
116
+ """
117
+ self.__m_settings.remove('window/' + u'{}'.format(name))
118
+ self.changed.emit(u'{}'.format(name))
@@ -0,0 +1,140 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ShortcutsPanel: the Shortcuts tab - every keyboard shortcut of every feature, editable, with conflict detection.
4
+ Window shortcuts are saved by ShortcutStore, global hotkeys by the zoomer controller (they work in other applications
5
+ and games). Global hotkeys are suspended while one is recorded, so pressing the current keys does not trigger them.
6
+ """
7
+ from ManyQt.QtWidgets import QWidget, QVBoxLayout, QLabel, QCheckBox, QPushButton, QScrollArea, QFrame
8
+ from ManyQt.QtCore import Qt
9
+ from os.path import dirname
10
+ from sys import path
11
+
12
+ if not __package__ and dirname(__file__) not in path:
13
+ path.append(dirname(__file__))
14
+
15
+ try:
16
+ from .shortcuts import SHORTCUTS, ShortcutStore, defaultsOf
17
+ from .shortcuteditor import ShortcutEditorWidget
18
+ except:
19
+ from shortcuts import SHORTCUTS, ShortcutStore, defaultsOf
20
+ from shortcuteditor import ShortcutEditorWidget
21
+
22
+ PANEL_QSS = """
23
+ QWidget#shortcutContent { background: transparent; }
24
+ QLabel[role="title"] { color: #9AA3B8; font-size: 10px; font-weight: bold; letter-spacing: 1px; padding-top: 10px; }
25
+ QLabel[role="hint"] { color: #7C8498; font-size: 10px; }
26
+ """ # type: str
27
+
28
+
29
+ class ShortcutsPanel(QScrollArea):
30
+ """
31
+ ShortcutsPanel class.
32
+ """
33
+
34
+ def __init__(self, *args, **kwargs):
35
+ """
36
+ :param store: ShortcutStore
37
+ :param controller: AdvancedOverlayController (global hotkeys).
38
+ :param args: any
39
+ :param kwargs: any
40
+ """
41
+ store = kwargs.pop('store', None) # type: ShortcutStore
42
+ controller = kwargs.pop('controller', None)
43
+ super(ShortcutsPanel, self).__init__(*args, **kwargs)
44
+ self.__m_store = store # type: ShortcutStore
45
+ self.__m_ctrl = controller
46
+ self.setWidgetResizable(True)
47
+ self.setFrameShape(QFrame.NoFrame)
48
+ self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
49
+ self.setMinimumWidth(300)
50
+ content = QWidget() # type: QWidget
51
+ content.setObjectName('shortcutContent')
52
+ content.setStyleSheet(PANEL_QSS)
53
+ lay = QVBoxLayout(content) # type: QVBoxLayout
54
+ lay.setContentsMargins(14, 6, 14, 14)
55
+ lay.setSpacing(6)
56
+ title = QLabel(self.tr(u'KEYBOARD SHORTCUTS')) # type: QLabel
57
+ title.setProperty('role', 'title')
58
+ lay.addWidget(title)
59
+ self.__m_global = QCheckBox(self.tr(u'Global hotkeys: work in other applications and games')) # type: QCheckBox
60
+ self.__m_global.setChecked(controller.isHotkeysEnabled())
61
+ self.__m_global.toggled.connect(controller.setHotkeysEnabled)
62
+ lay.addWidget(self.__m_global)
63
+ self.__m_backend = QLabel() # type: QLabel
64
+ self.__m_backend.setProperty('role', 'hint')
65
+ self.__m_backend.setWordWrap(True)
66
+ lay.addWidget(self.__m_backend)
67
+ self.__m_editor = ShortcutEditorWidget(actions=self._actions()) # type: ShortcutEditorWidget
68
+ self.__m_editor.shortcutChanged.connect(self._onChanged)
69
+ self.__m_editor.recordingChanged.connect(self._onRecording)
70
+ lay.addWidget(self.__m_editor)
71
+ reset = QPushButton(self.tr(u'Reset every shortcut to its default')) # type: QPushButton
72
+ reset.setFocusPolicy(Qt.NoFocus)
73
+ reset.clicked.connect(self.__m_editor.resetAll)
74
+ lay.addWidget(reset)
75
+ hint = QLabel(self.tr(u'Click a field and press the new keys. "In the window" shortcuts work while this window '
76
+ u'is active; "everywhere" hotkeys work in any application or game. \u2713 registered, '
77
+ u'\u2717 refused (taken by another application).')) # type: QLabel
78
+ hint.setProperty('role', 'hint')
79
+ hint.setWordWrap(True)
80
+ lay.addWidget(hint)
81
+ lay.addStretch(1)
82
+ self.setWidget(content)
83
+ store.changed.connect(lambda name: self.__m_editor.updateShortcut('window', name, store.get(name)))
84
+ controller.getHotkeys().registrationChanged.connect(self.refreshStatus)
85
+ controller.settingsChanged.connect(self.refreshStatus)
86
+ self.refreshStatus()
87
+
88
+ def _actions(self):
89
+ """
90
+ :return: (list[dict]) Registry entries with their current values, for the editor.
91
+ """
92
+ out = [] # type: list
93
+ for scope, name, group, label, defaults in SHORTCUTS:
94
+ values = self.__m_store.get(name) if scope == 'window' else [self.__m_ctrl.getHotkey(name)] # type: list
95
+ out.append({'name': name, 'scope': scope, 'group': self.tr(group), 'label': self.tr(label),
96
+ 'defaults': list(defaults), 'values': values})
97
+ return out
98
+
99
+ def _onChanged(self, name, scope, slot, keys):
100
+ """
101
+ :param name: str | unicode | QString
102
+ :param scope: str | unicode | QString
103
+ :param slot: int
104
+ :param keys: str | unicode | QString
105
+ :return:
106
+ """
107
+ if u'{}'.format(scope) == 'global':
108
+ self.__m_ctrl.setHotkey(u'{}'.format(name), u'{}'.format(keys))
109
+ else:
110
+ self.__m_store.set(u'{}'.format(name), int(slot), u'{}'.format(keys))
111
+
112
+ def _onRecording(self, recording):
113
+ """
114
+ :param recording: bool
115
+ :return:
116
+ """
117
+ self.__m_ctrl.getHotkeys().setEnabled(False if recording else self.__m_ctrl.isHotkeysEnabled())
118
+
119
+ def refreshStatus(self):
120
+ """
121
+ :return:
122
+ """
123
+ hk = self.__m_ctrl.getHotkeys()
124
+ self.__m_global.blockSignals(True)
125
+ self.__m_global.setChecked(self.__m_ctrl.isHotkeysEnabled())
126
+ self.__m_global.blockSignals(False)
127
+ for scope, name, group, label, defaults in SHORTCUTS:
128
+ if scope == 'global':
129
+ self.__m_editor.updateShortcut('global', name, [self.__m_ctrl.getHotkey(name)])
130
+ state = hk.getStatus(name)
131
+ self.__m_editor.setStatus(name, state, {True: self.tr(u'Registered'), False: self.tr(
132
+ u'Could not register: invalid, or already used by another application')}.get(state, ''))
133
+ backend = {'windows': 'Windows RegisterHotKey', 'pynput': 'pynput'}.get(hk.getBackendName(), 'none')
134
+ self.__m_backend.setText(hk.getError() or self.tr(u'Global hotkeys backend: {}').format(backend))
135
+
136
+ def getEditor(self):
137
+ """
138
+ :return: ShortcutEditorWidget
139
+ """
140
+ return self.__m_editor