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.
- ScreenMagnifier/__init__.py +68 -0
- ScreenMagnifier/__main__.py +17 -0
- ScreenMagnifier/advancedoverlay.py +593 -0
- ScreenMagnifier/advancedpanel.py +521 -0
- ScreenMagnifier/analysiscontroller.py +533 -0
- ScreenMagnifier/analysisserver.py +404 -0
- ScreenMagnifier/colordetector/__init__.py +28 -0
- ScreenMagnifier/colordetector/colordetector.py +570 -0
- ScreenMagnifier/colordetector/core.py +434 -0
- ScreenMagnifier/colordetector/main.py +23 -0
- ScreenMagnifier/colordetector/mainwindow.py +182 -0
- ScreenMagnifier/colorpanel.py +424 -0
- ScreenMagnifier/colorswatches/__init__.py +16 -0
- ScreenMagnifier/colorswatches/colorswatches.py +316 -0
- ScreenMagnifier/colorswatches/main.py +23 -0
- ScreenMagnifier/colorswatches/mainwindow.py +60 -0
- ScreenMagnifier/controlpanel.py +234 -0
- ScreenMagnifier/detectionpanel.py +790 -0
- ScreenMagnifier/facedetector/__init__.py +24 -0
- ScreenMagnifier/facedetector/core.py +314 -0
- ScreenMagnifier/facedetector/facedetector.py +288 -0
- ScreenMagnifier/facedetector/main.py +23 -0
- ScreenMagnifier/facedetector/mainwindow.py +122 -0
- ScreenMagnifier/facedetector/models/__init__.py +4 -0
- ScreenMagnifier/facepointer.py +1121 -0
- ScreenMagnifier/features.py +50 -0
- ScreenMagnifier/hotkeys/__init__.py +16 -0
- ScreenMagnifier/hotkeys/hotkeys.py +379 -0
- ScreenMagnifier/hotkeys/main.py +23 -0
- ScreenMagnifier/hotkeys/mainwindow.py +56 -0
- ScreenMagnifier/imagefilters/__init__.py +24 -0
- ScreenMagnifier/imagefilters/core.py +172 -0
- ScreenMagnifier/imagefilters/imagefilters.py +220 -0
- ScreenMagnifier/imagefilters/main.py +23 -0
- ScreenMagnifier/imagefilters/mainwindow.py +120 -0
- ScreenMagnifier/magnifierview/__init__.py +16 -0
- ScreenMagnifier/magnifierview/magnifierview.py +1249 -0
- ScreenMagnifier/magnifierview/main.py +23 -0
- ScreenMagnifier/magnifierview/mainwindow.py +91 -0
- ScreenMagnifier/main.py +157 -0
- ScreenMagnifier/mainwindow.py +1368 -0
- ScreenMagnifier/mousecatcher/__init__.py +16 -0
- ScreenMagnifier/mousecatcher/main.py +23 -0
- ScreenMagnifier/mousecatcher/mainwindow.py +78 -0
- ScreenMagnifier/mousecatcher/mousecatcher.py +251 -0
- ScreenMagnifier/mousemove.py +259 -0
- ScreenMagnifier/netprotocol/__init__.py +25 -0
- ScreenMagnifier/netprotocol/main.py +23 -0
- ScreenMagnifier/netprotocol/mainwindow.py +91 -0
- ScreenMagnifier/netprotocol/netprotocol.py +372 -0
- ScreenMagnifier/netprotocol/wire.py +189 -0
- ScreenMagnifier/regionselector/__init__.py +16 -0
- ScreenMagnifier/regionselector/main.py +23 -0
- ScreenMagnifier/regionselector/mainwindow.py +70 -0
- ScreenMagnifier/regionselector/regionselector.py +549 -0
- ScreenMagnifier/remoteclient.py +636 -0
- ScreenMagnifier/resources/icon-128.png +0 -0
- ScreenMagnifier/resources/icon-16.png +0 -0
- ScreenMagnifier/resources/icon-24.png +0 -0
- ScreenMagnifier/resources/icon-256.png +0 -0
- ScreenMagnifier/resources/icon-32.png +0 -0
- ScreenMagnifier/resources/icon-48.png +0 -0
- ScreenMagnifier/resources/icon-512.png +0 -0
- ScreenMagnifier/resources/icon-64.png +0 -0
- ScreenMagnifier/resources/icon.icns +0 -0
- ScreenMagnifier/resources/icon.ico +0 -0
- ScreenMagnifier/screengrabber/__init__.py +16 -0
- ScreenMagnifier/screengrabber/main.py +23 -0
- ScreenMagnifier/screengrabber/mainwindow.py +79 -0
- ScreenMagnifier/screengrabber/screengrabber.py +558 -0
- ScreenMagnifier/server.py +150 -0
- ScreenMagnifier/serverpanel.py +379 -0
- ScreenMagnifier/shortcuteditor/__init__.py +16 -0
- ScreenMagnifier/shortcuteditor/main.py +23 -0
- ScreenMagnifier/shortcuteditor/mainwindow.py +54 -0
- ScreenMagnifier/shortcuteditor/shortcuteditor.py +411 -0
- ScreenMagnifier/shortcuts.py +118 -0
- ScreenMagnifier/shortcutspanel.py +140 -0
- ScreenMagnifier/support.py +127 -0
- ScreenMagnifier/translations/ar.json +387 -0
- ScreenMagnifier/translations/de.json +387 -0
- ScreenMagnifier/translations/es.json +387 -0
- ScreenMagnifier/translations/fr.json +387 -0
- ScreenMagnifier/translations/it.json +387 -0
- ScreenMagnifier/translations/ja.json +387 -0
- ScreenMagnifier/translations/ko.json +387 -0
- ScreenMagnifier/translations/pt_BR.json +387 -0
- ScreenMagnifier/translations/ru.json +387 -0
- ScreenMagnifier/translations/tr.json +387 -0
- ScreenMagnifier/translations/zh_CN.json +387 -0
- ScreenMagnifier/translator/__init__.py +16 -0
- ScreenMagnifier/translator/main.py +23 -0
- ScreenMagnifier/translator/mainwindow.py +62 -0
- ScreenMagnifier/translator/translator.py +284 -0
- ScreenMagnifier/upscaler/__init__.py +24 -0
- ScreenMagnifier/upscaler/core.py +315 -0
- ScreenMagnifier/upscaler/main.py +23 -0
- ScreenMagnifier/upscaler/mainwindow.py +128 -0
- ScreenMagnifier/upscaler/models/FSRCNN-small_x2.pb +0 -0
- ScreenMagnifier/upscaler/models/FSRCNN-small_x3.pb +0 -0
- ScreenMagnifier/upscaler/models/FSRCNN-small_x4.pb +0 -0
- ScreenMagnifier/upscaler/models/FSRCNN_x2.pb +0 -0
- ScreenMagnifier/upscaler/models/FSRCNN_x3.pb +0 -0
- ScreenMagnifier/upscaler/models/FSRCNN_x4.pb +0 -0
- ScreenMagnifier/upscaler/models/LICENSE-FSRCNN +201 -0
- ScreenMagnifier/upscaler/models/__init__.py +4 -0
- ScreenMagnifier/upscaler/upscaler.py +285 -0
- ScreenMagnifier/wincheck.py +65 -0
- ScreenMagnifier/zoomoverlay/__init__.py +16 -0
- ScreenMagnifier/zoomoverlay/main.py +23 -0
- ScreenMagnifier/zoomoverlay/mainwindow.py +99 -0
- ScreenMagnifier/zoomoverlay/zoomoverlay.py +1779 -0
- screenmagnifier-1.11.0.post8.dist-info/METADATA +591 -0
- screenmagnifier-1.11.0.post8.dist-info/RECORD +117 -0
- screenmagnifier-1.11.0.post8.dist-info/WHEEL +5 -0
- screenmagnifier-1.11.0.post8.dist-info/entry_points.txt +5 -0
- screenmagnifier-1.11.0.post8.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,790 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
DetectionPanel: the Detection tab - color detection, palette and the optional AI face detection (color codes,
|
|
4
|
+
copying and contrast are in the Colors tab). Bound to an AnalysisController; every setting is saved with QSettings.
|
|
5
|
+
"""
|
|
6
|
+
from ManyQt.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QSlider, QComboBox, QFrame, \
|
|
7
|
+
QCheckBox, QPushButton, QScrollArea, QListWidget, QListWidgetItem, QColorDialog
|
|
8
|
+
from ManyQt.QtCore import Qt, QPoint, QRectF, QSettings, QSize, pyqtSignal, pyqtSlot, pyqtProperty
|
|
9
|
+
from ManyQt.QtGui import QColor, QPainter, QPixmap, QIcon
|
|
10
|
+
from os.path import dirname
|
|
11
|
+
from sys import path
|
|
12
|
+
|
|
13
|
+
if not __package__ and dirname(__file__) not in path:
|
|
14
|
+
path.append(dirname(__file__))
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
from .facepointer import FacePointer, FOLLOW_POINTER, FOLLOW_ZOOMER, CHOOSE_LARGEST, CHOOSE_NEAREST, \
|
|
18
|
+
MOTION_POINTER, MOTION_VIEW, MOTION_AUTO, HOLD_ALWAYS, HOLD_RIGHT_BUTTON
|
|
19
|
+
from .colordetector import ColorDetector, nearestColorName
|
|
20
|
+
from .analysiscontroller import AnalysisController
|
|
21
|
+
from .facedetector import FaceDetector
|
|
22
|
+
except:
|
|
23
|
+
from facepointer import FacePointer, FOLLOW_POINTER, FOLLOW_ZOOMER, CHOOSE_LARGEST, CHOOSE_NEAREST, \
|
|
24
|
+
MOTION_POINTER, MOTION_VIEW, MOTION_AUTO, HOLD_ALWAYS, HOLD_RIGHT_BUTTON
|
|
25
|
+
from colordetector import ColorDetector, nearestColorName
|
|
26
|
+
from analysiscontroller import AnalysisController
|
|
27
|
+
from facedetector import FaceDetector
|
|
28
|
+
|
|
29
|
+
PANEL_QSS = """
|
|
30
|
+
QWidget#detectionContent { background: transparent; }
|
|
31
|
+
QLabel[role="title"] { color: #9AA3B8; font-size: 10px; font-weight: bold; letter-spacing: 1px; padding-top: 10px; }
|
|
32
|
+
QLabel[role="value"] { color: #E8EBF2; font-weight: bold; }
|
|
33
|
+
QLabel[role="hint"] { color: #7C8498; font-size: 10px; }
|
|
34
|
+
QLabel[role="mono"] { color: #E8EBF2; font-family: monospace; }
|
|
35
|
+
QListWidget { background: #22252E; color: #E8EBF2; border: 1px solid #3A3F50; border-radius: 6px; }
|
|
36
|
+
QPushButton[role="small"] { padding: 3px 6px; }
|
|
37
|
+
""" # type: str
|
|
38
|
+
FACE_MODES = [('box', 'Boxes'), ('landmarks', 'Boxes + landmarks'), ('blur', 'Privacy blur')] # type: list
|
|
39
|
+
FACE_BACKENDS = [('auto', 'Auto (YuNet if installed)'), ('yunet', 'YuNet (DNN, accurate)'),
|
|
40
|
+
('haar', 'Haar cascade (no download)')] # type: list
|
|
41
|
+
MATCH_MODES = [(0, 'Similar shades (lighting, shadows, anti-aliasing)'), (1, 'Exact color')] # type: list
|
|
42
|
+
ENGINE_VERSION = 2 # type: int # 2: tolerance = hue degrees in Similar mode (was delta E): saved values reset.
|
|
43
|
+
MASK_MODES = [('isolate', 'Isolate matches (dim the rest)'), ('tint', 'Tint matches')] # type: list
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def swatch(color, size=14):
|
|
47
|
+
"""
|
|
48
|
+
:param color: QColor | str
|
|
49
|
+
:param size: int
|
|
50
|
+
:return: QIcon
|
|
51
|
+
"""
|
|
52
|
+
pm = QPixmap(size, size) # type: QPixmap
|
|
53
|
+
pm.fill(Qt.transparent)
|
|
54
|
+
p = QPainter(pm) # type: QPainter
|
|
55
|
+
p.setRenderHint(QPainter.Antialiasing, True)
|
|
56
|
+
p.setPen(QColor(255, 255, 255, 120))
|
|
57
|
+
p.setBrush(QColor(color))
|
|
58
|
+
p.drawRoundedRect(QRectF(0.5, 0.5, size - 1, size - 1), 3, 3)
|
|
59
|
+
p.end()
|
|
60
|
+
return QIcon(pm)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
POINTER_FOLLOW = [(FOLLOW_POINTER, 'The mouse pointer'),
|
|
64
|
+
(FOLLOW_ZOOMER, 'Only the zoomer (the pointer stays still)')] # type: list[tuple[int, str]]
|
|
65
|
+
POINTER_CHOOSE = [(CHOOSE_LARGEST, 'The largest face'), (CHOOSE_NEAREST, 'The face nearest the pointer')] # type: list
|
|
66
|
+
POINTER_MOTION = [(MOTION_AUTO, 'Automatic (turn the view when the game captures the mouse)'),
|
|
67
|
+
(MOTION_POINTER, 'Move the pointer to the face (films, games with a pointer)'),
|
|
68
|
+
(MOTION_VIEW, 'Turn the view to the face (games that capture the mouse)')] # type: list
|
|
69
|
+
POINTER_HOLD = [(HOLD_ALWAYS, 'Always'), (HOLD_RIGHT_BUTTON, 'While the right mouse button is held')] # type: list
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class PaletteBar(QWidget):
|
|
73
|
+
"""
|
|
74
|
+
PaletteBar class: horizontal bar of the dominant colors, each segment as wide as its share.
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
def __init__(self, *args, **kwargs):
|
|
78
|
+
"""
|
|
79
|
+
:param args: any
|
|
80
|
+
:param kwargs: any
|
|
81
|
+
"""
|
|
82
|
+
super(PaletteBar, self).__init__(*args, **kwargs)
|
|
83
|
+
self.__m_palette = [] # type: list
|
|
84
|
+
self.setMinimumHeight(26)
|
|
85
|
+
|
|
86
|
+
@pyqtSlot(list)
|
|
87
|
+
def setColors(self, colors):
|
|
88
|
+
"""
|
|
89
|
+
:param colors: (list[dict]) [{'color': '#RRGGBB', 'fraction': f, 'name': str}]
|
|
90
|
+
:return:
|
|
91
|
+
"""
|
|
92
|
+
self.__m_palette = list(colors or []) # type: list
|
|
93
|
+
self.setToolTip('\n'.join('{} {} {:.1f} %'.format(p['color'], p['name'], 100 * p['fraction'])
|
|
94
|
+
for p in self.__m_palette))
|
|
95
|
+
self.update()
|
|
96
|
+
|
|
97
|
+
def getColors(self):
|
|
98
|
+
"""
|
|
99
|
+
:return: list[dict]
|
|
100
|
+
"""
|
|
101
|
+
return list(self.__m_palette)
|
|
102
|
+
|
|
103
|
+
def sizeHint(self):
|
|
104
|
+
"""
|
|
105
|
+
:return: QSize
|
|
106
|
+
"""
|
|
107
|
+
return QSize(220, 26)
|
|
108
|
+
|
|
109
|
+
def paintEvent(self, event):
|
|
110
|
+
"""
|
|
111
|
+
:param event: QPaintEvent
|
|
112
|
+
:return:
|
|
113
|
+
"""
|
|
114
|
+
p = QPainter(self) # type: QPainter
|
|
115
|
+
p.setRenderHint(QPainter.Antialiasing, True)
|
|
116
|
+
r = QRectF(self.rect()).adjusted(0.5, 0.5, -0.5, -0.5) # type: QRectF
|
|
117
|
+
p.setPen(QColor('#3A3F50'))
|
|
118
|
+
p.setBrush(QColor('#22252E'))
|
|
119
|
+
p.drawRoundedRect(r, 5, 5)
|
|
120
|
+
total = sum(c['fraction'] for c in self.__m_palette) or 1.0 # type: float
|
|
121
|
+
x = r.left() + 1 # type: float
|
|
122
|
+
p.setPen(Qt.NoPen)
|
|
123
|
+
for c in self.__m_palette:
|
|
124
|
+
w = (r.width() - 2) * c['fraction'] / total # type: float
|
|
125
|
+
p.setBrush(QColor(c['color']))
|
|
126
|
+
p.drawRect(QRectF(x, r.top() + 1, w, r.height() - 2))
|
|
127
|
+
x += w
|
|
128
|
+
p.end()
|
|
129
|
+
|
|
130
|
+
# ---------- Properties ----------
|
|
131
|
+
colors = pyqtProperty(list, fget=getColors, fset=setColors) # type: pyqtProperty
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class DetectionPanel(QScrollArea):
|
|
135
|
+
"""
|
|
136
|
+
DetectionPanel class.
|
|
137
|
+
"""
|
|
138
|
+
notify = pyqtSignal('QString') # type: pyqtSignal # Message for the status bar / tray.
|
|
139
|
+
|
|
140
|
+
def __init__(self, *args, **kwargs):
|
|
141
|
+
"""
|
|
142
|
+
:param controller: AnalysisController
|
|
143
|
+
:param settings: (QSettings | None) None = ScreenMagnifier / Detection.
|
|
144
|
+
:param features: (FeatureSettings | None) Where the zones are shown (magnifier / zoomer).
|
|
145
|
+
:param args: any
|
|
146
|
+
:param kwargs: any
|
|
147
|
+
"""
|
|
148
|
+
controller = kwargs.pop('controller', None) # type: AnalysisController
|
|
149
|
+
settings = kwargs.pop('settings', None) # type: QSettings | None
|
|
150
|
+
features = kwargs.pop('features', None) # type: FeatureSettings | None
|
|
151
|
+
facePointer = kwargs.pop('facePointer', None) # type: FacePointer | None
|
|
152
|
+
hotkeyText = kwargs.pop('hotkeyText', None) # type: callable | None
|
|
153
|
+
super(DetectionPanel, self).__init__(*args, **kwargs)
|
|
154
|
+
self.__m_pointer = facePointer # type: FacePointer | None
|
|
155
|
+
self.__m_hotkeyText = hotkeyText if callable(hotkeyText) else (lambda name: '') # type: callable
|
|
156
|
+
self.__m_pointerSettings = QSettings('ScreenMagnifier', 'FacePointer') # type: QSettings
|
|
157
|
+
self.__m_features = features # type: FeatureSettings | None
|
|
158
|
+
self.__m_ctrl = controller # type: AnalysisController
|
|
159
|
+
self.__m_colors = controller.getColorDetector() # type: ColorDetector
|
|
160
|
+
self.__m_faces = controller.getFaceDetector() # type: FaceDetector
|
|
161
|
+
self.__m_settings = settings if settings is not None else QSettings('ScreenMagnifier', 'Detection')
|
|
162
|
+
self.__m_notifyOn = True # type: bool
|
|
163
|
+
self.__m_loading = False # type: bool # No saving while the saved values are being restored.
|
|
164
|
+
self.setWidgetResizable(True)
|
|
165
|
+
self.setFrameShape(QFrame.NoFrame)
|
|
166
|
+
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
167
|
+
self.setMinimumWidth(260)
|
|
168
|
+
content = QWidget() # type: QWidget
|
|
169
|
+
content.setObjectName('detectionContent')
|
|
170
|
+
content.setStyleSheet(PANEL_QSS)
|
|
171
|
+
self.__m_layout = QVBoxLayout(content) # type: QVBoxLayout
|
|
172
|
+
self.__m_layout.setContentsMargins(14, 6, 14, 14)
|
|
173
|
+
self.__m_layout.setSpacing(6)
|
|
174
|
+
self._buildColors()
|
|
175
|
+
self._buildFaces()
|
|
176
|
+
if facePointer is not None:
|
|
177
|
+
self._buildFacePointer()
|
|
178
|
+
self._buildAnalysis()
|
|
179
|
+
self.__m_layout.addStretch(1)
|
|
180
|
+
self.setWidget(content)
|
|
181
|
+
self._load()
|
|
182
|
+
self._syncWhere()
|
|
183
|
+
if features is not None:
|
|
184
|
+
features.changed.connect(self._syncWhere)
|
|
185
|
+
controller.resultsReady.connect(self._onResults)
|
|
186
|
+
controller.colorAppeared.connect(self._onAppeared)
|
|
187
|
+
self.__m_colors.targetsChanged.connect(self._refreshTargets)
|
|
188
|
+
self.__m_faces.downloadProgress.connect(lambda v: self.__m_modelState.setText(
|
|
189
|
+
self.tr(u'Downloading YuNet model... {} %').format(v)))
|
|
190
|
+
self.__m_faces.downloadFinished.connect(self._onDownloaded)
|
|
191
|
+
self.__m_faces.errorOccurred.connect(self.notify.emit)
|
|
192
|
+
self._refreshTargets()
|
|
193
|
+
self._refreshModelState()
|
|
194
|
+
|
|
195
|
+
# ---------- Building ----------
|
|
196
|
+
@staticmethod
|
|
197
|
+
def _label(text, role):
|
|
198
|
+
"""
|
|
199
|
+
:param text: str | unicode | QString
|
|
200
|
+
:param role: str | unicode | QString
|
|
201
|
+
:return: QLabel
|
|
202
|
+
"""
|
|
203
|
+
lbl = QLabel(text) # type: QLabel
|
|
204
|
+
lbl.setProperty('role', role)
|
|
205
|
+
lbl.setWordWrap(role == 'hint')
|
|
206
|
+
return lbl
|
|
207
|
+
|
|
208
|
+
def _title(self, text, value=None):
|
|
209
|
+
"""
|
|
210
|
+
:param text: str | unicode | QString
|
|
211
|
+
:param value: QLabel | None
|
|
212
|
+
:return:
|
|
213
|
+
"""
|
|
214
|
+
row = QHBoxLayout() # type: QHBoxLayout
|
|
215
|
+
row.addWidget(DetectionPanel._label(text.upper(), 'title'))
|
|
216
|
+
row.addStretch(1)
|
|
217
|
+
if value is not None:
|
|
218
|
+
value.setProperty('role', 'value')
|
|
219
|
+
row.addWidget(value)
|
|
220
|
+
self.__m_layout.addLayout(row)
|
|
221
|
+
|
|
222
|
+
def _check(self, text, slot):
|
|
223
|
+
"""
|
|
224
|
+
:param text: str | unicode | QString
|
|
225
|
+
:param slot: callable
|
|
226
|
+
:return: QCheckBox
|
|
227
|
+
"""
|
|
228
|
+
box = QCheckBox(text) # type: QCheckBox
|
|
229
|
+
box.toggled.connect(slot)
|
|
230
|
+
self.__m_layout.addWidget(box)
|
|
231
|
+
return box
|
|
232
|
+
|
|
233
|
+
def _slider(self, lo, hi, slot):
|
|
234
|
+
"""
|
|
235
|
+
:param lo: int
|
|
236
|
+
:param hi: int
|
|
237
|
+
:param slot: callable
|
|
238
|
+
:return: QSlider
|
|
239
|
+
"""
|
|
240
|
+
s = QSlider(Qt.Horizontal) # type: QSlider
|
|
241
|
+
s.setRange(lo, hi)
|
|
242
|
+
s.valueChanged.connect(slot)
|
|
243
|
+
self.__m_layout.addWidget(s)
|
|
244
|
+
return s
|
|
245
|
+
|
|
246
|
+
def _combo(self, items, slot):
|
|
247
|
+
"""
|
|
248
|
+
:param items: (list[tuple[str, str]]) (data, text)
|
|
249
|
+
:param slot: callable f(data)
|
|
250
|
+
:return: QComboBox
|
|
251
|
+
"""
|
|
252
|
+
c = QComboBox() # type: QComboBox
|
|
253
|
+
for data, text in items:
|
|
254
|
+
c.addItem(self.tr(text), data)
|
|
255
|
+
c.currentIndexChanged.connect(lambda i, cb=c: slot(cb.itemData(i)))
|
|
256
|
+
self.__m_layout.addWidget(c)
|
|
257
|
+
return c
|
|
258
|
+
|
|
259
|
+
def _buildColors(self):
|
|
260
|
+
"""
|
|
261
|
+
:return:
|
|
262
|
+
"""
|
|
263
|
+
ctrl = self.__m_ctrl # type: AnalysisController
|
|
264
|
+
self._title(self.tr(u'Color detection'))
|
|
265
|
+
if not ColorDetector.isAvailable():
|
|
266
|
+
self.__m_layout.addWidget(DetectionPanel._label(self.tr(u'Install numpy to enable color detection.'),
|
|
267
|
+
'hint'))
|
|
268
|
+
self.__m_colorOn = self._check(self.tr(u'Detect target colors'), self._setColorEnabled) # type: QCheckBox
|
|
269
|
+
self.__m_colorOn.setEnabled(ColorDetector.isAvailable())
|
|
270
|
+
self.__m_targets = QListWidget() # type: QListWidget
|
|
271
|
+
self.__m_targets.setMaximumHeight(110)
|
|
272
|
+
self.__m_layout.addWidget(self.__m_targets)
|
|
273
|
+
row = QGridLayout() # type: QGridLayout # 2 x 2: fits a narrow panel in every language
|
|
274
|
+
buttons = [] # type: list
|
|
275
|
+
for text, tip, slot in ((self.tr(u'Add...'), self.tr(u'Choose a color'), self._addDialog),
|
|
276
|
+
(self.tr(u'Remove'), self.tr(u'Remove the selected color'), self._removeSelected),
|
|
277
|
+
(self.tr(u'Clear'), self.tr(u'Remove every target color'),
|
|
278
|
+
self.__m_colors.clearTargetColors)):
|
|
279
|
+
b = QPushButton(text) # type: QPushButton
|
|
280
|
+
b.setProperty('role', 'small')
|
|
281
|
+
b.setToolTip(tip)
|
|
282
|
+
b.clicked.connect(slot)
|
|
283
|
+
buttons.append(b)
|
|
284
|
+
self.__m_pick = QPushButton(self.tr(u'Pick')) # type: QPushButton
|
|
285
|
+
self.__m_pick.setProperty('role', 'small')
|
|
286
|
+
self.__m_pick.setCheckable(True)
|
|
287
|
+
self.__m_pick.setToolTip(self.tr(u'Click a pixel in the magnifier to add its color'))
|
|
288
|
+
buttons.insert(1, self.__m_pick)
|
|
289
|
+
for i, b in enumerate(buttons):
|
|
290
|
+
row.addWidget(b, i // 2, i % 2)
|
|
291
|
+
self.__m_layout.addLayout(row)
|
|
292
|
+
self._title(self.tr(u'Match'))
|
|
293
|
+
self.__m_match = self._combo(MATCH_MODES, lambda m: (self.__m_colors.setMatchMode(m), self._save()))
|
|
294
|
+
self.__m_tolValue = QLabel() # type: QLabel
|
|
295
|
+
self._title(self.tr(u'Tolerance'), self.__m_tolValue)
|
|
296
|
+
self.__m_tol = self._slider(1, 60, lambda v: (self.__m_colors.setTolerance(v), self._save())) # type: QSlider
|
|
297
|
+
self.__m_groupValue = QLabel() # type: QLabel
|
|
298
|
+
self._title(self.tr(u'Group nearby'), self.__m_groupValue)
|
|
299
|
+
self.__m_group = self._slider(
|
|
300
|
+
0, 20, lambda v: (self.__m_colors.setGroupDistance(v), self._save())) # type: QSlider
|
|
301
|
+
self.__m_group.setToolTip(self.tr(u'Fragments closer than this form one box (letters of a text line)'))
|
|
302
|
+
self.__m_areaValue = QLabel() # type: QLabel
|
|
303
|
+
self._title(self.tr(u'Smallest region'), self.__m_areaValue)
|
|
304
|
+
self.__m_area = self._slider(1, 400, lambda v: (self.__m_colors.setMinArea(v), self._save())) # type: QSlider
|
|
305
|
+
self.__m_boxes = self._check(self.tr(u'Boxes around regions'),
|
|
306
|
+
lambda on: (ctrl.setShowBoxes(on), self._save())) # type: QCheckBox
|
|
307
|
+
self.__m_mask = self._check(self.tr(u'Highlight mask'), lambda on: (ctrl.setShowMask(on), self._save()))
|
|
308
|
+
self.__m_maskMode = self._combo(MASK_MODES, lambda m: (ctrl.setMaskMode(m), self._save())) # type: QComboBox
|
|
309
|
+
self.__m_notify = self._check(self.tr(u'Notify when a target color appears'), self._setNotify)
|
|
310
|
+
self._title(self.tr(u'Show the zones in'))
|
|
311
|
+
self.__m_inView = self._check(self.tr(u'the magnifier'), lambda on: self._setWhere('zonesInMagnifier', on))
|
|
312
|
+
self.__m_inLens = self._check(self.tr(u'the zoomer (also in the Zoomer tab)'),
|
|
313
|
+
lambda on: self._setWhere('zonesInZoomer', on))
|
|
314
|
+
self._title(self.tr(u'Dominant colors'))
|
|
315
|
+
self.__m_palette = PaletteBar() # type: PaletteBar
|
|
316
|
+
self.__m_layout.addWidget(self.__m_palette)
|
|
317
|
+
self.__m_paletteNames = DetectionPanel._label('', 'hint') # type: QLabel
|
|
318
|
+
self.__m_layout.addWidget(self.__m_paletteNames)
|
|
319
|
+
|
|
320
|
+
def _buildFaces(self):
|
|
321
|
+
"""
|
|
322
|
+
:return:
|
|
323
|
+
"""
|
|
324
|
+
ctrl = self.__m_ctrl # type: AnalysisController
|
|
325
|
+
self._title(self.tr(u'Face detection (AI, optional)'))
|
|
326
|
+
if not FaceDetector.isAvailable():
|
|
327
|
+
self.__m_layout.addWidget(DetectionPanel._label(
|
|
328
|
+
self.tr(u'Install opencv-python (and numpy) to enable face detection.'), 'hint'))
|
|
329
|
+
self.__m_faceOn = self._check(self.tr(u'Detect faces'), self._setFaceEnabled) # type: QCheckBox
|
|
330
|
+
self.__m_faceOn.setEnabled(FaceDetector.isAvailable())
|
|
331
|
+
self.__m_backend = self._combo(FACE_BACKENDS, lambda b: (self.__m_faces.setBackend(b),
|
|
332
|
+
self._refreshModelState(), self._save()))
|
|
333
|
+
row = QHBoxLayout() # type: QHBoxLayout
|
|
334
|
+
self.__m_modelState = DetectionPanel._label('', 'hint') # type: QLabel
|
|
335
|
+
self.__m_download = QPushButton(self.tr(u'Download model')) # type: QPushButton
|
|
336
|
+
self.__m_download.setProperty('role', 'small')
|
|
337
|
+
self.__m_download.setToolTip(self.tr(u'YuNet, 232 KB, MIT license, from the official OpenCV model zoo'))
|
|
338
|
+
self.__m_download.clicked.connect(self._download)
|
|
339
|
+
row.addWidget(self.__m_modelState, 1)
|
|
340
|
+
row.addWidget(self.__m_download)
|
|
341
|
+
self.__m_layout.addLayout(row)
|
|
342
|
+
self.__m_scoreValue = QLabel() # type: QLabel
|
|
343
|
+
self._title(self.tr(u'Confidence'), self.__m_scoreValue)
|
|
344
|
+
self.__m_score = self._slider(10, 99, lambda v: (self.__m_faces.setScoreThreshold(v / 100.0),
|
|
345
|
+
self.__m_ctrl.reanalyse(), self._save())) # type: QSlider
|
|
346
|
+
self.__m_faceMode = self._combo(FACE_MODES, lambda m: (ctrl.setFaceMode(m), self._save())) # type: QComboBox
|
|
347
|
+
self.__m_faceInfo = DetectionPanel._label('', 'hint') # type: QLabel
|
|
348
|
+
self.__m_layout.addWidget(self.__m_faceInfo)
|
|
349
|
+
|
|
350
|
+
def _buildFacePointer(self):
|
|
351
|
+
"""
|
|
352
|
+
FACE POINTER: the pointer (or the zoomer) glides to the faces on the screen, e.g. while watching a film.
|
|
353
|
+
:return:
|
|
354
|
+
"""
|
|
355
|
+
fp = self.__m_pointer # type: FacePointer
|
|
356
|
+
s = self.__m_pointerSettings # type: QSettings
|
|
357
|
+
fp.setFollow(int(s.value('follow', FOLLOW_POINTER)))
|
|
358
|
+
fp.setChoose(int(s.value('choose', CHOOSE_LARGEST)))
|
|
359
|
+
fp.setSmoothness(int(s.value('smoothness', 40)))
|
|
360
|
+
fp.setPauseSeconds(float(s.value('pauseSeconds', 3.0)))
|
|
361
|
+
fp.setScanRate(int(s.value('scanRate', 5)))
|
|
362
|
+
fp.setMotion(int(s.value('motion', MOTION_AUTO)))
|
|
363
|
+
fp.setHold(int(s.value('hold', HOLD_ALWAYS)))
|
|
364
|
+
fp.setAssistArea(int(s.value('assistArea', 35)))
|
|
365
|
+
fp.setStrength(int(s.value('strength', 60)))
|
|
366
|
+
self._title(self.tr(u'Face pointer (films, offline games)'))
|
|
367
|
+
self.__m_pointerOn = self._check(self.tr(u'Follow the faces on the screen'), fp.setEnabled) # type: QCheckBox
|
|
368
|
+
self.__m_pointerOn.setEnabled(FacePointer.isAvailable())
|
|
369
|
+
fp.enabledChanged.connect(self._refreshFacePointer)
|
|
370
|
+
fp.statusChanged.connect(self._refreshFacePointer)
|
|
371
|
+
self._title(self.tr(u'How to move'))
|
|
372
|
+
self.__m_pointerMotion = self._combo(POINTER_MOTION, lambda v: (fp.setMotion(v), self._savePointer(),
|
|
373
|
+
self._refreshFacePointer()))
|
|
374
|
+
self._title(self.tr(u'When'))
|
|
375
|
+
self.__m_pointerHold = self._combo(POINTER_HOLD, lambda v: (fp.setHold(v), self._savePointer()))
|
|
376
|
+
self.__m_followBox = QWidget() # type: QWidget # only when the pointer moves (not the game's view)
|
|
377
|
+
followLayout = QVBoxLayout(self.__m_followBox) # type: QVBoxLayout
|
|
378
|
+
followLayout.setContentsMargins(0, 0, 0, 0)
|
|
379
|
+
followLayout.addWidget(DetectionPanel._label(self.tr(u'What follows the face').upper(), 'title'))
|
|
380
|
+
self.__m_pointerFollow = self._combo(POINTER_FOLLOW, lambda v: (fp.setFollow(v), self._savePointer()))
|
|
381
|
+
followLayout.addWidget(self.__m_pointerFollow)
|
|
382
|
+
self.__m_layout.addWidget(self.__m_followBox)
|
|
383
|
+
self._title(self.tr(u'Which face'))
|
|
384
|
+
self.__m_pointerChoose = self._combo(POINTER_CHOOSE, lambda v: (fp.setChoose(v), self._savePointer()))
|
|
385
|
+
self.__m_pointerValues = {} # type: dict
|
|
386
|
+
self.__m_pointerSliders = {} # type: dict
|
|
387
|
+
self.__m_pointerRows = {} # type: dict # name -> row widget (shown for the motion it applies to)
|
|
388
|
+
for name, title, lo, hi in (('assistArea', self.tr(u'Assist area around the crosshair'), 10, 100),
|
|
389
|
+
('strength', self.tr(u'Strength'), 10, 100),
|
|
390
|
+
('smoothness', self.tr(u'Smoothness'), 0, 100),
|
|
391
|
+
('pauseSeconds', self.tr(u'Give the mouse back for'), 1, 10),
|
|
392
|
+
('scanRate', self.tr(u'Scans per second'), 1, 15)):
|
|
393
|
+
row = QWidget() # type: QWidget
|
|
394
|
+
column = QVBoxLayout(row) # type: QVBoxLayout
|
|
395
|
+
column.setContentsMargins(0, 0, 0, 0)
|
|
396
|
+
head = QHBoxLayout() # type: QHBoxLayout
|
|
397
|
+
head.addWidget(DetectionPanel._label(title.upper(), 'title'))
|
|
398
|
+
head.addStretch(1)
|
|
399
|
+
value = QLabel() # type: QLabel
|
|
400
|
+
value.setProperty('role', 'value')
|
|
401
|
+
head.addWidget(value)
|
|
402
|
+
column.addLayout(head)
|
|
403
|
+
slider = QSlider(Qt.Horizontal) # type: QSlider
|
|
404
|
+
slider.setRange(lo, hi)
|
|
405
|
+
setter = getattr(fp, 'set' + name[0].upper() + name[1:])
|
|
406
|
+
slider.valueChanged.connect(lambda v, f=setter: (f(v), self._savePointer(), self._refreshFacePointer()))
|
|
407
|
+
column.addWidget(slider)
|
|
408
|
+
self.__m_layout.addWidget(row)
|
|
409
|
+
self.__m_pointerRows[name] = row
|
|
410
|
+
self.__m_pointerValues[name] = value
|
|
411
|
+
self.__m_pointerSliders[name] = slider
|
|
412
|
+
self.__m_pointerStatus = DetectionPanel._label('', 'hint') # type: QLabel
|
|
413
|
+
self.__m_layout.addWidget(self.__m_pointerStatus)
|
|
414
|
+
self.__m_gameHint = DetectionPanel._label(self.tr(
|
|
415
|
+
u'Offline games that capture the mouse: the view turns until the face is at the crosshair (the screen '
|
|
416
|
+
'centre), about 30 times per second; the game\'s mouse sensitivity is measured from the picture while it '
|
|
417
|
+
'assists. Only faces inside the assist area '
|
|
418
|
+
'count, and a portrait of the game\'s interface is ignored. "While the right mouse button is held" never '
|
|
419
|
+
'fights your own aiming. Run the game in borderless / windowed mode. Realistic faces work best.'),
|
|
420
|
+
'hint') # type: QLabel
|
|
421
|
+
self.__m_layout.addWidget(self.__m_gameHint)
|
|
422
|
+
self.__m_filmHint = DetectionPanel._label(self.tr(
|
|
423
|
+
u'Faces are found anywhere on the screen of the pointer (the zoomer lens and this window are ignored), '
|
|
424
|
+
'with the face detection settings above. Move the mouse yourself to take the control back. Video '
|
|
425
|
+
'players show their controls when the pointer moves: choose "Only the zoomer" to keep it still. The YuNet '
|
|
426
|
+
'model (Download model, above) finds smaller faces, faster.'),
|
|
427
|
+
'hint') # type: QLabel
|
|
428
|
+
self.__m_layout.addWidget(self.__m_filmHint)
|
|
429
|
+
for combo, value in ((self.__m_pointerFollow, fp.getFollow()), (self.__m_pointerChoose, fp.getChoose()),
|
|
430
|
+
(self.__m_pointerMotion, fp.getMotion()), (self.__m_pointerHold, fp.getHold())):
|
|
431
|
+
combo.blockSignals(True)
|
|
432
|
+
combo.setCurrentIndex(max(0, combo.findData(value)))
|
|
433
|
+
combo.blockSignals(False)
|
|
434
|
+
for name, slider in self.__m_pointerSliders.items():
|
|
435
|
+
slider.blockSignals(True)
|
|
436
|
+
slider.setValue(int(getattr(fp, 'get' + name[0].upper() + name[1:])()))
|
|
437
|
+
slider.blockSignals(False)
|
|
438
|
+
self._refreshFacePointer()
|
|
439
|
+
|
|
440
|
+
def _savePointer(self):
|
|
441
|
+
"""
|
|
442
|
+
:return:
|
|
443
|
+
"""
|
|
444
|
+
fp = self.__m_pointer # type: FacePointer
|
|
445
|
+
s = self.__m_pointerSettings # type: QSettings
|
|
446
|
+
for key, value in (('follow', fp.getFollow()), ('choose', fp.getChoose()), ('smoothness', fp.getSmoothness()),
|
|
447
|
+
('pauseSeconds', fp.getPauseSeconds()), ('scanRate', fp.getScanRate()),
|
|
448
|
+
('motion', fp.getMotion()), ('hold', fp.getHold()), ('assistArea', fp.getAssistArea()),
|
|
449
|
+
('strength', fp.getStrength())):
|
|
450
|
+
s.setValue(key, value)
|
|
451
|
+
|
|
452
|
+
@pyqtSlot()
|
|
453
|
+
def _refreshFacePointer(self, *args):
|
|
454
|
+
"""
|
|
455
|
+
:return:
|
|
456
|
+
"""
|
|
457
|
+
fp = self.__m_pointer # type: FacePointer
|
|
458
|
+
self.__m_pointerOn.blockSignals(True)
|
|
459
|
+
self.__m_pointerOn.setChecked(fp.isEnabled())
|
|
460
|
+
self.__m_pointerOn.blockSignals(False)
|
|
461
|
+
key = self.__m_hotkeyText('facePointer') # type: str
|
|
462
|
+
self.__m_pointerOn.setText(self.tr(u'Follow the faces on the screen') + (u' ({})'.format(key) if key else u''))
|
|
463
|
+
motion = fp.getMotion() # type: int
|
|
464
|
+
game, film = motion != MOTION_POINTER, motion != MOTION_VIEW # type: bool, bool # (Automatic: both)
|
|
465
|
+
view = fp.isTurningView() # type: bool
|
|
466
|
+
self.__m_followBox.setVisible(film)
|
|
467
|
+
self.__m_pointerHold.setEnabled(game)
|
|
468
|
+
for name in ('assistArea', 'strength'):
|
|
469
|
+
self.__m_pointerRows[name].setVisible(game)
|
|
470
|
+
for name in ('pauseSeconds', 'scanRate'):
|
|
471
|
+
self.__m_pointerRows[name].setVisible(film)
|
|
472
|
+
self.__m_gameHint.setVisible(game)
|
|
473
|
+
self.__m_filmHint.setVisible(film)
|
|
474
|
+
self.__m_pointerValues['assistArea'].setText(u'{} %'.format(fp.getAssistArea()))
|
|
475
|
+
self.__m_pointerValues['strength'].setText(u'{} %'.format(fp.getStrength()))
|
|
476
|
+
self.__m_pointerValues['smoothness'].setText(u'{} %'.format(fp.getSmoothness()))
|
|
477
|
+
self.__m_pointerValues['pauseSeconds'].setText(self.tr(u'{} s').format(int(fp.getPauseSeconds())))
|
|
478
|
+
self.__m_pointerValues['scanRate'].setText(self.tr(u'{} / s').format(fp.getScanRate()))
|
|
479
|
+
status, d = fp.getStatus(), fp.getStatusDetail() # type: str, dict
|
|
480
|
+
role = 'hint' # type: str
|
|
481
|
+
if status == 'unavailable':
|
|
482
|
+
text = self.tr(u'Install opencv-python (and numpy) to enable face detection.') # type: str
|
|
483
|
+
elif status == 'off':
|
|
484
|
+
text = self.tr(u'Off.')
|
|
485
|
+
elif status == 'searching':
|
|
486
|
+
text = self.tr(u'Looking for faces\u2026')
|
|
487
|
+
elif status == 'following' and view and d.get('auto'):
|
|
488
|
+
text, role = self.tr(u'\u2713 This game captures the mouse: the view turns to a face ({} in the assist '
|
|
489
|
+
'area, {:.0f} ms).').format(d.get('faces', 1), d.get('timeMs', 0.0)), 'ok'
|
|
490
|
+
elif status == 'following' and view:
|
|
491
|
+
text, role = self.tr(u'\u2713 Turning the view to a face ({} in the assist area, {:.0f} ms)').format(
|
|
492
|
+
d.get('faces', 1), d.get('timeMs', 0.0)), 'ok'
|
|
493
|
+
elif status == 'blank':
|
|
494
|
+
text, role = self.tr(u'\u26a0 The game\'s picture cannot be captured (black): run it in borderless / '
|
|
495
|
+
'windowed mode. On Windows, "pip install dxcam" captures more games.'), 'warn'
|
|
496
|
+
elif status == 'noReaction':
|
|
497
|
+
text, role = self.tr(u'\u26a0 The game does not receive the mouse movements. Click into the game; if '
|
|
498
|
+
'it runs as administrator, run Screen Magnifier as administrator too.'), 'warn'
|
|
499
|
+
elif status == 'following':
|
|
500
|
+
text, role = self.tr(u'\u2713 Following a face ({} on the screen, {:.0f} ms)').format(
|
|
501
|
+
d.get('faces', 1), d.get('timeMs', 0.0)), 'ok'
|
|
502
|
+
elif status == 'waiting':
|
|
503
|
+
text = self.tr(u'Hold the right mouse button to assist.')
|
|
504
|
+
elif status == 'static':
|
|
505
|
+
text = self.tr(u'A face that does not move with the view (a portrait of the game\'s interface) is '
|
|
506
|
+
'ignored for a few seconds.')
|
|
507
|
+
elif status == 'blocked' and view:
|
|
508
|
+
text, role = self.tr(u'\u26a0 This system does not let applications send mouse movements (Wayland, or '
|
|
509
|
+
'macOS without the Accessibility permission).'), 'warn'
|
|
510
|
+
elif status == 'paused':
|
|
511
|
+
text = self.tr(u'Paused: you moved the mouse. It starts again {} s after you stop.').format(
|
|
512
|
+
int(fp.getPauseSeconds()))
|
|
513
|
+
elif status == 'blocked':
|
|
514
|
+
text, role = self.tr(u'\u26a0 This system does not let applications move the pointer (Wayland, or macOS '
|
|
515
|
+
'without the Accessibility permission): choose "Only the zoomer".'), 'warn'
|
|
516
|
+
else:
|
|
517
|
+
text, role = self.tr(u'Face detection failed: {}').format(d.get('message', '')), 'warn'
|
|
518
|
+
self.__m_pointerStatus.setText(text)
|
|
519
|
+
self.__m_pointerStatus.setProperty('role', role)
|
|
520
|
+
self.__m_pointerStatus.style().unpolish(self.__m_pointerStatus)
|
|
521
|
+
self.__m_pointerStatus.style().polish(self.__m_pointerStatus)
|
|
522
|
+
|
|
523
|
+
def _buildAnalysis(self):
|
|
524
|
+
"""
|
|
525
|
+
:return:
|
|
526
|
+
"""
|
|
527
|
+
self.__m_rateValue = QLabel() # type: QLabel
|
|
528
|
+
self._title(self.tr(u'Analysis rate'), self.__m_rateValue)
|
|
529
|
+
self.__m_rate = self._slider(1, 30, lambda v: (self.__m_ctrl.setRateHz(v), self._save())) # type: QSlider
|
|
530
|
+
self.__m_engine = DetectionPanel._label('', 'hint') # type: QLabel
|
|
531
|
+
self.__m_layout.addWidget(self.__m_engine)
|
|
532
|
+
|
|
533
|
+
# ---------- Settings ----------
|
|
534
|
+
def _load(self):
|
|
535
|
+
"""
|
|
536
|
+
:return:
|
|
537
|
+
"""
|
|
538
|
+
self.__m_loading = True # type: bool
|
|
539
|
+
s = self.__m_settings # type: QSettings
|
|
540
|
+
get = lambda key, default, cast: cast(s.value(key, default))
|
|
541
|
+
flag = lambda v: u'{}'.format(v).lower() in ('1', 'true', 'yes')
|
|
542
|
+
targets = s.value('targets', []) or [] # type: list
|
|
543
|
+
if hasattr(targets, 'encode'):
|
|
544
|
+
targets = [t for t in targets.split(',') if t] # type: list
|
|
545
|
+
if int(s.value('engineVersion', 1)) < ENGINE_VERSION: # Tolerance changed meaning: start from defaults.
|
|
546
|
+
for key in ('tolerance', 'matchMode', 'groupDistance'):
|
|
547
|
+
s.remove(key)
|
|
548
|
+
s.setValue('engineVersion', ENGINE_VERSION)
|
|
549
|
+
widgets = (self.__m_match, self.__m_group, self.__m_tol, self.__m_area, self.__m_boxes, self.__m_mask,
|
|
550
|
+
self.__m_maskMode, self.__m_notify, self.__m_backend, self.__m_score, self.__m_faceMode,
|
|
551
|
+
self.__m_rate)
|
|
552
|
+
for w in widgets:
|
|
553
|
+
w.blockSignals(True)
|
|
554
|
+
self.__m_colors.setTargetColors([QColor(u'{}'.format(t)) for t in targets if QColor(u'{}'.format(t)).isValid()])
|
|
555
|
+
self.__m_match.setCurrentIndex(max(0, self.__m_match.findData(get('matchMode', 0, int))))
|
|
556
|
+
self.__m_group.setValue(get('groupDistance', 5, int))
|
|
557
|
+
self.__m_tol.setValue(get('tolerance', 15, int))
|
|
558
|
+
self.__m_area.setValue(get('minArea', 12, int))
|
|
559
|
+
self.__m_boxes.setChecked(get('boxes', True, flag))
|
|
560
|
+
self.__m_mask.setChecked(get('mask', True, flag))
|
|
561
|
+
self.__m_maskMode.setCurrentIndex(max(0, self.__m_maskMode.findData(get('maskMode', 'isolate', str))))
|
|
562
|
+
self.__m_notify.setChecked(get('notify', True, flag))
|
|
563
|
+
self.__m_backend.setCurrentIndex(max(0, self.__m_backend.findData(get('faceBackend', 'auto', str))))
|
|
564
|
+
self.__m_score.setValue(get('faceScore', 60, int))
|
|
565
|
+
self.__m_faceMode.setCurrentIndex(max(0, self.__m_faceMode.findData(get('faceMode', 'box', str))))
|
|
566
|
+
self.__m_rate.setValue(get('rate', 8, int))
|
|
567
|
+
for w in widgets:
|
|
568
|
+
w.blockSignals(False)
|
|
569
|
+
ctrl = self.__m_ctrl # type: AnalysisController
|
|
570
|
+
self.__m_colors.setMatchMode(self.__m_match.currentData())
|
|
571
|
+
self.__m_colors.setGroupDistance(self.__m_group.value())
|
|
572
|
+
self.__m_colors.setTolerance(self.__m_tol.value())
|
|
573
|
+
self.__m_colors.setMinArea(self.__m_area.value())
|
|
574
|
+
ctrl.setShowBoxes(self.__m_boxes.isChecked())
|
|
575
|
+
ctrl.setShowMask(self.__m_mask.isChecked())
|
|
576
|
+
ctrl.setMaskMode(self.__m_maskMode.currentData())
|
|
577
|
+
ctrl.setFaceMode(self.__m_faceMode.currentData())
|
|
578
|
+
ctrl.setRateHz(self.__m_rate.value())
|
|
579
|
+
self.__m_faces.setBackend(self.__m_backend.currentData())
|
|
580
|
+
self.__m_faces.setScoreThreshold(self.__m_score.value() / 100.0)
|
|
581
|
+
self.__m_notifyOn = self.__m_notify.isChecked() # type: bool
|
|
582
|
+
colorOn = get('colorEnabled', False, flag) and ColorDetector.isAvailable() # type: bool
|
|
583
|
+
faceOn = get('faceEnabled', False, flag) and FaceDetector.isAvailable() # type: bool
|
|
584
|
+
self.__m_colorOn.setChecked(colorOn)
|
|
585
|
+
self.__m_faceOn.setChecked(faceOn)
|
|
586
|
+
self.__m_loading = False # type: bool
|
|
587
|
+
self._updateLabels()
|
|
588
|
+
|
|
589
|
+
def _save(self):
|
|
590
|
+
"""
|
|
591
|
+
:return: None
|
|
592
|
+
"""
|
|
593
|
+
if self.__m_loading:
|
|
594
|
+
return
|
|
595
|
+
s = self.__m_settings # type: QSettings
|
|
596
|
+
s.setValue('targets', ','.join(u'{}'.format(c.name()) for c in self.__m_colors.getTargetColors()))
|
|
597
|
+
for key, value in (('matchMode', self.__m_match.currentData()), ('groupDistance', self.__m_group.value()),
|
|
598
|
+
('tolerance', self.__m_tol.value()), ('minArea', self.__m_area.value()),
|
|
599
|
+
('boxes', self.__m_boxes.isChecked()), ('mask', self.__m_mask.isChecked()),
|
|
600
|
+
('maskMode', self.__m_maskMode.currentData()), ('notify', self.__m_notify.isChecked()),
|
|
601
|
+
('faceBackend', self.__m_backend.currentData()),
|
|
602
|
+
('faceScore', self.__m_score.value()), ('faceMode', self.__m_faceMode.currentData()),
|
|
603
|
+
('rate', self.__m_rate.value()), ('colorEnabled', self.__m_colorOn.isChecked()),
|
|
604
|
+
('faceEnabled', self.__m_faceOn.isChecked())):
|
|
605
|
+
s.setValue(key, value)
|
|
606
|
+
self._updateLabels()
|
|
607
|
+
|
|
608
|
+
def _updateLabels(self):
|
|
609
|
+
"""
|
|
610
|
+
:return:
|
|
611
|
+
"""
|
|
612
|
+
exact = self.__m_match.currentData() == 1 # type: bool
|
|
613
|
+
self.__m_tolValue.setText(
|
|
614
|
+
(self.tr(u'Delta E {}') if exact else self.tr(u'{} deg hue')).format(self.__m_tol.value()))
|
|
615
|
+
self.__m_groupValue.setText(self.tr(u'{} px').format(self.__m_group.value()))
|
|
616
|
+
self.__m_areaValue.setText(self.tr(u'{} px').format(self.__m_area.value()))
|
|
617
|
+
self.__m_scoreValue.setText('{} %'.format(self.__m_score.value()))
|
|
618
|
+
self.__m_rateValue.setText(self.tr(u'{} / s').format(self.__m_rate.value()))
|
|
619
|
+
self.__m_maskMode.setEnabled(self.__m_mask.isChecked())
|
|
620
|
+
|
|
621
|
+
# ---------- Slots ----------
|
|
622
|
+
def _setColorEnabled(self, on):
|
|
623
|
+
"""
|
|
624
|
+
:param on: bool
|
|
625
|
+
:return:
|
|
626
|
+
"""
|
|
627
|
+
self.__m_ctrl.setColorEnabled(on)
|
|
628
|
+
self._save()
|
|
629
|
+
|
|
630
|
+
def _setFaceEnabled(self, on):
|
|
631
|
+
"""
|
|
632
|
+
:param on: bool
|
|
633
|
+
:return:
|
|
634
|
+
"""
|
|
635
|
+
self.__m_ctrl.setFaceEnabled(on)
|
|
636
|
+
self._refreshModelState()
|
|
637
|
+
self._save()
|
|
638
|
+
|
|
639
|
+
def _setNotify(self, on):
|
|
640
|
+
"""
|
|
641
|
+
:param on: bool
|
|
642
|
+
:return:
|
|
643
|
+
"""
|
|
644
|
+
self.__m_notifyOn = bool(on) # type: bool
|
|
645
|
+
self._save()
|
|
646
|
+
|
|
647
|
+
def _setWhere(self, name, on):
|
|
648
|
+
"""
|
|
649
|
+
:param name: (str | unicode | QString) 'zonesInMagnifier' or 'zonesInZoomer' (FeatureSettings).
|
|
650
|
+
:param on: bool
|
|
651
|
+
:return:
|
|
652
|
+
"""
|
|
653
|
+
if self.__m_features is not None:
|
|
654
|
+
self.__m_features.set(name, bool(on))
|
|
655
|
+
|
|
656
|
+
def _syncWhere(self, *args):
|
|
657
|
+
"""
|
|
658
|
+
:param args: any
|
|
659
|
+
:return:
|
|
660
|
+
"""
|
|
661
|
+
f = self.__m_features
|
|
662
|
+
for box, name in ((self.__m_inView, 'zonesInMagnifier'), (self.__m_inLens, 'zonesInZoomer')):
|
|
663
|
+
box.blockSignals(True)
|
|
664
|
+
box.setChecked(f is not None and f.get(name))
|
|
665
|
+
box.setEnabled(f is not None)
|
|
666
|
+
box.blockSignals(False)
|
|
667
|
+
|
|
668
|
+
def _addDialog(self):
|
|
669
|
+
"""
|
|
670
|
+
:return:
|
|
671
|
+
"""
|
|
672
|
+
color = QColorDialog.getColor(QColor('#E01020'), self, self.tr(u'Target color')) # type: QColor
|
|
673
|
+
if color.isValid():
|
|
674
|
+
self.__m_colors.addTargetColor(color)
|
|
675
|
+
|
|
676
|
+
def _removeSelected(self):
|
|
677
|
+
"""
|
|
678
|
+
:return:
|
|
679
|
+
"""
|
|
680
|
+
row = self.__m_targets.currentRow() # type: int
|
|
681
|
+
if row >= 0:
|
|
682
|
+
self.__m_colors.removeTargetColor(row)
|
|
683
|
+
|
|
684
|
+
def _refreshTargets(self):
|
|
685
|
+
"""
|
|
686
|
+
:return:
|
|
687
|
+
"""
|
|
688
|
+
coverage = {c['target']: c['fraction'] for c in
|
|
689
|
+
self.__m_ctrl.getLastResult('view').get('colors', {}).get('coverage', [])} # type: dict
|
|
690
|
+
self.__m_targets.clear()
|
|
691
|
+
for i, c in enumerate(self.__m_colors.getTargetColors()):
|
|
692
|
+
text = '{} {}'.format(nearestColorName(c)[0], u'{}'.format(c.name()).upper()) # type: str
|
|
693
|
+
if i in coverage:
|
|
694
|
+
text += ' {:.1f} %'.format(100.0 * coverage[i])
|
|
695
|
+
self.__m_targets.addItem(QListWidgetItem(swatch(c), text))
|
|
696
|
+
self._save()
|
|
697
|
+
|
|
698
|
+
def _onResults(self, source, result):
|
|
699
|
+
"""
|
|
700
|
+
:param source: str | unicode | QString
|
|
701
|
+
:param result: dict
|
|
702
|
+
:return:
|
|
703
|
+
"""
|
|
704
|
+
if u'{}'.format(source) != 'view':
|
|
705
|
+
return
|
|
706
|
+
colors = result.get('colors') or {} # type: dict
|
|
707
|
+
faces = result.get('faces') or {} # type: dict
|
|
708
|
+
palette = colors.get('palette', []) # type: list
|
|
709
|
+
self.__m_palette.setColors(palette)
|
|
710
|
+
self.__m_paletteNames.setText(', '.join('{} {:.0f}%'.format(p['name'], 100 * p['fraction'])
|
|
711
|
+
for p in palette[:4]))
|
|
712
|
+
for i, c in enumerate(colors.get('coverage', [])):
|
|
713
|
+
item = self.__m_targets.item(c['target']) # type: QListWidgetItem
|
|
714
|
+
if item is not None:
|
|
715
|
+
item.setText('{} {} {:.1f} %'.format(c['name'], c['color'], 100.0 * c['fraction']))
|
|
716
|
+
if self.__m_ctrl.isFaceEnabled():
|
|
717
|
+
self.__m_faceInfo.setText(self.tr(u'{} face(s) - {} - {:.0f} ms').format(
|
|
718
|
+
len(faces.get('faces', [])), faces.get('backend', '-') or '-', faces.get('timeMs', 0)))
|
|
719
|
+
where = self.tr(u'server') if self.__m_ctrl.isRemoteActive() else self.tr(u'this computer') # type: str
|
|
720
|
+
self.__m_engine.setText(self.tr(u'Analysed on {}: colors {:.0f} ms, faces {:.0f} ms').format(
|
|
721
|
+
where, colors.get('timeMs', 0), faces.get('timeMs', 0)))
|
|
722
|
+
|
|
723
|
+
def _onAppeared(self, source, name):
|
|
724
|
+
"""
|
|
725
|
+
:param source: str | unicode | QString
|
|
726
|
+
:param name: str | unicode | QString
|
|
727
|
+
:return:
|
|
728
|
+
"""
|
|
729
|
+
if self.__m_notifyOn:
|
|
730
|
+
where = self.tr(u'zoom lens') if u'{}'.format(source) == 'lens' else self.tr(u'magnifier') # type: str
|
|
731
|
+
self.notify.emit(self.tr(u'Target color "{}" detected in the {}').format(name, where))
|
|
732
|
+
|
|
733
|
+
def _refreshModelState(self):
|
|
734
|
+
"""
|
|
735
|
+
:return:
|
|
736
|
+
"""
|
|
737
|
+
fd = self.__m_faces # type: FaceDetector
|
|
738
|
+
if not FaceDetector.isAvailable():
|
|
739
|
+
text = self.tr(u'OpenCV not installed') # type: str
|
|
740
|
+
elif fd.isModelReady():
|
|
741
|
+
text = self.tr(u'YuNet model installed') # type: str
|
|
742
|
+
elif not FaceDetector.hasYuNetSupport():
|
|
743
|
+
text = self.tr(u'This OpenCV has no YuNet support: Haar is used') # type: str
|
|
744
|
+
else:
|
|
745
|
+
text = self.tr(u'YuNet model not installed: Haar is used') # type: str
|
|
746
|
+
active = fd.getActiveBackend() # type: str
|
|
747
|
+
if active:
|
|
748
|
+
text += self.tr(u' (active: {})').format(active)
|
|
749
|
+
self.__m_modelState.setText(text)
|
|
750
|
+
self.__m_download.setVisible(FaceDetector.hasYuNetSupport() and not fd.isModelReady())
|
|
751
|
+
self.__m_download.setEnabled(not fd.isDownloading())
|
|
752
|
+
|
|
753
|
+
def _download(self):
|
|
754
|
+
"""
|
|
755
|
+
:return:
|
|
756
|
+
"""
|
|
757
|
+
self.__m_download.setEnabled(False)
|
|
758
|
+
self.__m_faces.downloadModel()
|
|
759
|
+
|
|
760
|
+
def _onDownloaded(self, ok, message):
|
|
761
|
+
"""
|
|
762
|
+
:param ok: bool
|
|
763
|
+
:param message: str | unicode | QString
|
|
764
|
+
:return:
|
|
765
|
+
"""
|
|
766
|
+
self._refreshModelState()
|
|
767
|
+
self.__m_ctrl.reanalyse()
|
|
768
|
+
self.notify.emit(self.tr(u'YuNet face model installed.') if ok else u'{}'.format(message))
|
|
769
|
+
|
|
770
|
+
# ---------- Public API ----------
|
|
771
|
+
@pyqtSlot(QPoint, QColor)
|
|
772
|
+
def onPixelClicked(self, pos, color):
|
|
773
|
+
"""
|
|
774
|
+
In pick mode, a click in the magnifier adds the clicked color as a target.
|
|
775
|
+
:param pos: QPoint
|
|
776
|
+
:param color: QColor
|
|
777
|
+
:return:
|
|
778
|
+
"""
|
|
779
|
+
if self.__m_pick.isChecked() and color.isValid():
|
|
780
|
+
self.__m_colors.addTargetColor(color)
|
|
781
|
+
self.__m_pick.setChecked(False)
|
|
782
|
+
if not self.__m_colorOn.isChecked():
|
|
783
|
+
self.__m_colorOn.setChecked(True)
|
|
784
|
+
self.notify.emit(self.tr(u'Target color {} added').format(u'{}'.format(color.name()).upper()))
|
|
785
|
+
|
|
786
|
+
def isPicking(self):
|
|
787
|
+
"""
|
|
788
|
+
:return: bool
|
|
789
|
+
"""
|
|
790
|
+
return self.__m_pick.isChecked()
|