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,50 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ FeatureSettings: where the detection results are shown - the single source of truth shared by the Detection tab,
4
+ the Zoomer tab and the application logic (every checkbox bound to a feature follows changed()).
5
+ zonesInMagnifier : color zones (and faces) drawn in the magnifier.
6
+ zonesInZoomer : color zones (and faces) drawn in the zoomer lens.
7
+ The zoomer's color code (live HEX under the crosshair) is a zoomer option (AdvancedOverlayController.setColorReadout).
8
+ """
9
+ from ManyQt.QtCore import QObject, QSettings, pyqtSignal
10
+
11
+ FEATURES = {'zonesInMagnifier': True, 'zonesInZoomer': False} # type: dict # name -> default
12
+
13
+
14
+ class FeatureSettings(QObject):
15
+ """
16
+ FeatureSettings class.
17
+ """
18
+ changed = pyqtSignal('QString', bool) # type: pyqtSignal
19
+
20
+ def __init__(self, *args, **kwargs):
21
+ """
22
+ :param settings: (QSettings | None) None = ScreenMagnifier / Features.
23
+ :param args: any
24
+ :param kwargs: any
25
+ """
26
+ settings = kwargs.pop('settings', None) # type: QSettings | None
27
+ super(FeatureSettings, self).__init__(*args, **kwargs)
28
+ self.__m_settings = settings if settings is not None else QSettings('ScreenMagnifier', 'Features')
29
+ if self.__m_settings.value('zonesInZoomer', None) is None: # Earlier versions: Detection tab option.
30
+ old = QSettings('ScreenMagnifier', 'Detection').value('lens', None)
31
+ if old is not None:
32
+ self.__m_settings.setValue('zonesInZoomer', u'{}'.format(old).lower() in ('1', 'true', 'yes'))
33
+
34
+ def get(self, name):
35
+ """
36
+ :param name: str | unicode | QString
37
+ :return: bool
38
+ """
39
+ value = self.__m_settings.value(u'{}'.format(name), FEATURES.get(u'{}'.format(name), False))
40
+ return u'{}'.format(value).lower() in ('1', 'true', 'yes')
41
+
42
+ def set(self, name, on):
43
+ """
44
+ :param name: str | unicode | QString
45
+ :param on: bool
46
+ :return:
47
+ """
48
+ if self.get(name) != bool(on):
49
+ self.__m_settings.setValue(u'{}'.format(name), bool(on))
50
+ self.changed.emit(u'{}'.format(name), bool(on))
@@ -0,0 +1,16 @@
1
+ # coding=utf-8
2
+ """
3
+ hotkeys package.
4
+ """
5
+ from os.path import dirname
6
+ from sys import path
7
+
8
+ if not __package__ and dirname(__file__) not in path:
9
+ path.append(dirname(__file__))
10
+
11
+ try:
12
+ from .hotkeys import GlobalHotkeys
13
+ except:
14
+ from hotkeys import GlobalHotkeys
15
+
16
+ __all__ = ['GlobalHotkeys'] # type: list[str]
@@ -0,0 +1,379 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ GlobalHotkeys: system-wide keyboard shortcuts that fire even while another application (e.g. a game) has the
4
+ keyboard focus.
5
+ Backends:
6
+ - windows : Win32 RegisterHotKey on a dedicated message-loop thread. No dependency. The combination is
7
+ consumed, so the focused application does not receive it.
8
+ - pynput : pynput.keyboard.GlobalHotKeys (Linux X11, macOS with Accessibility permission). The focused
9
+ application still receives the keys.
10
+ Key sequences use Qt's portable text form, e.g. 'Ctrl+Alt+Z', 'Ctrl+Alt+=', 'Ctrl+Shift+F9', 'Num+5'.
11
+ """
12
+ from ManyQt.QtCore import QObject, pyqtSignal, pyqtSlot, pyqtProperty
13
+ from threading import Thread, Event
14
+ from sys import platform
15
+
16
+ MODIFIERS = {'ctrl': 'Ctrl', 'control': 'Ctrl', 'alt': 'Alt', 'option': 'Alt', 'shift': 'Shift', 'meta': 'Meta',
17
+ 'win': 'Meta', 'super': 'Meta', 'cmd': 'Meta', 'num': 'Num', 'keypad': 'Num'} # type: dict[str, str]
18
+ KEY_ALIASES = {'escape': 'Esc', 'esc': 'Esc', 'insert': 'Ins', 'ins': 'Ins', 'delete': 'Del', 'del': 'Del',
19
+ 'pageup': 'PgUp', 'pgup': 'PgUp', 'pagedown': 'PgDown', 'pgdown': 'PgDown', 'return': 'Return',
20
+ 'enter': 'Enter', 'space': 'Space', 'tab': 'Tab', 'backspace': 'Backspace', 'home': 'Home',
21
+ 'end': 'End', 'up': 'Up', 'down': 'Down', 'left': 'Left', 'right': 'Right', 'pause': 'Pause',
22
+ 'print': 'Print', 'printscreen': 'Print', 'scrolllock': 'ScrollLock', 'numlock': 'NumLock',
23
+ 'plus': '+', 'minus': '-'} # type: dict[str, str]
24
+ # Win32 virtual-key codes.
25
+ VK_NAMED = {'Up': 0x26, 'Down': 0x28, 'Left': 0x25, 'Right': 0x27, 'Space': 0x20, 'Tab': 0x09, 'Esc': 0x1B,
26
+ 'Return': 0x0D, 'Enter': 0x0D, 'Ins': 0x2D, 'Del': 0x2E, 'Home': 0x24, 'End': 0x23, 'PgUp': 0x21,
27
+ 'PgDown': 0x22, 'Backspace': 0x08, 'Pause': 0x13, 'Print': 0x2C, 'ScrollLock': 0x91,
28
+ 'NumLock': 0x90, '=': 0xBB, '+': 0xBB, '-': 0xBD, ',': 0xBC, '.': 0xBE, '/': 0xBF, ';': 0xBA,
29
+ '`': 0xC0, '[': 0xDB, '\\': 0xDC, ']': 0xDD, "'": 0xDE} # type: dict[str, int]
30
+ VK_KEYPAD = {'+': 0x6B, '-': 0x6D, '*': 0x6A, '/': 0x6F, '.': 0x6E, 'Enter': 0x0D} # type: dict[str, int]
31
+ MOD_FLAGS = {'Alt': 0x0001, 'Ctrl': 0x0002, 'Shift': 0x0004, 'Meta': 0x0008} # type: dict[str, int]
32
+ MOD_NOREPEAT = 0x4000 # type: int
33
+ # pynput tokens.
34
+ PYNPUT_MODS = {'Ctrl': '<ctrl>', 'Alt': '<alt>', 'Shift': '<shift>', 'Meta': '<cmd>'} # type: dict
35
+ PYNPUT_NAMED = {'Up': '<up>', 'Down': '<down>', 'Left': '<left>', 'Right': '<right>', 'Space': '<space>',
36
+ 'Tab': '<tab>', 'Esc': '<esc>', 'Return': '<enter>', 'Enter': '<enter>', 'Ins': '<insert>',
37
+ 'Del': '<delete>', 'Home': '<home>', 'End': '<end>', 'PgUp': '<page_up>',
38
+ 'PgDown': '<page_down>', 'Backspace': '<backspace>', 'Pause': '<pause>',
39
+ 'Print': '<print_screen>', 'ScrollLock': '<scroll_lock>', 'NumLock': '<num_lock>',
40
+ '+': '='} # type: dict[str, str]
41
+
42
+
43
+ def parseSequence(sequence):
44
+ """
45
+ Parse 'Ctrl+Alt+Z' (Qt portable text, first chord only) into its modifiers and key.
46
+ :param sequence: str | unicode | QString
47
+ :return: (tuple[frozenset, str]) Canonical modifiers and key.
48
+ :raise ValueError: on empty or unknown sequences.
49
+ """
50
+ text = u'{}'.format(sequence).split(',')[0].strip() # type: str
51
+ if not text:
52
+ raise ValueError(u'Empty key sequence')
53
+ if text.endswith('++') or text == '+':
54
+ parts, key = [p for p in text[:-2].split('+') if p], '+'
55
+ else:
56
+ parts = text.split('+') # type: list
57
+ key = parts.pop() # type: str
58
+ mods = set() # type: set
59
+ for p in parts:
60
+ m = MODIFIERS.get(p.strip().lower())
61
+ if m is None:
62
+ raise ValueError(u'Unknown modifier: {}'.format(p))
63
+ mods.add(m)
64
+ key = key.strip() # type: str
65
+ low = key.lower() # type: str
66
+ if low in KEY_ALIASES:
67
+ key = KEY_ALIASES[low] # type: str
68
+ elif len(key) == 1:
69
+ key = key.upper() # type: str
70
+ elif low.startswith('f') and low[1:].isdigit() and 1 <= int(low[1:]) <= 24:
71
+ key = 'F{}'.format(int(low[1:])) # type: str
72
+ else:
73
+ raise ValueError(u'Unknown key: {}'.format(key))
74
+ return frozenset(mods), key
75
+
76
+
77
+ def toVirtualKey(mods, key):
78
+ """
79
+ :param mods: frozenset
80
+ :param key: str | unicode | QString
81
+ :return: (tuple[int, int]) RegisterHotKey modifier flags and virtual-key code.
82
+ """
83
+ flags = 0 # type: int
84
+ for m in mods:
85
+ flags |= MOD_FLAGS.get(m, 0)
86
+ if 'Num' in mods and (key.isdigit() or key in VK_KEYPAD):
87
+ vk = 0x60 + int(key) if key.isdigit() else VK_KEYPAD[key] # type: int
88
+ elif len(key) == 1 and (key.isalpha() or key.isdigit()):
89
+ vk = ord(key) # type: int
90
+ elif key.startswith('F') and key[1:].isdigit():
91
+ vk = 0x6F + int(key[1:]) # type: int
92
+ elif key in VK_NAMED:
93
+ vk = VK_NAMED[key] # type: int
94
+ else:
95
+ raise ValueError(u'No virtual-key code for {}'.format(key))
96
+ return flags | MOD_NOREPEAT, vk
97
+
98
+
99
+ def toPynput(mods, key):
100
+ """
101
+ :param mods: frozenset
102
+ :param key: str | unicode | QString
103
+ :return: (str | unicode | QString)pynput hotkey string such as '<ctrl>+<alt>+z'.
104
+ """
105
+ tokens = [PYNPUT_MODS[m] for m in ('Ctrl', 'Alt', 'Shift', 'Meta') if m in mods] # type: list
106
+ if key.startswith('F') and key[1:].isdigit():
107
+ tokens.append('<{}>'.format(key.lower()))
108
+ elif key in PYNPUT_NAMED:
109
+ tokens.append(PYNPUT_NAMED[key])
110
+ else:
111
+ tokens.append(key.lower())
112
+ return '+'.join(tokens)
113
+
114
+
115
+ class _WindowsBackend(object):
116
+ """
117
+ RegisterHotKey on a private thread that runs its own Win32 message loop.
118
+ """
119
+
120
+ def __init__(self, bindings, callback):
121
+ """
122
+ :param bindings: (dict) name -> (modifiers, key).
123
+ :param callback: (callable) f(name), called from the hotkey thread.
124
+ :return:
125
+ """
126
+ self.status = {} # type: dict
127
+ self.__m_bindings = bindings # type: dict
128
+ self.__m_callback = callback # type: callable
129
+ self.__m_threadId = 0 # type: int
130
+ self.__m_ready = Event() # type: Event
131
+ self.__m_thread = Thread(target=self._run, name='GlobalHotkeys') # type: Thread
132
+ self.__m_thread.daemon = True
133
+ self.__m_thread.start()
134
+ self.__m_ready.wait(2.0)
135
+
136
+ def _run(self):
137
+ """
138
+ :return:
139
+ """
140
+ from ctypes import c_int, byref, windll, POINTER
141
+ from ctypes.wintypes import HWND, UINT, MSG
142
+ user32 = windll.user32
143
+ kernel32 = windll.kernel32
144
+ user32.RegisterHotKey.argtypes = [HWND, c_int, UINT, UINT]
145
+ user32.UnregisterHotKey.argtypes = [HWND, c_int]
146
+ user32.GetMessageW.argtypes = [POINTER(MSG), HWND, UINT, UINT]
147
+ user32.PeekMessageW.argtypes = [POINTER(MSG), HWND, UINT, UINT, UINT]
148
+ WM_HOTKEY, WM_USER, PM_NOREMOVE = 0x0312, 0x0400, 0x0000
149
+ msg = MSG()
150
+ user32.PeekMessageW(byref(msg), None, WM_USER, WM_USER, PM_NOREMOVE) # Create the queue.
151
+ self.__m_threadId = kernel32.GetCurrentThreadId() # type: int
152
+ ids = {} # type: dict
153
+ for i, (name, (mods, key)) in enumerate(sorted(self.__m_bindings.items()), 1):
154
+ try:
155
+ flags, vk = toVirtualKey(mods, key)
156
+ ok = bool(user32.RegisterHotKey(None, i, flags, vk)) # type: bool
157
+ except ValueError:
158
+ ok = False # type: bool
159
+ self.status[name] = ok
160
+ if ok:
161
+ ids[i] = name
162
+ self.__m_ready.set()
163
+ while user32.GetMessageW(byref(msg), None, 0, 0) > 0:
164
+ if msg.message == WM_HOTKEY and msg.wParam in ids:
165
+ self.__m_callback(ids[msg.wParam])
166
+ for i in ids:
167
+ user32.UnregisterHotKey(None, i)
168
+
169
+ def stop(self):
170
+ """
171
+ :return:
172
+ """
173
+ if self.__m_threadId:
174
+ from ctypes import windll
175
+ WM_QUIT = 0x0012 # type: int
176
+ windll.user32.PostThreadMessageW(self.__m_threadId, WM_QUIT, 0, 0)
177
+ self.__m_thread.join(1.0)
178
+
179
+
180
+ class _PynputBackend(object):
181
+ """
182
+ pynput.keyboard.GlobalHotKeys wrapper.
183
+ """
184
+
185
+ def __init__(self, bindings, callback):
186
+ """
187
+ :param bindings: (dict) name -> (modifiers, key).
188
+ :param callback: (callable) f(name), called from the listener thread.
189
+ """
190
+ from pynput import keyboard
191
+ self.status = {} # type: dict
192
+ mapping = {} # type: dict
193
+ for name, (mods, key) in bindings.items():
194
+ combo = toPynput(mods, key) # type: str
195
+ try:
196
+ keyboard.HotKey.parse(combo)
197
+ mapping[combo] = (lambda n=name: callback(n))
198
+ self.status[name] = True
199
+ except Exception:
200
+ self.status[name] = False
201
+ self.__m_listener = keyboard.GlobalHotKeys(mapping)
202
+ self.__m_listener.daemon = True
203
+ self.__m_listener.start()
204
+
205
+ def stop(self):
206
+ """
207
+ :return:
208
+ """
209
+ self.__m_listener.stop()
210
+
211
+
212
+ class GlobalHotkeys(QObject):
213
+ """
214
+ GlobalHotkeys class: name -> key sequence bindings, activated(name) when one is pressed anywhere.
215
+ """
216
+ activated = pyqtSignal('QString') # type: pyqtSignal
217
+ registrationChanged = pyqtSignal() # type: pyqtSignal
218
+ enabledChanged = pyqtSignal(bool) # type: pyqtSignal
219
+
220
+ def __init__(self, *args, **kwargs):
221
+ """
222
+ :param bindings: (dict[str, str]) name -> key sequence, e.g. {'toggle': 'Ctrl+Alt+Z'}.
223
+ :param enabled: bool
224
+ :param backend: (str | unicode | QString)'auto' | 'windows' | 'pynput'
225
+ :param activated: callable | None
226
+ :param args: any
227
+ :param kwargs: any
228
+ """
229
+ bindings = kwargs.pop('bindings', {}) # type: dict
230
+ enabled = kwargs.pop('enabled', True) # type: bool
231
+ backend = kwargs.pop('backend', 'auto') # type: str
232
+ activated = kwargs.pop('activated', None) # type: callable | None
233
+ super(GlobalHotkeys, self).__init__(*args, **kwargs)
234
+ if callable(activated):
235
+ self.activated.connect(activated)
236
+ self.__m_bindings = dict(bindings) # type: dict
237
+ self.__m_enabled = bool(enabled) # type: bool
238
+ self.__m_backendName = GlobalHotkeys.detectBackend() if backend == 'auto' else u'{}'.format(backend) # type: str
239
+ self.__m_backend = None # type: _WindowsBackend | _PynputBackend | None
240
+ self.__m_status = {} # type: dict
241
+ self.__m_error = '' # type: str
242
+ self._apply()
243
+
244
+ # ---------- Helpers ----------
245
+ @staticmethod
246
+ def detectBackend():
247
+ """
248
+ :return: (str | unicode | QString)'windows', 'pynput' or '' when no backend can work here.
249
+ """
250
+ if platform == 'win32':
251
+ return 'windows'
252
+ try:
253
+ from pynput import keyboard # noqa: F401 (fails without an X server / permission)
254
+ return 'pynput'
255
+ except:
256
+ return ''
257
+
258
+ def _emit(self, name):
259
+ """
260
+ Called from the backend thread; the queued signal delivers it in the GUI thread.
261
+ :param name: str | unicode | QString
262
+ :return:
263
+ """
264
+ self.activated.emit(name)
265
+
266
+ def _apply(self):
267
+ """
268
+ (Re)register every binding with the backend.
269
+ :return:
270
+ """
271
+ if self.__m_backend is not None:
272
+ try:
273
+ self.__m_backend.stop()
274
+ except Exception:
275
+ pass
276
+ self.__m_backend = None
277
+ self.__m_status = {} # type: dict
278
+ self.__m_error = '' # type: str
279
+ parsed = {} # type: dict
280
+ for name, seq in self.__m_bindings.items():
281
+ try:
282
+ parsed[name] = parseSequence(seq)
283
+ except ValueError:
284
+ self.__m_status[name] = False
285
+ if self.__m_enabled and parsed:
286
+ try:
287
+ if self.__m_backendName == 'windows':
288
+ self.__m_backend = _WindowsBackend(parsed, self._emit)
289
+ elif self.__m_backendName == 'pynput':
290
+ self.__m_backend = _PynputBackend(parsed, self._emit)
291
+ else:
292
+ self.__m_error = 'No global hotkey backend: install pynput (pip install pynput).' # type: str
293
+ if self.__m_backend is not None:
294
+ self.__m_status.update(self.__m_backend.status)
295
+ except Exception as e:
296
+ self.__m_backend = None
297
+ self.__m_error = 'Global hotkeys unavailable: {}'.format(e) # type: str
298
+ self.registrationChanged.emit()
299
+
300
+ # ---------- Public API ----------
301
+ def getStatus(self, name):
302
+ """
303
+ :param name: str | unicode | QString
304
+ :return: (bool | None) True registered, False failed (invalid or taken by another app), None inactive.
305
+ """
306
+ return self.__m_status.get(name)
307
+
308
+ def getError(self):
309
+ """
310
+ :return: str | unicode | QString
311
+ """
312
+ return self.__m_error
313
+
314
+ def getBackendName(self):
315
+ """
316
+ :return: str | unicode | QString
317
+ """
318
+ return self.__m_backendName
319
+
320
+ def getBindings(self):
321
+ """
322
+ :return: dict[str, str]
323
+ """
324
+ return dict(self.__m_bindings)
325
+
326
+ def setBindings(self, bindings):
327
+ """
328
+ :param bindings: dict[str, str]
329
+ :return:
330
+ """
331
+ self.__m_bindings = dict(bindings) # type: dict
332
+ self._apply()
333
+
334
+ def setBinding(self, name, sequence):
335
+ """
336
+ :param name: str | unicode | QString
337
+ :param sequence: (str | unicode | QString)Empty string removes the binding.
338
+ :return:
339
+ """
340
+ if sequence:
341
+ self.__m_bindings[u'{}'.format(name)] = u'{}'.format(sequence)
342
+ else:
343
+ self.__m_bindings.pop(u'{}'.format(name), None)
344
+ self._apply()
345
+
346
+ def isEnabled(self):
347
+ """
348
+ :return: bool
349
+ """
350
+ return self.__m_enabled
351
+
352
+ @pyqtSlot(bool)
353
+ @pyqtSlot(int)
354
+ def setEnabled(self, enabled):
355
+ """
356
+ :param enabled: bool
357
+ :return:
358
+ """
359
+ enabled = bool(enabled) # type: bool
360
+ if enabled != self.__m_enabled:
361
+ self.__m_enabled = enabled # type: bool
362
+ self._apply()
363
+ self.enabledChanged.emit(enabled)
364
+
365
+ @pyqtSlot()
366
+ def shutdown(self):
367
+ """
368
+ Unregister everything (call before quitting).
369
+ :return:
370
+ """
371
+ if self.__m_backend is not None:
372
+ try:
373
+ self.__m_backend.stop()
374
+ except Exception:
375
+ pass
376
+ self.__m_backend = None
377
+
378
+ # ---------- Properties ----------
379
+ enabled = pyqtProperty(bool, fget=isEnabled, fset=setEnabled, notify=enabledChanged) # type: pyqtProperty
@@ -0,0 +1,23 @@
1
+ # coding=utf-8
2
+ """
3
+ Entry point for the GlobalHotkeys demo.
4
+ """
5
+ from os.path import dirname
6
+ from sys import path
7
+
8
+ if not __package__ and dirname(__file__) not in path:
9
+ path.append(dirname(__file__))
10
+
11
+ try:
12
+ from .mainwindow import MainWindow
13
+ except:
14
+ from mainwindow import MainWindow
15
+
16
+ if __name__ == '__main__':
17
+ from ManyQt.QtWidgets import QApplication
18
+ from sys import argv, exit
19
+
20
+ a = QApplication(argv) # type: QApplication
21
+ w = MainWindow() # type: MainWindow
22
+ w.show()
23
+ exit(a.exec_())
@@ -0,0 +1,56 @@
1
+ # coding=utf-8
2
+ """
3
+ Demo window for GlobalHotkeys: press the shortcuts while another application has the focus.
4
+ """
5
+ from ManyQt.QtWidgets import QMainWindow, QVBoxLayout, QWidget, QLabel, QListWidget
6
+ from ManyQt.QtCore import QDateTime, pyqtSlot
7
+ from os.path import dirname
8
+ from sys import path
9
+
10
+ if not __package__ and dirname(__file__) not in path:
11
+ path.append(dirname(__file__))
12
+
13
+ try:
14
+ from .hotkeys import GlobalHotkeys
15
+ except:
16
+ from hotkeys import GlobalHotkeys
17
+
18
+
19
+ class MainWindow(QMainWindow):
20
+ """
21
+ MainWindow class.
22
+ """
23
+
24
+ def __init__(self, *args, **kwargs):
25
+ """
26
+ :param args: any
27
+ :param kwargs: any
28
+ """
29
+ super(MainWindow, self).__init__(*args, **kwargs)
30
+ self.setWindowTitle(self.tr(u'GlobalHotkeys demo'))
31
+ self.resize(520, 360)
32
+ self.__m_hotkeys = GlobalHotkeys(bindings={'hello': 'Ctrl+Alt+H', 'world': 'Ctrl+Alt+F9'},
33
+ activated=self.onActivated, parent=self) # type: GlobalHotkeys
34
+ info = QLabel() # type: QLabel
35
+ lines = ['Backend: {}'.format(self.__m_hotkeys.getBackendName() or 'none')] # type: list
36
+ for name, seq in sorted(self.__m_hotkeys.getBindings().items()):
37
+ lines.append('{} = {} [{}]'.format(name, seq, {True: 'registered', False: 'FAILED'}.get(
38
+ self.__m_hotkeys.getStatus(name), 'inactive')))
39
+ if self.__m_hotkeys.getError():
40
+ lines.append(self.__m_hotkeys.getError())
41
+ info.setText('\n'.join(lines))
42
+ self.__m_log = QListWidget() # type: QListWidget
43
+ wdg = QWidget() # type: QWidget
44
+ layout = QVBoxLayout(wdg) # type: QVBoxLayout
45
+ layout.addWidget(info)
46
+ layout.addWidget(self.__m_log)
47
+ self.setCentralWidget(wdg)
48
+
49
+ @pyqtSlot('QString')
50
+ @pyqtSlot(str)
51
+ def onActivated(self, name):
52
+ """
53
+ :param name: str | unicode | QString
54
+ :return:
55
+ """
56
+ self.__m_log.insertItem(0, '{} {}'.format(QDateTime.currentDateTime().toString('HH:mm:ss.zzz'), name))
@@ -0,0 +1,24 @@
1
+ # coding=utf-8
2
+ """
3
+ imagefilters package: the Qt-free part (core.py) is always available; the Qt class ImageFilters is available when a
4
+ Qt binding is installed (None otherwise).
5
+ """
6
+ from os.path import dirname
7
+ from sys import path
8
+
9
+ if not __package__ and dirname(__file__) not in path:
10
+ path.append(dirname(__file__))
11
+
12
+ try:
13
+ from .core import applyFilters, EFFECT_NAMES
14
+ except:
15
+ from core import applyFilters, EFFECT_NAMES
16
+ try:
17
+ from .imagefilters import ImageFilters
18
+ except:
19
+ try:
20
+ from imagefilters import ImageFilters
21
+ except: # No Qt binding: the Qt-free part only.
22
+ ImageFilters = None
23
+
24
+ __all__ = ['applyFilters', 'EFFECT_NAMES', 'ImageFilters'] # type: list[str]