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.
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,68 @@
1
+ # coding=utf-8
2
+ """
3
+ Screen Magnifier root package: aggregates all components and the application window.
4
+ Components are imported on first use (PEP 562): `from ScreenMagnifier import Upscaler` works as before, and the
5
+ ScreenMagnifier command can explain a missing Qt binding instead of failing while importing the package.
6
+ """
7
+ __version__ = '1.11.0.post8' # Single version source (pyproject.toml reads it; release tags override it).
8
+ STARTUP_ENVIRONMENT = dict(__import__('os').environ) # type: dict # before anything imports OpenCV (see
9
+ # support.cleanEnvironment: a restarted instance gets these values back, not OpenCV's Qt plugin folders).
10
+ from importlib import import_module
11
+ from os.path import dirname
12
+ from sys import path
13
+
14
+ if not __package__ and dirname(__file__) not in path:
15
+ path.append(dirname(__file__))
16
+
17
+ EXPORTS = {
18
+ 'LanguageManager': 'translator',
19
+ 'AdvancedOverlayController': 'advancedoverlay',
20
+ 'AdvancedOverlayPanel': 'advancedpanel',
21
+ 'MagnifierViewWidget': 'magnifierview',
22
+ 'RegionSelector': 'regionselector',
23
+ 'ScreenGrabber': 'screengrabber',
24
+ 'ControlPanel': 'controlpanel',
25
+ 'ZoomOverlay': 'zoomoverlay',
26
+ 'MainWindow': 'mainwindow',
27
+ 'GlobalHotkeys': 'hotkeys',
28
+ 'Upscaler': 'upscaler',
29
+ 'ColorDetector': 'colordetector',
30
+ 'FaceDetector': 'facedetector',
31
+ 'FrameChannel': 'netprotocol',
32
+ 'AnalysisController': 'analysiscontroller',
33
+ 'AnalysisServer': 'analysisserver',
34
+ 'RemoteClient': 'remoteclient',
35
+ 'DetectionPanel': 'detectionpanel',
36
+ 'ServerPanel': 'serverpanel',
37
+ 'ColorPickerPanel': 'colorpanel',
38
+ 'ColorSwatchesWidget': 'colorswatches',
39
+ 'GlobalMouseCatcher': 'mousecatcher',
40
+ 'ShortcutEditorWidget': 'shortcuteditor',
41
+ } # type: dict # exported name -> module of this package
42
+
43
+ __all__ = list(EXPORTS) # type: list[str]
44
+
45
+
46
+ def __getattr__(name):
47
+ """
48
+ :param name: str | unicode | QString
49
+ :return: any
50
+ """
51
+ module = EXPORTS.get(name)
52
+ if module is None:
53
+ raise AttributeError(u'Module {!r} has no attribute {!r}'.format(__name__, name))
54
+ try:
55
+ value = getattr(import_module('.' + module, __name__), name)
56
+ except:
57
+ if __package__:
58
+ raise
59
+ value = getattr(import_module(module), name)
60
+ globals()[name] = value # Cached: later accesses do not come back here.
61
+ return value
62
+
63
+
64
+ def __dir__():
65
+ """
66
+ :return: list[str | unicode | QString]
67
+ """
68
+ return sorted(list(globals()) + __all__)
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ python -m ScreenMagnifier [--tray] [--selftest] [--version]
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 .main import run
13
+ except:
14
+ from main import run
15
+
16
+ if __name__ == '__main__':
17
+ run()
@@ -0,0 +1,593 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ AdvancedOverlayController: connects GlobalHotkeys, ZoomOverlay and a dedicated ScreenGrabber, and persists the
4
+ game-overlay settings with QSettings.
5
+ Default hotkeys (all rebindable):
6
+ Ctrl+Alt+Z show / hide the zoom lens.
7
+ Ctrl+Alt+= zoom in Ctrl+Alt+- zoom out.
8
+ Ctrl+Alt+X pin the target at the mouse position.
9
+ Ctrl+Alt+C cycle the target: screen center -> pinned point -> mouse cursor.
10
+ Ctrl+Alt+K copy the zoomer color code (when "Color code under the crosshair" is on).
11
+ Ctrl+Alt+P screen color picker: a live zoom follows the mouse, click anywhere to copy.
12
+ All hotkeys are defined in shortcuts.py and editable in the Shortcuts tab.
13
+ Scope mode (lens on top of what it magnifies) uses, in order:
14
+ 1. desktop capture with the lens hidden from capture (Windows 10 2004+), verified with a probe;
15
+ 2. direct capture of the game window (PrintWindow), which can never contain the lens;
16
+ 3. otherwise the lens moves to a free screen corner.
17
+ """
18
+ from ManyQt.QtCore import QRect, Qt, QObject, QSize, QPoint, QSettings, QTimer, pyqtSignal, pyqtSlot
19
+ from ManyQt.QtGui import QCursor, QGuiApplication, QImage
20
+ from sys import path, platform
21
+ from os.path import dirname
22
+
23
+ if not __package__ and dirname(__file__) not in path:
24
+ path.append(dirname(__file__))
25
+
26
+ try:
27
+ from .screengrabber import ScreenGrabber, winWindowAt, winGrabWindowRect, isBlankImage
28
+ from .mousecatcher import GlobalMouseCatcher
29
+ from .imagefilters import ImageFilters
30
+ from .shortcuts import HOTKEY_ACTIONS
31
+ from .zoomoverlay import ZoomOverlay
32
+ from .hotkeys import GlobalHotkeys
33
+ except:
34
+ from screengrabber import ScreenGrabber, winWindowAt, winGrabWindowRect, isBlankImage
35
+ from mousecatcher import GlobalMouseCatcher
36
+ from imagefilters import ImageFilters
37
+ from shortcuts import HOTKEY_ACTIONS
38
+ from zoomoverlay import ZoomOverlay
39
+ from hotkeys import GlobalHotkeys
40
+
41
+
42
+ def toBool(value, default=False):
43
+ """
44
+ QSettings returns 'true' / 'false' strings with the INI backend.
45
+ :param value: any
46
+ :param default: bool
47
+ :return: bool
48
+ """
49
+ if value is None:
50
+ return default
51
+ if hasattr(value, 'encode'):
52
+ return value.strip().lower() in ('1', 'true', 'yes', 'on')
53
+ return bool(value)
54
+
55
+
56
+ class AdvancedOverlayController(QObject):
57
+ """
58
+ AdvancedOverlayController class.
59
+ """
60
+ settingsChanged = pyqtSignal() # type: pyqtSignal
61
+ overlayToggled = pyqtSignal(bool) # type: pyqtSignal
62
+ hotkeyTriggered = pyqtSignal('QString') # type: pyqtSignal
63
+ colorPickRequested = pyqtSignal() # type: pyqtSignal # 'copyZoomerColor': copy the zoomer's readoutColor().
64
+ screenPickRequested = pyqtSignal(QPoint) # type: pyqtSignal # picker: copy the screen pixel at this position
65
+ pickerToggled = pyqtSignal(bool) # type: pyqtSignal
66
+ message = pyqtSignal('QString') # type: pyqtSignal
67
+
68
+ def __init__(self, *args, **kwargs):
69
+ """
70
+ :param processor: (callable | None) Upscaler for the lens, f(QImage, QSize) -> QImage.
71
+ :param settings: (QSettings | None) Where to persist; default organisation/application names.
72
+ :param args: any
73
+ :param kwargs: any
74
+ """
75
+ processor = kwargs.pop('processor', None) # type: callable | None
76
+ settings = kwargs.pop('settings', None) # type: QSettings | None
77
+ super(AdvancedOverlayController, self).__init__(*args, **kwargs)
78
+ self.__m_settings = settings if settings is not None else QSettings('ScreenMagnifier', 'GameOverlay')
79
+ s = self.__m_settings # type: QSettings
80
+ self.__m_filters = ImageFilters(effect=int(s.value('filterEffect', 0)),
81
+ brightness=int(s.value('filterBrightness', 0)),
82
+ contrast=int(s.value('filterContrast', 0)),
83
+ saturation=int(s.value('filterSaturation', 0)),
84
+ strength=int(s.value('filterStrength', 100)),
85
+ changed=self._filtersChanged) # type: ImageFilters
86
+ self.__m_upscale = processor # type: callable | None
87
+ self.__m_overlay = ZoomOverlay(
88
+ zoom=float(s.value('zoom', 2.5)),
89
+ lensSize=QSize(int(s.value('lensWidth', 380)), int(s.value('lensHeight', 380))),
90
+ target=int(s.value('target', int(ZoomOverlay.Center))),
91
+ targetPoint=QPoint(int(s.value('targetX', 0)), int(s.value('targetY', 0))),
92
+ placement=int(s.value('placement', int(ZoomOverlay.OnTarget if ZoomOverlay.canExcludeFromCapture()
93
+ else ZoomOverlay.TopRight))),
94
+ shape=int(s.value('shape', int(ZoomOverlay.Circle))),
95
+ cornerRadius=int(s.value('cornerRadius', 45)),
96
+ customRect=QRect(int(s.value('customX', 0)), int(s.value('customY', 0)), int(s.value('customW', 0)),
97
+ int(s.value('customH', 0))),
98
+ fullScreenIndex=int(s.value('fullScreen', -1)),
99
+ showCrosshair=toBool(s.value('crosshair', True), True),
100
+ lensOpacity=float(s.value('opacity', 1.0)),
101
+ processor=self._process, overlayToggled=self._onToggled) # type: ZoomOverlay
102
+ self.__m_grabber = ScreenGrabber(fps=int(s.value('fps', 60)), frameReady=self.__m_overlay.setFrame,
103
+ parent=self) # type: ScreenGrabber
104
+ bindings = {} # type: dict
105
+ old = self.__m_settings.value('hotkeys/copyColor', None) # Earlier versions: one hotkey for both actions.
106
+ if old is not None:
107
+ if self.__m_settings.value('hotkeys/screenPicker', None) is None:
108
+ self.__m_settings.setValue('hotkeys/screenPicker', old)
109
+ self.__m_settings.remove('hotkeys/copyColor')
110
+ for name, title, default in HOTKEY_ACTIONS:
111
+ seq = s.value('hotkeys/' + name, default) # type: str
112
+ if seq:
113
+ bindings[name] = u'{}'.format(seq)
114
+ self.__m_hotkeys = GlobalHotkeys(bindings=bindings, enabled=toBool(s.value('hotkeysEnabled', True), True),
115
+ activated=self.onHotkey, parent=self) # type: GlobalHotkeys
116
+ self.__m_overlay.sourceChanged.connect(self._syncCapture)
117
+ self.__m_tryingWindow = False # type: bool
118
+ self.__m_overlay.captureStatusChanged.connect(self._onCaptureStatus)
119
+ self.__m_overlay.zoomChanged.connect(
120
+ lambda z: None if self.__m_pickState is not None else self._save('zoom', z))
121
+ self.__m_overlay.setShowColorReadout(toBool(self.__m_settings.value('colorReadout', False), False)) # opt-in
122
+ self.__m_pickState = None # type: dict | None # Lens settings to restore after the screen color picker.
123
+ self.__m_catcher = GlobalMouseCatcher(clicked=self._onPickerClick, keyPressed=self._onPickerKey,
124
+ wheelTurned=lambda d: self.__m_overlay.setZoom(
125
+ self.__m_overlay.getZoom() * 1.25 ** (d / 120.0)),
126
+ parent=self) # type: GlobalMouseCatcher
127
+
128
+ # ---------- Helpers ----------
129
+ def _save(self, key, value):
130
+ """
131
+ :param key: str | unicode | QString
132
+ :param value: any
133
+ :return:
134
+ """
135
+ self.__m_settings.setValue(key, value)
136
+ self.settingsChanged.emit()
137
+
138
+ def _onToggled(self, shown):
139
+ """
140
+ :param shown: bool
141
+ :return:
142
+ """
143
+ self._syncCapture()
144
+ self.overlayToggled.emit(bool(shown))
145
+ if shown and self.__m_overlay.getPlacement() == ZoomOverlay.FullScreen: # it covers everything
146
+ self._tell(self.tr(u'Full-screen zoom: press {} to hide it.').format(self.getHotkey('toggle') or '-'))
147
+
148
+ def _syncCapture(self):
149
+ """
150
+ Point the grabber at what the lens shows; run it only while the lens is visible.
151
+ :return: None
152
+ """
153
+ ov = self.__m_overlay # type: ZoomOverlay
154
+ if not ov.isVisible():
155
+ self.__m_grabber.stop()
156
+ return
157
+ src = ov.sourceRect()
158
+ if ov.getTarget() == ZoomOverlay.Cursor:
159
+ pos = QCursor.pos() # type: QPoint
160
+ sc = QGuiApplication.screenAt(pos) if hasattr(QGuiApplication, 'screenAt') else None
161
+ dpr = float((sc or QGuiApplication.primaryScreen()).devicePixelRatio()) # type: float
162
+ self.__m_grabber.setFollowSize(QSize(int(src.width() * dpr), int(src.height() * dpr)))
163
+ self.__m_grabber.setFollowCursor(True)
164
+ else:
165
+ self.__m_grabber.setFollowCursor(False)
166
+ self.__m_grabber.setRegion(src)
167
+ self.__m_grabber.start()
168
+
169
+ @pyqtSlot('QString')
170
+ @pyqtSlot(str)
171
+ def _onCaptureStatus(self, status):
172
+ """
173
+ Pick the capture engine for the lens' current status; try window capture when hiding the lens failed.
174
+ :param status: str | unicode | QString
175
+ :return:
176
+ """
177
+ ov = self.__m_overlay # type: ZoomOverlay
178
+ self.__m_grabber.setCaptureFunction(self._windowCapture if status == 'windowCapture' else None)
179
+ if status in ('failed', 'otherScreen') and platform == 'win32' and not ov.isExternalSource() and \
180
+ ov.getPlacement() in (ZoomOverlay.OnTarget, ZoomOverlay.Custom, ZoomOverlay.FullScreen) and \
181
+ not self.__m_tryingWindow: # Capturing the game window keeps the lens where it was asked.
182
+ self.__m_tryingWindow = True # type: bool
183
+ try:
184
+ self._tryWindowCapture()
185
+ finally:
186
+ self.__m_tryingWindow = False # type: bool
187
+
188
+ def _tryWindowCapture(self):
189
+ """
190
+ Scope mode without hiding the lens: capture the game window itself (the lens floats above it).
191
+ :return: None
192
+ """
193
+ ov = self.__m_overlay # type: ZoomOverlay
194
+ hwnd = winWindowAt(ov.targetPos())
195
+ if not hwnd:
196
+ ov.appendCaptureDetail(u'Window capture: no application window under the target')
197
+ return
198
+ try:
199
+ img, dpr = winGrabWindowRect(hwnd, ov.sourceRect())
200
+ except Exception as e:
201
+ ov.appendCaptureDetail(u'Window capture failed: {}'.format(e))
202
+ return
203
+ if isBlankImage(img):
204
+ ov.appendCaptureDetail(u'Window capture of the game returned a black image')
205
+ return
206
+ ov.setExternalSource(True) # -> status 'windowCapture' -> _windowCapture becomes the grabber.
207
+
208
+ @staticmethod
209
+ def _windowCapture(rect, background):
210
+ """
211
+ ScreenGrabber capture function: the application window under the rect center, looked up every frame
212
+ so that Alt+Tab to another game keeps working.
213
+ :param rect: QRect
214
+ :param background: QColor
215
+ :return: tuple[QImage, float | int]
216
+ """
217
+ hwnd = winWindowAt(rect.center())
218
+ if hwnd:
219
+ img, dpr = winGrabWindowRect(hwnd, rect, background)
220
+ if not img.isNull():
221
+ return img, dpr
222
+ img = QImage(max(1, rect.width()), max(1, rect.height()), QImage.Format_RGB32) # type: QImage
223
+ img.fill(background)
224
+ return img, 1.0
225
+
226
+ def getCaptureEngine(self):
227
+ """
228
+ :return: (str | unicode | QString)'desktop' or 'window'.
229
+ """
230
+ return 'window' if self.__m_grabber.getCaptureFunction() is not None else 'desktop'
231
+
232
+ # ---------- Public API ----------
233
+ def _process(self, image, size):
234
+ """
235
+ The lens processor: filters on the small captured frame (cheap), then the upscaler.
236
+ :param image: QImage
237
+ :param size: QSize
238
+ :return: QImage
239
+ """
240
+ image = self.__m_filters.apply(image) # type: QImage
241
+ return self.__m_upscale(image, size) if self.__m_upscale else image.scaled(
242
+ size, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
243
+
244
+ @pyqtSlot()
245
+ def _filtersChanged(self):
246
+ """
247
+ :return:
248
+ """
249
+ f = self.__m_filters # type: ImageFilters
250
+ for key, value in (('filterEffect', f.getEffect()), ('filterBrightness', f.getBrightness()),
251
+ ('filterContrast', f.getContrast()), ('filterSaturation', f.getSaturation()),
252
+ ('filterStrength', f.getStrength())):
253
+ self._save(key, value)
254
+ if hasattr(self, '_AdvancedOverlayController__m_overlay'):
255
+ self.__m_overlay.refresh()
256
+
257
+ def getFilters(self):
258
+ """
259
+ :return: (ImageFilters) The zoomer's color filters.
260
+ """
261
+ return self.__m_filters
262
+
263
+ def getOverlay(self):
264
+ """
265
+ :return: ZoomOverlay
266
+ """
267
+ return self.__m_overlay
268
+
269
+ def getGrabber(self):
270
+ """
271
+ :return: ScreenGrabber
272
+ """
273
+ return self.__m_grabber
274
+
275
+ def getHotkeys(self):
276
+ """
277
+ :return: GlobalHotkeys
278
+ """
279
+ return self.__m_hotkeys
280
+
281
+ @pyqtSlot('QString')
282
+ @pyqtSlot(str)
283
+ def onHotkey(self, name):
284
+ """
285
+ :param name: str | unicode | QString
286
+ :return:
287
+ """
288
+ ov = self.__m_overlay # type: ZoomOverlay
289
+ if name == 'toggle':
290
+ if self.__m_pickState is not None:
291
+ self.stopColorPicker() # Hiding the lens while picking cancels the picker (and frees the mouse).
292
+ else:
293
+ ov.toggle()
294
+ elif name == 'zoomIn':
295
+ ov.zoomIn()
296
+ elif name == 'zoomOut':
297
+ ov.zoomOut()
298
+ elif name == 'pinTarget':
299
+ self.pinTarget(QCursor.pos())
300
+ elif name == 'cycleTarget':
301
+ self.setTarget((int(ov.getTarget()) + 1) % 3)
302
+ elif name == 'screenPicker': # One meaning: the screen color picker (start, or copy while it runs).
303
+ if self.__m_pickState is not None:
304
+ self.screenPickRequested.emit(QCursor.pos())
305
+ else:
306
+ self.startColorPicker()
307
+ elif name == 'copyZoomerColor': # One meaning: copy the zoomer's color code (only when it is shown).
308
+ if self.__m_pickState is not None:
309
+ self.screenPickRequested.emit(QCursor.pos())
310
+ elif not ov.isVisible():
311
+ self._tell(self.tr(u'The zoomer is hidden: show it with {}, or use the screen color picker ({}).')
312
+ .format(self.getHotkey('toggle') or '-', self.getHotkey('screenPicker') or '-'))
313
+ elif not ov.isShowColorReadout():
314
+ self._tell(self.tr(u'The zoomer color code is off: turn on "Color code under the crosshair" in the '
315
+ 'Zoomer tab.'))
316
+ else:
317
+ self.colorPickRequested.emit()
318
+ elif name == 'pickerCancel':
319
+ self.stopColorPicker()
320
+ self.hotkeyTriggered.emit(name)
321
+
322
+ @pyqtSlot()
323
+ def toggle(self):
324
+ """
325
+ :return:
326
+ """
327
+ if self.__m_pickState is not None:
328
+ self.stopColorPicker()
329
+ else:
330
+ self.__m_overlay.toggle()
331
+
332
+ @pyqtSlot(QPoint)
333
+ def pinTarget(self, point):
334
+ """
335
+ :param point: (QPoint) Global position.
336
+ :return:
337
+ """
338
+ self.__m_overlay.setTargetPoint(point)
339
+ self._save('targetX', point.x())
340
+ self._save('targetY', point.y())
341
+ self.setTarget(ZoomOverlay.Point)
342
+
343
+ @pyqtSlot(int)
344
+ def setTarget(self, target):
345
+ """
346
+ :param target: ZoomOverlay.Target | int
347
+ :return:
348
+ """
349
+ self.__m_overlay.setTarget(target)
350
+ self._save('target', int(target))
351
+
352
+ @pyqtSlot(int)
353
+ def setPlacement(self, placement):
354
+ """
355
+ :param placement: ZoomOverlay.Placement | int
356
+ :return:
357
+ """
358
+ self.__m_overlay.setPlacement(placement)
359
+ self._save('placement', int(placement))
360
+
361
+ @pyqtSlot(QRect)
362
+ def setCustomRect(self, rect):
363
+ """
364
+ :param rect: (QRect) Lens rect of the Custom placement (global, device-independent px).
365
+ :return:
366
+ """
367
+ self.__m_overlay.setCustomRect(rect)
368
+ r = self.__m_overlay.getCustomRect() # type: QRect
369
+ for key, value in (('customX', r.x()), ('customY', r.y()), ('customW', r.width()), ('customH', r.height())):
370
+ self._save(key, value)
371
+
372
+ @pyqtSlot(int)
373
+ def setFullScreenIndex(self, index):
374
+ """
375
+ :param index: (int) Screen of the FullScreen placement, -1 = the screen of the target.
376
+ :return:
377
+ """
378
+ self.__m_overlay.setFullScreenIndex(index)
379
+ self._save('fullScreen', int(index))
380
+
381
+ @pyqtSlot(int)
382
+ def setCornerRadius(self, radius):
383
+ """
384
+ :param radius: (int) Corner radius of the rounded-square lens in px.
385
+ :return:
386
+ """
387
+ self.__m_overlay.setCornerRadius(radius)
388
+ self._save('cornerRadius', int(radius))
389
+
390
+ @pyqtSlot(int)
391
+ def setShape(self, shape):
392
+ """
393
+ :param shape: ZoomOverlay.Shape | int
394
+ :return:
395
+ """
396
+ self.__m_overlay.setShape(shape)
397
+ self._save('shape', int(shape))
398
+
399
+ @pyqtSlot(int)
400
+ def setLensSize(self, size):
401
+ """
402
+ :param size: (int) Square lens edge in px.
403
+ :return:
404
+ """
405
+ self.__m_overlay.setLensSize(QSize(int(size), int(size)))
406
+ self._save('lensWidth', int(size))
407
+ self._save('lensHeight', int(size))
408
+
409
+ @pyqtSlot(float)
410
+ @pyqtSlot(int)
411
+ def setZoom(self, zoom):
412
+ """
413
+ :param zoom: float | int
414
+ :return:
415
+ """
416
+ self.__m_overlay.setZoom(zoom)
417
+
418
+ @pyqtSlot(int)
419
+ def setFps(self, fps):
420
+ """
421
+ :param fps: int
422
+ :return:
423
+ """
424
+ self.__m_grabber.setFps(fps)
425
+ self._save('fps', int(fps))
426
+
427
+ @pyqtSlot(bool)
428
+ @pyqtSlot(int)
429
+ def setCrosshair(self, on):
430
+ """
431
+ :param on: bool
432
+ :return:
433
+ """
434
+ self.__m_overlay.setShowCrosshair(bool(on))
435
+ self._save('crosshair', bool(on))
436
+
437
+ @pyqtSlot(float)
438
+ @pyqtSlot(int)
439
+ def setOpacity(self, opacity):
440
+ """
441
+ :param opacity: float | int
442
+ :return:
443
+ """
444
+ self.__m_overlay.setLensOpacity(opacity)
445
+ self._save('opacity', float(opacity))
446
+
447
+ @pyqtSlot(bool)
448
+ @pyqtSlot(int)
449
+ def setHotkeysEnabled(self, enabled):
450
+ """
451
+ :param enabled: bool
452
+ :return:
453
+ """
454
+ self.__m_hotkeys.setEnabled(bool(enabled))
455
+ self._save('hotkeysEnabled', bool(enabled))
456
+
457
+ def isHotkeysEnabled(self):
458
+ """
459
+ :return: (bool) The saved preference (hotkeys may be suspended temporarily while recording one).
460
+ """
461
+ return toBool(self.__m_settings.value('hotkeysEnabled', True), True)
462
+
463
+ def setHotkey(self, name, sequence):
464
+ """
465
+ :param name: str | unicode | QString
466
+ :param sequence: (str | unicode | QString)Qt portable text, '' to unbind.
467
+ :return:
468
+ """
469
+ self.__m_hotkeys.setBinding(name, sequence)
470
+ self._save('hotkeys/' + name, sequence)
471
+
472
+ def getHotkey(self, name):
473
+ """
474
+ :param name: str | unicode | QString
475
+ :return: str | unicode | QString
476
+ """
477
+ return self.__m_hotkeys.getBindings().get(name, '')
478
+
479
+ def _tell(self, text):
480
+ """
481
+ Explain why a hotkey did nothing - after the generic "hotkey pressed" notice, so it is the one shown.
482
+ :param text: str | unicode | QString
483
+ :return:
484
+ """
485
+ QTimer.singleShot(0, lambda: self.message.emit(text))
486
+
487
+ # ---------- Screen color picker ----------
488
+ def isColorPicking(self):
489
+ """
490
+ :return: bool
491
+ """
492
+ return self.__m_pickState is not None
493
+
494
+ @pyqtSlot()
495
+ def startColorPicker(self):
496
+ """
497
+ Screen color picker: a pixel-exact lens follows the mouse anywhere on the screen with the live color of
498
+ the pixel under the crosshair; left click (anywhere) or the hotkey copies, right click / Esc cancels,
499
+ wheel zooms, arrows move 1 px (Linux).
500
+ :return: None
501
+ """
502
+ if self.__m_pickState is not None:
503
+ return
504
+ ov = self.__m_overlay # type: ZoomOverlay
505
+ self.__m_pickState = {'visible': ov.isVisible(), 'target': ov.getTarget(), 'placement': ov.getPlacement(),
506
+ 'zoom': ov.getZoom(), 'lensSize': ov.getLensSize(), 'pixelated': ov.isPixelated(),
507
+ 'readout': ov.isShowColorReadout(), 'fps': self.__m_grabber.getFps()} # type: dict
508
+ ov.hideOverlay()
509
+ ov.setTarget(ZoomOverlay.Cursor)
510
+ ov.setPlacement(ZoomOverlay.NearTarget)
511
+ ov.setZoom(10.0)
512
+ ov.setLensSize(QSize(180, 180))
513
+ ov.setPixelated(True)
514
+ ov.setShowColorReadout(True)
515
+ self.__m_grabber.setFps(60)
516
+ ov.showOverlay()
517
+ if not self.__m_catcher.start():
518
+ self.message.emit(self.__m_catcher.getError() + ' - press {} again to copy.'.format(
519
+ self.getHotkey('screenPicker') or 'the hotkey'))
520
+ if self.__m_catcher.getBackendName() != 'qtgrab': # Esc while another application has the keyboard.
521
+ self.__m_hotkeys.setBinding('pickerCancel', 'Esc')
522
+ self.pickerToggled.emit(True)
523
+
524
+ @pyqtSlot()
525
+ def stopColorPicker(self, delayMs=0):
526
+ """
527
+ :param delayMs: (int) Keep the lens visible this long (e.g. to show the "copied" message).
528
+ :return: None
529
+ """
530
+ if self.__m_pickState is None:
531
+ return
532
+ self.__m_catcher.stop()
533
+ if 'pickerCancel' in self.__m_hotkeys.getBindings():
534
+ self.__m_hotkeys.setBinding('pickerCancel', '')
535
+ if delayMs > 0:
536
+ QTimer.singleShot(int(delayMs), self.stopColorPicker)
537
+ self.__m_pickState['delayed'] = True
538
+ return
539
+ state, self.__m_pickState = self.__m_pickState, None
540
+ ov = self.__m_overlay # type: ZoomOverlay
541
+ ov.hideOverlay()
542
+ ov.setTarget(state['target'])
543
+ ov.setPlacement(state['placement'])
544
+ ov.setZoom(state['zoom'])
545
+ ov.setLensSize(state['lensSize'])
546
+ ov.setPixelated(state['pixelated'])
547
+ ov.setShowColorReadout(state['readout'])
548
+ self.__m_grabber.setFps(state['fps'])
549
+ if state['visible']:
550
+ ov.showOverlay()
551
+ self.pickerToggled.emit(False)
552
+
553
+ def _onPickerClick(self, pos, button):
554
+ """
555
+ :param pos: QPoint
556
+ :param button: int
557
+ :return:
558
+ """
559
+ self.screenPickRequested.emit(pos) if button == 1 else self.stopColorPicker()
560
+
561
+ def _onPickerKey(self, key):
562
+ """
563
+ :param key: (int) Qt key (keyboard grabbed by the qtgrab backend).
564
+ :return:
565
+ """
566
+ steps = {int(Qt.Key_Left): (-1, 0), int(Qt.Key_Right): (1, 0), int(Qt.Key_Up): (0, -1),
567
+ int(Qt.Key_Down): (0, 1)} # type: dict
568
+ if key == int(Qt.Key_Escape):
569
+ self.stopColorPicker()
570
+ elif key in (int(Qt.Key_Return), int(Qt.Key_Enter), int(Qt.Key_Space)):
571
+ self.screenPickRequested.emit(QCursor.pos())
572
+ elif key in steps:
573
+ QCursor.setPos(QCursor.pos() + QPoint(*steps[key]))
574
+
575
+ def setColorReadout(self, on):
576
+ """
577
+ :param on: (bool) Live color code of the crosshair pixel in the lens (saved).
578
+ :return:
579
+ """
580
+ self.__m_overlay.setShowColorReadout(on)
581
+ self._save('colorReadout', bool(on))
582
+
583
+ @pyqtSlot()
584
+ def shutdown(self):
585
+ """
586
+ :return:
587
+ """
588
+ self.__m_catcher.stop()
589
+ self.__m_overlay.hideOverlay()
590
+ self.__m_grabber.stop()
591
+ self.__m_hotkeys.shutdown()
592
+ self.__m_overlay.close()
593
+ self.__m_settings.sync()