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,316 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
ColorSwatchesWidget: a grid of color swatches, e.g. a color-picker history.
|
|
4
|
+
- Newest first; adding an existing color moves it to the front; at most maxColors are kept.
|
|
5
|
+
- Click a swatch: colorClicked(QColor); right-click: removes it (colorRemoved(int)).
|
|
6
|
+
- Hover highlight and a tooltip with the HEX code; columns adapt to the width (heightForWidth).
|
|
7
|
+
"""
|
|
8
|
+
from ManyQt.QtCore import Qt, QRectF, QSize, pyqtSignal, pyqtSlot, pyqtProperty
|
|
9
|
+
from ManyQt.QtWidgets import QWidget, QToolTip, QSizePolicy
|
|
10
|
+
from ManyQt.QtGui import QPainter, QColor, QPen, QFont
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ColorSwatchesWidget(QWidget):
|
|
14
|
+
"""
|
|
15
|
+
ColorSwatchesWidget class.
|
|
16
|
+
"""
|
|
17
|
+
colorClicked = pyqtSignal(QColor) # type: pyqtSignal
|
|
18
|
+
colorRemoved = pyqtSignal(int) # type: pyqtSignal
|
|
19
|
+
colorsChanged = pyqtSignal() # type: pyqtSignal
|
|
20
|
+
|
|
21
|
+
def __init__(self, *args, **kwargs):
|
|
22
|
+
"""
|
|
23
|
+
:param colors: (list[QColor | str]) Initial colors, newest first.
|
|
24
|
+
:param maxColors: (int) Older colors are dropped beyond this.
|
|
25
|
+
:param swatchSize: (int) Swatch edge in px.
|
|
26
|
+
:param spacing: (int) Gap between swatches in px.
|
|
27
|
+
:param placeholderText: (str | unicode | QString) Shown when empty.
|
|
28
|
+
:param colorClicked: callable | None
|
|
29
|
+
:param colorRemoved: callable | None
|
|
30
|
+
:param colorsChanged: callable | None
|
|
31
|
+
:param args: any
|
|
32
|
+
:param kwargs: any
|
|
33
|
+
"""
|
|
34
|
+
colors = kwargs.pop('colors', []) # type: list
|
|
35
|
+
maxColors = kwargs.pop('maxColors', 24) # type: int
|
|
36
|
+
swatchSize = kwargs.pop('swatchSize', 24) # type: int
|
|
37
|
+
spacing = kwargs.pop('spacing', 6) # type: int
|
|
38
|
+
placeholderText = kwargs.pop('placeholderText', 'No colors yet') # type: str
|
|
39
|
+
colorClicked = kwargs.pop('colorClicked', None) # type: callable | None
|
|
40
|
+
colorRemoved = kwargs.pop('colorRemoved', None) # type: callable | None
|
|
41
|
+
colorsChanged = kwargs.pop('colorsChanged', None) # type: callable | None
|
|
42
|
+
super(ColorSwatchesWidget, self).__init__(*args, **kwargs)
|
|
43
|
+
for signal, slot in ((self.colorClicked, colorClicked), (self.colorRemoved, colorRemoved),
|
|
44
|
+
(self.colorsChanged, colorsChanged)):
|
|
45
|
+
if callable(slot):
|
|
46
|
+
signal.connect(slot)
|
|
47
|
+
self.__m_maxColors = max(1, int(maxColors)) # type: int
|
|
48
|
+
self.__m_swatchSize = max(8, int(swatchSize)) # type: int
|
|
49
|
+
self.__m_spacing = max(0, int(spacing)) # type: int
|
|
50
|
+
self.__m_placeholderText = placeholderText # type: str
|
|
51
|
+
self.__m_colors = [QColor(c) for c in colors if QColor(c).isValid()][:self.__m_maxColors] # type: list
|
|
52
|
+
self.__m_hover = -1 # type: int
|
|
53
|
+
self.setMouseTracking(True)
|
|
54
|
+
self.setCursor(Qt.PointingHandCursor)
|
|
55
|
+
policy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) # type: QSizePolicy
|
|
56
|
+
policy.setHeightForWidth(True)
|
|
57
|
+
self.setSizePolicy(policy)
|
|
58
|
+
|
|
59
|
+
# ---------- Helpers ----------
|
|
60
|
+
def _columns(self, width=None):
|
|
61
|
+
"""
|
|
62
|
+
:param width: (int | None) Widget width (None = current).
|
|
63
|
+
:return: int
|
|
64
|
+
"""
|
|
65
|
+
w = self.width() if width is None else int(width) # type: int
|
|
66
|
+
return max(1, (w + self.__m_spacing) // (self.__m_swatchSize + self.__m_spacing))
|
|
67
|
+
|
|
68
|
+
def _rect(self, index):
|
|
69
|
+
"""
|
|
70
|
+
:param index: int
|
|
71
|
+
:return: QRectF
|
|
72
|
+
"""
|
|
73
|
+
cols = self._columns() # type: int
|
|
74
|
+
step = self.__m_swatchSize + self.__m_spacing # type: int
|
|
75
|
+
return QRectF((index % cols) * step + 1, (index // cols) * step + 1, self.__m_swatchSize - 2,
|
|
76
|
+
self.__m_swatchSize - 2)
|
|
77
|
+
|
|
78
|
+
def _indexAt(self, pos):
|
|
79
|
+
"""
|
|
80
|
+
:param pos: QPoint
|
|
81
|
+
:return: (int) Swatch index, -1 if none.
|
|
82
|
+
"""
|
|
83
|
+
for i in range(len(self.__m_colors)):
|
|
84
|
+
if self._rect(i).adjusted(-1, -1, 1, 1).contains(pos.x(), pos.y()):
|
|
85
|
+
return i
|
|
86
|
+
return -1
|
|
87
|
+
|
|
88
|
+
def _changed(self):
|
|
89
|
+
"""
|
|
90
|
+
:return:
|
|
91
|
+
"""
|
|
92
|
+
self.updateGeometry()
|
|
93
|
+
self.update()
|
|
94
|
+
self.colorsChanged.emit()
|
|
95
|
+
|
|
96
|
+
# ---------- Public API ----------
|
|
97
|
+
def getColors(self):
|
|
98
|
+
"""
|
|
99
|
+
:return: (list[QColor]) Newest first.
|
|
100
|
+
"""
|
|
101
|
+
return [QColor(c) for c in self.__m_colors]
|
|
102
|
+
|
|
103
|
+
@pyqtSlot(list)
|
|
104
|
+
def setColors(self, colors):
|
|
105
|
+
"""
|
|
106
|
+
:param colors: list[QColor | str]
|
|
107
|
+
:return:
|
|
108
|
+
"""
|
|
109
|
+
self.__m_colors = [QColor(c) for c in colors if QColor(c).isValid()][:self.__m_maxColors] # type: list[QColor]
|
|
110
|
+
self._changed()
|
|
111
|
+
|
|
112
|
+
@pyqtSlot(QColor)
|
|
113
|
+
@pyqtSlot(Qt.GlobalColor)
|
|
114
|
+
@pyqtSlot(int)
|
|
115
|
+
@pyqtSlot(str)
|
|
116
|
+
@pyqtSlot('QString')
|
|
117
|
+
def addColor(self, color):
|
|
118
|
+
"""
|
|
119
|
+
Put a color first (moving it if already present).
|
|
120
|
+
:param color: QColor | Qt.GlobalColor | int | str | unicode | QString
|
|
121
|
+
:return:
|
|
122
|
+
"""
|
|
123
|
+
c = QColor(color) # type: QColor
|
|
124
|
+
if not c.isValid():
|
|
125
|
+
return
|
|
126
|
+
self.__m_colors = [x for x in self.__m_colors if x.rgb() != c.rgb()] # type: list
|
|
127
|
+
self.__m_colors.insert(0, c)
|
|
128
|
+
del self.__m_colors[self.__m_maxColors:]
|
|
129
|
+
self._changed()
|
|
130
|
+
|
|
131
|
+
@pyqtSlot(int)
|
|
132
|
+
def removeColor(self, index):
|
|
133
|
+
"""
|
|
134
|
+
:param index: int
|
|
135
|
+
:return:
|
|
136
|
+
"""
|
|
137
|
+
if 0 <= int(index) < len(self.__m_colors):
|
|
138
|
+
del self.__m_colors[int(index)]
|
|
139
|
+
self.__m_hover = -1 # type: int
|
|
140
|
+
self._changed()
|
|
141
|
+
self.colorRemoved.emit(int(index))
|
|
142
|
+
|
|
143
|
+
@pyqtSlot()
|
|
144
|
+
def clear(self):
|
|
145
|
+
"""
|
|
146
|
+
:return:
|
|
147
|
+
"""
|
|
148
|
+
if self.__m_colors:
|
|
149
|
+
self.__m_colors = [] # type: list
|
|
150
|
+
self._changed()
|
|
151
|
+
|
|
152
|
+
def getMaxColors(self):
|
|
153
|
+
"""
|
|
154
|
+
:return: int
|
|
155
|
+
"""
|
|
156
|
+
return self.__m_maxColors
|
|
157
|
+
|
|
158
|
+
@pyqtSlot(int)
|
|
159
|
+
def setMaxColors(self, maxColors):
|
|
160
|
+
"""
|
|
161
|
+
:param maxColors: int
|
|
162
|
+
:return:
|
|
163
|
+
"""
|
|
164
|
+
self.__m_maxColors = max(1, int(maxColors)) # type: int
|
|
165
|
+
del self.__m_colors[self.__m_maxColors:]
|
|
166
|
+
self._changed()
|
|
167
|
+
|
|
168
|
+
def getSwatchSize(self):
|
|
169
|
+
"""
|
|
170
|
+
:return: int
|
|
171
|
+
"""
|
|
172
|
+
return self.__m_swatchSize
|
|
173
|
+
|
|
174
|
+
@pyqtSlot(int)
|
|
175
|
+
def setSwatchSize(self, swatchSize):
|
|
176
|
+
"""
|
|
177
|
+
:param swatchSize: int
|
|
178
|
+
:return:
|
|
179
|
+
"""
|
|
180
|
+
self.__m_swatchSize = max(8, int(swatchSize)) # type: int
|
|
181
|
+
self._changed()
|
|
182
|
+
|
|
183
|
+
def getSpacing(self):
|
|
184
|
+
"""
|
|
185
|
+
:return: int
|
|
186
|
+
"""
|
|
187
|
+
return self.__m_spacing
|
|
188
|
+
|
|
189
|
+
@pyqtSlot(int)
|
|
190
|
+
def setSpacing(self, spacing):
|
|
191
|
+
"""
|
|
192
|
+
:param spacing: int
|
|
193
|
+
:return:
|
|
194
|
+
"""
|
|
195
|
+
self.__m_spacing = max(0, int(spacing)) # type: int
|
|
196
|
+
self._changed()
|
|
197
|
+
|
|
198
|
+
def getPlaceholderText(self):
|
|
199
|
+
"""
|
|
200
|
+
:return: str | unicode | QString
|
|
201
|
+
"""
|
|
202
|
+
return self.__m_placeholderText
|
|
203
|
+
|
|
204
|
+
@pyqtSlot('QString')
|
|
205
|
+
@pyqtSlot(str)
|
|
206
|
+
def setPlaceholderText(self, placeholderText):
|
|
207
|
+
"""
|
|
208
|
+
:param placeholderText: str | unicode | QString
|
|
209
|
+
:return:
|
|
210
|
+
"""
|
|
211
|
+
self.__m_placeholderText = placeholderText # type: str
|
|
212
|
+
self.update()
|
|
213
|
+
|
|
214
|
+
# ---------- Qt overrides ----------
|
|
215
|
+
def hasHeightForWidth(self):
|
|
216
|
+
"""
|
|
217
|
+
:return: bool
|
|
218
|
+
"""
|
|
219
|
+
return True
|
|
220
|
+
|
|
221
|
+
def heightForWidth(self, width):
|
|
222
|
+
"""
|
|
223
|
+
:param width: int
|
|
224
|
+
:return: int
|
|
225
|
+
"""
|
|
226
|
+
rows = max(1, (len(self.__m_colors) + self._columns(width) - 1) // self._columns(width)) # type: int
|
|
227
|
+
return rows * (self.__m_swatchSize + self.__m_spacing)
|
|
228
|
+
|
|
229
|
+
def sizeHint(self):
|
|
230
|
+
"""
|
|
231
|
+
:return: QSize
|
|
232
|
+
"""
|
|
233
|
+
return QSize(8 * (self.__m_swatchSize + self.__m_spacing), self.heightForWidth(
|
|
234
|
+
8 * (self.__m_swatchSize + self.__m_spacing)))
|
|
235
|
+
|
|
236
|
+
def minimumSizeHint(self):
|
|
237
|
+
"""
|
|
238
|
+
:return: QSize
|
|
239
|
+
"""
|
|
240
|
+
return QSize(self.__m_swatchSize, self.__m_swatchSize)
|
|
241
|
+
|
|
242
|
+
def resizeEvent(self, e):
|
|
243
|
+
"""
|
|
244
|
+
:param e: QResizeEvent
|
|
245
|
+
:return:
|
|
246
|
+
"""
|
|
247
|
+
super(ColorSwatchesWidget, self).resizeEvent(e)
|
|
248
|
+
self.updateGeometry()
|
|
249
|
+
|
|
250
|
+
def mouseMoveEvent(self, e):
|
|
251
|
+
"""
|
|
252
|
+
:param e: QMouseEvent
|
|
253
|
+
:return:
|
|
254
|
+
"""
|
|
255
|
+
index = self._indexAt(e.pos()) # type: int
|
|
256
|
+
if index != self.__m_hover:
|
|
257
|
+
self.__m_hover = index # type: int
|
|
258
|
+
self.update()
|
|
259
|
+
if index >= 0:
|
|
260
|
+
QToolTip.showText(self.mapToGlobal(e.pos()), self.tr(u'{} - click: copy, right-click: remove').format(
|
|
261
|
+
u'{}'.format(self.__m_colors[index].name()).upper()), self)
|
|
262
|
+
super(ColorSwatchesWidget, self).mouseMoveEvent(e)
|
|
263
|
+
|
|
264
|
+
def leaveEvent(self, e):
|
|
265
|
+
"""
|
|
266
|
+
:param e: QEvent
|
|
267
|
+
:return:
|
|
268
|
+
"""
|
|
269
|
+
self.__m_hover = -1 # type: int
|
|
270
|
+
self.update()
|
|
271
|
+
super(ColorSwatchesWidget, self).leaveEvent(e)
|
|
272
|
+
|
|
273
|
+
def mouseReleaseEvent(self, e):
|
|
274
|
+
"""
|
|
275
|
+
:param e: QMouseEvent
|
|
276
|
+
:return:
|
|
277
|
+
"""
|
|
278
|
+
index = self._indexAt(e.pos()) # type: int
|
|
279
|
+
if index >= 0:
|
|
280
|
+
if e.button() == Qt.LeftButton:
|
|
281
|
+
self.colorClicked.emit(QColor(self.__m_colors[index]))
|
|
282
|
+
elif e.button() == Qt.RightButton:
|
|
283
|
+
self.removeColor(index)
|
|
284
|
+
super(ColorSwatchesWidget, self).mouseReleaseEvent(e)
|
|
285
|
+
|
|
286
|
+
def paintEvent(self, event):
|
|
287
|
+
"""
|
|
288
|
+
:param event: QPaintEvent
|
|
289
|
+
:return:
|
|
290
|
+
"""
|
|
291
|
+
p = QPainter(self) # type: QPainter
|
|
292
|
+
p.setRenderHint(QPainter.Antialiasing, True)
|
|
293
|
+
if not self.__m_colors:
|
|
294
|
+
font = QFont(self.font()) # type: QFont
|
|
295
|
+
font.setPointSizeF(max(7.0, font.pointSizeF() - 1))
|
|
296
|
+
p.setFont(font)
|
|
297
|
+
p.setPen(QColor('#7C8498'))
|
|
298
|
+
p.drawText(self.rect(), Qt.AlignLeft | Qt.AlignVCenter, self.__m_placeholderText)
|
|
299
|
+
p.end()
|
|
300
|
+
return
|
|
301
|
+
for i, c in enumerate(self.__m_colors):
|
|
302
|
+
r = self._rect(i) # type: QRectF
|
|
303
|
+
hover = i == self.__m_hover # type: bool
|
|
304
|
+
if hover:
|
|
305
|
+
r = r.adjusted(-1, -1, 1, 1) # type: QRectF
|
|
306
|
+
p.setPen(QPen(QColor(255, 255, 255, 230) if hover else QColor(255, 255, 255, 70), 2 if hover else 1))
|
|
307
|
+
p.setBrush(c)
|
|
308
|
+
p.drawRoundedRect(r, 5, 5)
|
|
309
|
+
p.end()
|
|
310
|
+
|
|
311
|
+
# ---------- Properties ----------
|
|
312
|
+
colors = pyqtProperty(list, fget=getColors, fset=setColors, notify=colorsChanged) # type: pyqtProperty
|
|
313
|
+
maxColors = pyqtProperty(int, fget=getMaxColors, fset=setMaxColors) # type: pyqtProperty
|
|
314
|
+
swatchSize = pyqtProperty(int, fget=getSwatchSize, fset=setSwatchSize) # type: pyqtProperty
|
|
315
|
+
spacing = pyqtProperty(int, fget=getSpacing, fset=setSpacing) # type: pyqtProperty
|
|
316
|
+
placeholderText = pyqtProperty('QString', fget=getPlaceholderText, fset=setPlaceholderText) # type: pyqtProperty
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Entry point for the ColorSwatches 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,60 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Demo window for ColorSwatchesWidget: add colors, click to copy, right-click to remove.
|
|
4
|
+
"""
|
|
5
|
+
from ManyQt.QtWidgets import QMainWindow, QVBoxLayout, QWidget, QLabel, QPushButton, QApplication
|
|
6
|
+
from ManyQt.QtCore import pyqtSlot, Qt
|
|
7
|
+
from ManyQt.QtGui import QColor
|
|
8
|
+
from os.path import dirname
|
|
9
|
+
from random import randint
|
|
10
|
+
from sys import path
|
|
11
|
+
|
|
12
|
+
if not __package__ and dirname(__file__) not in path:
|
|
13
|
+
path.append(dirname(__file__))
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from .colorswatches import ColorSwatchesWidget
|
|
17
|
+
except:
|
|
18
|
+
from colorswatches import ColorSwatchesWidget
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MainWindow(QMainWindow):
|
|
22
|
+
"""
|
|
23
|
+
MainWindow class.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, *args, **kwargs):
|
|
27
|
+
"""
|
|
28
|
+
:param args: any
|
|
29
|
+
:param kwargs: any
|
|
30
|
+
"""
|
|
31
|
+
super(MainWindow, self).__init__(*args, **kwargs)
|
|
32
|
+
self.setWindowTitle(self.tr(u'ColorSwatches demo'))
|
|
33
|
+
self.resize(420, 260)
|
|
34
|
+
self.__m_swatches = ColorSwatchesWidget(colors=['#E01020', '#1E5AD7', '#2AA845', '#F2C12E'], maxColors=24,
|
|
35
|
+
colorClicked=self.onColorClicked) # type: ColorSwatchesWidget
|
|
36
|
+
self.__m_info = QLabel(self.tr(u'Click a swatch to copy its HEX code, right-click to remove it.'))
|
|
37
|
+
add = QPushButton(self.tr(u'Add a random color')) # type: QPushButton
|
|
38
|
+
add.clicked.connect(lambda: self.__m_swatches.addColor(QColor(randint(0, 255), randint(0, 255),
|
|
39
|
+
randint(0, 255))))
|
|
40
|
+
wdg = QWidget() # type: QWidget
|
|
41
|
+
layout = QVBoxLayout(wdg) # type: QVBoxLayout
|
|
42
|
+
layout.addWidget(add)
|
|
43
|
+
layout.addWidget(self.__m_swatches)
|
|
44
|
+
layout.addWidget(self.__m_info)
|
|
45
|
+
layout.addStretch(1)
|
|
46
|
+
self.setCentralWidget(wdg)
|
|
47
|
+
|
|
48
|
+
@pyqtSlot(QColor)
|
|
49
|
+
@pyqtSlot(Qt.GlobalColor)
|
|
50
|
+
@pyqtSlot(int)
|
|
51
|
+
@pyqtSlot(str)
|
|
52
|
+
@pyqtSlot('QString')
|
|
53
|
+
def onColorClicked(self, color):
|
|
54
|
+
"""
|
|
55
|
+
:param color: QColor | Qt.GlobalColor | int | str | QString
|
|
56
|
+
:return:
|
|
57
|
+
"""
|
|
58
|
+
color = color if isinstance(color, QColor) else QColor(color) # type: QColor
|
|
59
|
+
QApplication.clipboard().setText(u'{}'.format(color.name()).upper())
|
|
60
|
+
self.__m_info.setText(self.tr(u'Copied {}').format(u'{}'.format(color.name()).upper()))
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
ControlPanel: live settings for the magnifier (zoom, upscaling method, sharpening, frame rate, overlays).
|
|
4
|
+
"""
|
|
5
|
+
from ManyQt.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QSlider, QComboBox, QFrame, \
|
|
6
|
+
QCheckBox, QPushButton, QScrollArea
|
|
7
|
+
from ManyQt.QtCore import Qt, pyqtSlot
|
|
8
|
+
from os.path import dirname
|
|
9
|
+
from math import log, exp
|
|
10
|
+
from sys import path
|
|
11
|
+
|
|
12
|
+
if not __package__ and dirname(__file__) not in path:
|
|
13
|
+
path.append(dirname(__file__))
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from .magnifierview import MagnifierViewWidget
|
|
17
|
+
from .screengrabber import ScreenGrabber
|
|
18
|
+
from .upscaler import Upscaler
|
|
19
|
+
except:
|
|
20
|
+
from magnifierview import MagnifierViewWidget
|
|
21
|
+
from screengrabber import ScreenGrabber
|
|
22
|
+
from upscaler import Upscaler
|
|
23
|
+
|
|
24
|
+
PANEL_QSS = """
|
|
25
|
+
QWidget#panelContent { background: transparent; }
|
|
26
|
+
QLabel[role="title"] { color: #9AA3B8; font-size: 10px; font-weight: bold; letter-spacing: 1px;
|
|
27
|
+
padding-top: 10px; }
|
|
28
|
+
QLabel[role="value"] { color: #E8EBF2; font-weight: bold; }
|
|
29
|
+
QLabel[role="hint"] { color: #7C8498; font-size: 10px; }
|
|
30
|
+
QPushButton[role="preset"] { padding: 4px 0; min-width: 34px; }
|
|
31
|
+
""" # type: str
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ControlPanel(QScrollArea):
|
|
35
|
+
"""
|
|
36
|
+
ControlPanel class: one row per option, bound to the view, the upscaler and the grabber.
|
|
37
|
+
"""
|
|
38
|
+
ZOOM_STEPS = 1000 # type: int
|
|
39
|
+
|
|
40
|
+
def __init__(self, *args, **kwargs):
|
|
41
|
+
"""
|
|
42
|
+
:param view: MagnifierViewWidget
|
|
43
|
+
:param upscaler: Upscaler
|
|
44
|
+
:param grabber: ScreenGrabber
|
|
45
|
+
:param args: any
|
|
46
|
+
:param kwargs: any
|
|
47
|
+
"""
|
|
48
|
+
view = kwargs.pop('view', None) # type: MagnifierViewWidget
|
|
49
|
+
upscaler = kwargs.pop('upscaler', None) # type: Upscaler
|
|
50
|
+
grabber = kwargs.pop('grabber', None) # type: ScreenGrabber
|
|
51
|
+
super(ControlPanel, self).__init__(*args, **kwargs)
|
|
52
|
+
self.__m_view = view # type: MagnifierViewWidget
|
|
53
|
+
self.__m_upscaler = upscaler # type: Upscaler
|
|
54
|
+
self.__m_grabber = grabber # type: ScreenGrabber
|
|
55
|
+
self.setWidgetResizable(True)
|
|
56
|
+
self.setFrameShape(QFrame.NoFrame)
|
|
57
|
+
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
58
|
+
self.setMinimumWidth(250)
|
|
59
|
+
content = QWidget() # type: QWidget
|
|
60
|
+
content.setObjectName('panelContent')
|
|
61
|
+
content.setStyleSheet(PANEL_QSS)
|
|
62
|
+
self.__m_layout = QVBoxLayout(content) # type: QVBoxLayout
|
|
63
|
+
self.__m_layout.setContentsMargins(14, 6, 14, 14)
|
|
64
|
+
self.__m_layout.setSpacing(6)
|
|
65
|
+
self._buildZoom()
|
|
66
|
+
self._buildUpscaling()
|
|
67
|
+
self._buildCapture()
|
|
68
|
+
self._buildOverlays()
|
|
69
|
+
self.__m_layout.addStretch(1)
|
|
70
|
+
self.setWidget(content)
|
|
71
|
+
view.zoomChanged.connect(self._syncZoom)
|
|
72
|
+
self._syncZoom(view.getZoom())
|
|
73
|
+
|
|
74
|
+
# ---------- Helpers ----------
|
|
75
|
+
@staticmethod
|
|
76
|
+
def _label(text, role):
|
|
77
|
+
"""
|
|
78
|
+
:param text: str | unicode | QString
|
|
79
|
+
:param role: (str | unicode | QString)title | value | hint
|
|
80
|
+
:return: QLabel
|
|
81
|
+
"""
|
|
82
|
+
lbl = QLabel(text) # type: QLabel
|
|
83
|
+
lbl.setProperty('role', role)
|
|
84
|
+
return lbl
|
|
85
|
+
|
|
86
|
+
def _row(self, title, valueLabel):
|
|
87
|
+
"""
|
|
88
|
+
:param title: str | unicode | QString
|
|
89
|
+
:param valueLabel: QLabel
|
|
90
|
+
:return:
|
|
91
|
+
"""
|
|
92
|
+
row = QHBoxLayout() # type: QHBoxLayout
|
|
93
|
+
row.addWidget(ControlPanel._label(title.upper(), 'title'))
|
|
94
|
+
row.addStretch(1)
|
|
95
|
+
valueLabel.setProperty('role', 'value')
|
|
96
|
+
valueLabel.setAlignment(Qt.AlignRight | Qt.AlignBottom)
|
|
97
|
+
row.addWidget(valueLabel)
|
|
98
|
+
self.__m_layout.addLayout(row)
|
|
99
|
+
|
|
100
|
+
def _zoomToSlider(self, zoom):
|
|
101
|
+
"""
|
|
102
|
+
Logarithmic mapping so that 1x..2x gets as much travel as 16x..32x.
|
|
103
|
+
:param zoom: float | int
|
|
104
|
+
:return: int
|
|
105
|
+
"""
|
|
106
|
+
lo, hi = log(self.__m_view.getMinZoom()), log(self.__m_view.getMaxZoom()) # type: float, float
|
|
107
|
+
return int(round((log(max(zoom, 1e-3)) - lo) / (hi - lo) * ControlPanel.ZOOM_STEPS))
|
|
108
|
+
|
|
109
|
+
def _sliderToZoom(self, value):
|
|
110
|
+
"""
|
|
111
|
+
:param value: int
|
|
112
|
+
:return: float | int
|
|
113
|
+
"""
|
|
114
|
+
lo, hi = log(self.__m_view.getMinZoom()), log(self.__m_view.getMaxZoom()) # type: float, float
|
|
115
|
+
return exp(lo + (hi - lo) * value / float(ControlPanel.ZOOM_STEPS))
|
|
116
|
+
|
|
117
|
+
def _buildZoom(self):
|
|
118
|
+
"""
|
|
119
|
+
:return:
|
|
120
|
+
"""
|
|
121
|
+
self.__m_zoomValue = QLabel() # type: QLabel
|
|
122
|
+
self._row(self.tr(u'Magnification'), self.__m_zoomValue)
|
|
123
|
+
self.__m_zoomSlider = QSlider(Qt.Horizontal) # type: QSlider
|
|
124
|
+
self.__m_zoomSlider.setRange(0, ControlPanel.ZOOM_STEPS)
|
|
125
|
+
self.__m_zoomSlider.valueChanged.connect(lambda v: self.__m_view.setZoom(self._sliderToZoom(v)))
|
|
126
|
+
self.__m_layout.addWidget(self.__m_zoomSlider)
|
|
127
|
+
presets = QGridLayout() # type: QGridLayout
|
|
128
|
+
presets.setSpacing(4)
|
|
129
|
+
for i, z in enumerate((1, 2, 4, 8, 16)):
|
|
130
|
+
btn = QPushButton('{}\u00d7'.format(z)) # type: QPushButton
|
|
131
|
+
btn.setProperty('role', 'preset')
|
|
132
|
+
btn.setFocusPolicy(Qt.NoFocus)
|
|
133
|
+
btn.clicked.connect(lambda checked=False, zz=z: self.__m_view.setZoom(zz))
|
|
134
|
+
presets.addWidget(btn, 0, i)
|
|
135
|
+
fit = QPushButton(self.tr(u'Fit region')) # type: QPushButton
|
|
136
|
+
fit.setFocusPolicy(Qt.NoFocus)
|
|
137
|
+
fit.clicked.connect(self.__m_view.fitToView)
|
|
138
|
+
presets.addWidget(fit, 1, 0, 1, 5)
|
|
139
|
+
self.__m_layout.addLayout(presets)
|
|
140
|
+
|
|
141
|
+
def _buildUpscaling(self):
|
|
142
|
+
"""
|
|
143
|
+
:return:
|
|
144
|
+
"""
|
|
145
|
+
self.__m_methodTime = QLabel() # type: QLabel
|
|
146
|
+
self._row(self.tr(u'Upscaling'), self.__m_methodTime)
|
|
147
|
+
self.__m_method = QComboBox() # type: QComboBox
|
|
148
|
+
for method, name in self.__m_upscaler.availableMethods():
|
|
149
|
+
self.__m_method.addItem(self.tr(name), int(method))
|
|
150
|
+
self.__m_method.setCurrentIndex(max(0, self.__m_method.findData(int(self.__m_upscaler.getMethod()))))
|
|
151
|
+
self.__m_method.currentIndexChanged.connect(
|
|
152
|
+
lambda i: self.__m_upscaler.setMethod(int(self.__m_method.itemData(i))))
|
|
153
|
+
self.__m_layout.addWidget(self.__m_method)
|
|
154
|
+
missing = [] # type: list[str]
|
|
155
|
+
if not Upscaler.hasOpenCV():
|
|
156
|
+
missing.append(self.tr(u'Install numpy + opencv-python for Bicubic, Lanczos and sharpening.'))
|
|
157
|
+
elif not Upscaler.hasSuperRes():
|
|
158
|
+
missing.append(self.tr(u'Install opencv-contrib-python for AI super-resolution.'))
|
|
159
|
+
for text in missing:
|
|
160
|
+
hint = ControlPanel._label(text, 'hint') # type: QLabel
|
|
161
|
+
hint.setWordWrap(True)
|
|
162
|
+
self.__m_layout.addWidget(hint)
|
|
163
|
+
self.__m_sharpValue = QLabel() # type: QLabel
|
|
164
|
+
self._row(self.tr(u'Sharpen'), self.__m_sharpValue)
|
|
165
|
+
sharp = QSlider(Qt.Horizontal) # type: QSlider
|
|
166
|
+
sharp.setRange(0, 200)
|
|
167
|
+
sharp.setEnabled(Upscaler.hasOpenCV())
|
|
168
|
+
sharp.valueChanged.connect(self._setSharpness)
|
|
169
|
+
sharp.setValue(int(round(self.__m_upscaler.getSharpness() * 100)))
|
|
170
|
+
self._setSharpness(sharp.value())
|
|
171
|
+
self.__m_layout.addWidget(sharp)
|
|
172
|
+
|
|
173
|
+
def _buildCapture(self):
|
|
174
|
+
"""
|
|
175
|
+
:return:
|
|
176
|
+
"""
|
|
177
|
+
self.__m_fpsValue = QLabel() # type: QLabel
|
|
178
|
+
self._row(self.tr(u'Frame rate'), self.__m_fpsValue)
|
|
179
|
+
fps = QSlider(Qt.Horizontal) # type: QSlider
|
|
180
|
+
fps.setRange(1, 60)
|
|
181
|
+
fps.valueChanged.connect(self._setFps)
|
|
182
|
+
fps.setValue(self.__m_grabber.getFps())
|
|
183
|
+
self._setFps(fps.value())
|
|
184
|
+
self.__m_layout.addWidget(fps)
|
|
185
|
+
|
|
186
|
+
def _buildOverlays(self):
|
|
187
|
+
"""
|
|
188
|
+
:return:
|
|
189
|
+
"""
|
|
190
|
+
self.__m_layout.addWidget(ControlPanel._label(self.tr(u'OVERLAYS'), 'title'))
|
|
191
|
+
v = self.__m_view # type: MagnifierViewWidget
|
|
192
|
+
for text, getter, setter in ((self.tr(u'Pixel grid (zoom \u2265 10\u00d7)'), v.isShowGrid, v.setShowGrid),
|
|
193
|
+
(self.tr(u'Crosshair'), v.isShowCrosshair, v.setShowCrosshair),
|
|
194
|
+
(self.tr(u'Invert colors'), v.isInvertColors, v.setInvertColors)):
|
|
195
|
+
box = QCheckBox(text) # type: QCheckBox
|
|
196
|
+
box.setChecked(getter())
|
|
197
|
+
box.toggled.connect(setter)
|
|
198
|
+
self.__m_layout.addWidget(box)
|
|
199
|
+
|
|
200
|
+
# ---------- Public API ----------
|
|
201
|
+
def _syncZoom(self, zoom):
|
|
202
|
+
"""
|
|
203
|
+
:param zoom: float | int
|
|
204
|
+
:return:
|
|
205
|
+
"""
|
|
206
|
+
self.__m_zoomValue.setText('{:.2f}\u00d7'.format(zoom))
|
|
207
|
+
self.__m_zoomSlider.blockSignals(True)
|
|
208
|
+
self.__m_zoomSlider.setValue(self._zoomToSlider(zoom))
|
|
209
|
+
self.__m_zoomSlider.blockSignals(False)
|
|
210
|
+
|
|
211
|
+
def _setSharpness(self, value):
|
|
212
|
+
"""
|
|
213
|
+
:param value: (int) 0 .. 200 %
|
|
214
|
+
:return:
|
|
215
|
+
"""
|
|
216
|
+
self.__m_sharpValue.setText('{} %'.format(int(value)))
|
|
217
|
+
self.__m_upscaler.setSharpness(value / 100.0)
|
|
218
|
+
|
|
219
|
+
def _setFps(self, value):
|
|
220
|
+
"""
|
|
221
|
+
:param value: int
|
|
222
|
+
:return:
|
|
223
|
+
"""
|
|
224
|
+
self.__m_fpsValue.setText('{} fps'.format(int(value)))
|
|
225
|
+
self.__m_grabber.setFps(value)
|
|
226
|
+
|
|
227
|
+
@pyqtSlot(float)
|
|
228
|
+
@pyqtSlot(int)
|
|
229
|
+
def showProcessTime(self, ms):
|
|
230
|
+
"""
|
|
231
|
+
:param ms: float | int
|
|
232
|
+
:return:
|
|
233
|
+
"""
|
|
234
|
+
self.__m_methodTime.setText('{:.1f} ms'.format(ms))
|