ScreenMagnifier 1.11.0.post8__py3-none-any.whl

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

Potentially problematic release.


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

Files changed (117) hide show
  1. ScreenMagnifier/__init__.py +68 -0
  2. ScreenMagnifier/__main__.py +17 -0
  3. ScreenMagnifier/advancedoverlay.py +593 -0
  4. ScreenMagnifier/advancedpanel.py +521 -0
  5. ScreenMagnifier/analysiscontroller.py +533 -0
  6. ScreenMagnifier/analysisserver.py +404 -0
  7. ScreenMagnifier/colordetector/__init__.py +28 -0
  8. ScreenMagnifier/colordetector/colordetector.py +570 -0
  9. ScreenMagnifier/colordetector/core.py +434 -0
  10. ScreenMagnifier/colordetector/main.py +23 -0
  11. ScreenMagnifier/colordetector/mainwindow.py +182 -0
  12. ScreenMagnifier/colorpanel.py +424 -0
  13. ScreenMagnifier/colorswatches/__init__.py +16 -0
  14. ScreenMagnifier/colorswatches/colorswatches.py +316 -0
  15. ScreenMagnifier/colorswatches/main.py +23 -0
  16. ScreenMagnifier/colorswatches/mainwindow.py +60 -0
  17. ScreenMagnifier/controlpanel.py +234 -0
  18. ScreenMagnifier/detectionpanel.py +790 -0
  19. ScreenMagnifier/facedetector/__init__.py +24 -0
  20. ScreenMagnifier/facedetector/core.py +314 -0
  21. ScreenMagnifier/facedetector/facedetector.py +288 -0
  22. ScreenMagnifier/facedetector/main.py +23 -0
  23. ScreenMagnifier/facedetector/mainwindow.py +122 -0
  24. ScreenMagnifier/facedetector/models/__init__.py +4 -0
  25. ScreenMagnifier/facepointer.py +1121 -0
  26. ScreenMagnifier/features.py +50 -0
  27. ScreenMagnifier/hotkeys/__init__.py +16 -0
  28. ScreenMagnifier/hotkeys/hotkeys.py +379 -0
  29. ScreenMagnifier/hotkeys/main.py +23 -0
  30. ScreenMagnifier/hotkeys/mainwindow.py +56 -0
  31. ScreenMagnifier/imagefilters/__init__.py +24 -0
  32. ScreenMagnifier/imagefilters/core.py +172 -0
  33. ScreenMagnifier/imagefilters/imagefilters.py +220 -0
  34. ScreenMagnifier/imagefilters/main.py +23 -0
  35. ScreenMagnifier/imagefilters/mainwindow.py +120 -0
  36. ScreenMagnifier/magnifierview/__init__.py +16 -0
  37. ScreenMagnifier/magnifierview/magnifierview.py +1249 -0
  38. ScreenMagnifier/magnifierview/main.py +23 -0
  39. ScreenMagnifier/magnifierview/mainwindow.py +91 -0
  40. ScreenMagnifier/main.py +157 -0
  41. ScreenMagnifier/mainwindow.py +1368 -0
  42. ScreenMagnifier/mousecatcher/__init__.py +16 -0
  43. ScreenMagnifier/mousecatcher/main.py +23 -0
  44. ScreenMagnifier/mousecatcher/mainwindow.py +78 -0
  45. ScreenMagnifier/mousecatcher/mousecatcher.py +251 -0
  46. ScreenMagnifier/mousemove.py +259 -0
  47. ScreenMagnifier/netprotocol/__init__.py +25 -0
  48. ScreenMagnifier/netprotocol/main.py +23 -0
  49. ScreenMagnifier/netprotocol/mainwindow.py +91 -0
  50. ScreenMagnifier/netprotocol/netprotocol.py +372 -0
  51. ScreenMagnifier/netprotocol/wire.py +189 -0
  52. ScreenMagnifier/regionselector/__init__.py +16 -0
  53. ScreenMagnifier/regionselector/main.py +23 -0
  54. ScreenMagnifier/regionselector/mainwindow.py +70 -0
  55. ScreenMagnifier/regionselector/regionselector.py +549 -0
  56. ScreenMagnifier/remoteclient.py +636 -0
  57. ScreenMagnifier/resources/icon-128.png +0 -0
  58. ScreenMagnifier/resources/icon-16.png +0 -0
  59. ScreenMagnifier/resources/icon-24.png +0 -0
  60. ScreenMagnifier/resources/icon-256.png +0 -0
  61. ScreenMagnifier/resources/icon-32.png +0 -0
  62. ScreenMagnifier/resources/icon-48.png +0 -0
  63. ScreenMagnifier/resources/icon-512.png +0 -0
  64. ScreenMagnifier/resources/icon-64.png +0 -0
  65. ScreenMagnifier/resources/icon.icns +0 -0
  66. ScreenMagnifier/resources/icon.ico +0 -0
  67. ScreenMagnifier/screengrabber/__init__.py +16 -0
  68. ScreenMagnifier/screengrabber/main.py +23 -0
  69. ScreenMagnifier/screengrabber/mainwindow.py +79 -0
  70. ScreenMagnifier/screengrabber/screengrabber.py +558 -0
  71. ScreenMagnifier/server.py +150 -0
  72. ScreenMagnifier/serverpanel.py +379 -0
  73. ScreenMagnifier/shortcuteditor/__init__.py +16 -0
  74. ScreenMagnifier/shortcuteditor/main.py +23 -0
  75. ScreenMagnifier/shortcuteditor/mainwindow.py +54 -0
  76. ScreenMagnifier/shortcuteditor/shortcuteditor.py +411 -0
  77. ScreenMagnifier/shortcuts.py +118 -0
  78. ScreenMagnifier/shortcutspanel.py +140 -0
  79. ScreenMagnifier/support.py +127 -0
  80. ScreenMagnifier/translations/ar.json +387 -0
  81. ScreenMagnifier/translations/de.json +387 -0
  82. ScreenMagnifier/translations/es.json +387 -0
  83. ScreenMagnifier/translations/fr.json +387 -0
  84. ScreenMagnifier/translations/it.json +387 -0
  85. ScreenMagnifier/translations/ja.json +387 -0
  86. ScreenMagnifier/translations/ko.json +387 -0
  87. ScreenMagnifier/translations/pt_BR.json +387 -0
  88. ScreenMagnifier/translations/ru.json +387 -0
  89. ScreenMagnifier/translations/tr.json +387 -0
  90. ScreenMagnifier/translations/zh_CN.json +387 -0
  91. ScreenMagnifier/translator/__init__.py +16 -0
  92. ScreenMagnifier/translator/main.py +23 -0
  93. ScreenMagnifier/translator/mainwindow.py +62 -0
  94. ScreenMagnifier/translator/translator.py +284 -0
  95. ScreenMagnifier/upscaler/__init__.py +24 -0
  96. ScreenMagnifier/upscaler/core.py +315 -0
  97. ScreenMagnifier/upscaler/main.py +23 -0
  98. ScreenMagnifier/upscaler/mainwindow.py +128 -0
  99. ScreenMagnifier/upscaler/models/FSRCNN-small_x2.pb +0 -0
  100. ScreenMagnifier/upscaler/models/FSRCNN-small_x3.pb +0 -0
  101. ScreenMagnifier/upscaler/models/FSRCNN-small_x4.pb +0 -0
  102. ScreenMagnifier/upscaler/models/FSRCNN_x2.pb +0 -0
  103. ScreenMagnifier/upscaler/models/FSRCNN_x3.pb +0 -0
  104. ScreenMagnifier/upscaler/models/FSRCNN_x4.pb +0 -0
  105. ScreenMagnifier/upscaler/models/LICENSE-FSRCNN +201 -0
  106. ScreenMagnifier/upscaler/models/__init__.py +4 -0
  107. ScreenMagnifier/upscaler/upscaler.py +285 -0
  108. ScreenMagnifier/wincheck.py +65 -0
  109. ScreenMagnifier/zoomoverlay/__init__.py +16 -0
  110. ScreenMagnifier/zoomoverlay/main.py +23 -0
  111. ScreenMagnifier/zoomoverlay/mainwindow.py +99 -0
  112. ScreenMagnifier/zoomoverlay/zoomoverlay.py +1779 -0
  113. screenmagnifier-1.11.0.post8.dist-info/METADATA +591 -0
  114. screenmagnifier-1.11.0.post8.dist-info/RECORD +117 -0
  115. screenmagnifier-1.11.0.post8.dist-info/WHEEL +5 -0
  116. screenmagnifier-1.11.0.post8.dist-info/entry_points.txt +5 -0
  117. screenmagnifier-1.11.0.post8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,424 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ColorPickerPanel: the Colors tab - color code of the pixel under the mouse in 13 formats, one-click copy to the
4
+ clipboard, averaged sampling, copy history, and the WCAG contrast checker. Every setting and the history are
5
+ saved with QSettings.
6
+ Ways to copy (wired by the MainWindow): C key, right-click menu of the magnifier (every format), optional left
7
+ click in the magnifier, the zoomer color code and screen color picker hotkeys, or the Copy buttons of this tab.
8
+ """
9
+ from ManyQt.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QComboBox, QCheckBox, QFrame, \
10
+ QMenu, QPushButton, QScrollArea
11
+ from ManyQt.QtCore import Qt, QSettings, pyqtSignal, pyqtSlot, pyqtProperty
12
+ from ManyQt.QtGui import QColor, QPixmap, QFont, QGuiApplication
13
+ from os.path import dirname
14
+ from sys import path
15
+
16
+ if not __package__ and dirname(__file__) not in path:
17
+ path.append(dirname(__file__))
18
+
19
+ try:
20
+ from .colordetector import COLOR_FORMATS, formatColor, nearestColorName, contrastRatio, wcagRating
21
+ from .colorswatches import ColorSwatchesWidget
22
+ except:
23
+ from colordetector import COLOR_FORMATS, formatColor, nearestColorName, contrastRatio, wcagRating
24
+ from colorswatches import ColorSwatchesWidget
25
+
26
+ PANEL_QSS = """
27
+ QWidget#colorContent { background: transparent; }
28
+ QLabel[role="title"] { color: #9AA3B8; font-size: 10px; font-weight: bold; letter-spacing: 1px; padding-top: 10px; }
29
+ QLabel[role="hint"] { color: #7C8498; font-size: 10px; }
30
+ QLabel[role="name"] { color: #9AA3B8; }
31
+ QLabel[role="mono"] { color: #E8EBF2; font-family: monospace; }
32
+ QLabel[role="big"] { color: #E8EBF2; font-size: 16px; font-weight: bold; font-family: monospace; }
33
+ QPushButton[role="small"] { padding: 2px 8px; }
34
+ """ # type: str
35
+ PICK_SOURCES = [('zoomed', 'Zoomed image (what you see)'), ('original', 'Original screen pixel')] # type: list
36
+ SAMPLE_SIZES = [(1, '1 pixel'), (3, '3 x 3 average'), (5, '5 x 5 average'), (9, '9 x 9 average')] # type: list
37
+
38
+
39
+ class ColorPickerPanel(QScrollArea):
40
+ """
41
+ ColorPickerPanel class.
42
+ """
43
+ colorCopied = pyqtSignal(QColor, 'QString') # type: pyqtSignal # color, copied text
44
+ optionsChanged = pyqtSignal() # type: pyqtSignal # format / pick source / sample size changed
45
+ notify = pyqtSignal('QString') # type: pyqtSignal
46
+
47
+ def __init__(self, *args, **kwargs):
48
+ """
49
+ :param settings: (QSettings | None) None = ScreenMagnifier / ColorPicker.
50
+ :param colorCopied: callable | None
51
+ :param args: any
52
+ :param kwargs: any
53
+ """
54
+ settings = kwargs.pop('settings', None) # type: QSettings | None
55
+ colorCopied = kwargs.pop('colorCopied', None) # type: callable | None
56
+ super(ColorPickerPanel, self).__init__(*args, **kwargs)
57
+ if callable(colorCopied):
58
+ self.colorCopied.connect(colorCopied)
59
+ self.__m_settings = settings if settings is not None else QSettings('ScreenMagnifier', 'ColorPicker')
60
+ self.__m_color = QColor() # type: QColor
61
+ self.__m_liveSource = '' # type: str # 'magnifier', 'zoomer' or 'picker'
62
+ self.__m_liveZone = '' # type: str
63
+ self.__m_reference = None # type: QColor | None
64
+ self.__m_values = {} # type: dict # format key -> value QLabel
65
+ self.__m_loading = False # type: bool
66
+ self.setWidgetResizable(True)
67
+ self.setFrameShape(QFrame.NoFrame)
68
+ self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
69
+ self.setMinimumWidth(260)
70
+ content = QWidget() # type: QWidget
71
+ content.setObjectName('colorContent')
72
+ content.setStyleSheet(PANEL_QSS)
73
+ self.__m_layout = QVBoxLayout(content) # type: QVBoxLayout
74
+ self.__m_layout.setContentsMargins(14, 6, 14, 14)
75
+ self.__m_layout.setSpacing(6)
76
+ self._build()
77
+ self.__m_layout.addStretch(1)
78
+ self.setWidget(content)
79
+ self._load()
80
+ self.setCurrentColor(QColor())
81
+
82
+ # ---------- Building ----------
83
+ @staticmethod
84
+ def _label(text, role):
85
+ """
86
+ :param text: str | unicode | QString
87
+ :param role: str | unicode | QString
88
+ :return: QLabel
89
+ """
90
+ lbl = QLabel(text) # type: QLabel
91
+ lbl.setProperty('role', role)
92
+ lbl.setWordWrap(role == 'hint')
93
+ return lbl
94
+
95
+ @staticmethod
96
+ def _button(text, slot, tip=''):
97
+ """
98
+ :param text: str | unicode | QString
99
+ :param slot: callable
100
+ :param tip: str | unicode | QString
101
+ :return: QPushButton
102
+ """
103
+ b = QPushButton(text) # type: QPushButton
104
+ b.setProperty('role', 'small')
105
+ b.setFocusPolicy(Qt.NoFocus)
106
+ b.setToolTip(tip)
107
+ b.clicked.connect(slot)
108
+ return b
109
+
110
+ def _build(self):
111
+ """
112
+ :return:
113
+ """
114
+ lay = self.__m_layout # type: QVBoxLayout
115
+ lay.addWidget(ColorPickerPanel._label(self.tr(u'LIVE COLOR'), 'title'))
116
+ self.__m_sourceLabel = ColorPickerPanel._label('', 'hint') # type: QLabel # where the color comes from
117
+ lay.addWidget(self.__m_sourceLabel)
118
+ head = QHBoxLayout() # type: QHBoxLayout
119
+ self.__m_swatch = QLabel() # type: QLabel
120
+ self.__m_swatch.setFixedSize(52, 52)
121
+ head.addWidget(self.__m_swatch)
122
+ names = QVBoxLayout() # type: QVBoxLayout
123
+ self.__m_hex = ColorPickerPanel._label('', 'big') # type: QLabel
124
+ self.__m_hex.setTextInteractionFlags(Qt.TextSelectableByMouse)
125
+ self.__m_name = ColorPickerPanel._label('', 'name') # type: QLabel
126
+ names.addWidget(self.__m_hex)
127
+ names.addWidget(self.__m_name)
128
+ self.__m_zoneLabel = ColorPickerPanel._label('', 'name') # type: QLabel
129
+ names.addWidget(self.__m_zoneLabel)
130
+ head.addLayout(names, 1)
131
+ head.addWidget(
132
+ self._button(self.tr(u'Copy'), lambda: self.copyColor(), self.tr(u'Copy in the default format (C)')))
133
+ lay.addLayout(head)
134
+ grid = QGridLayout() # type: QGridLayout
135
+ grid.setHorizontalSpacing(8)
136
+ grid.setVerticalSpacing(3)
137
+ for row, (key, label) in enumerate(COLOR_FORMATS):
138
+ value = ColorPickerPanel._label('-', 'mono') # type: QLabel
139
+ value.setTextInteractionFlags(Qt.TextSelectableByMouse)
140
+ self.__m_values[key] = value
141
+ grid.addWidget(ColorPickerPanel._label(self.tr(label), 'name'), row, 0)
142
+ grid.addWidget(value, row, 1)
143
+ grid.addWidget(self._button(self.tr(u'Copy'), lambda checked=False, k=key: self.copyColor(fmt=k),
144
+ self.tr(u'Copy as {}').format(self.tr(label))), row, 2)
145
+ grid.setColumnStretch(1, 1)
146
+ lay.addLayout(grid)
147
+ lay.addWidget(self._button(self.tr(u'Copy all formats'), self.copyAllFormats,
148
+ self.tr(u'Copy every format, one per line')))
149
+ lay.addWidget(ColorPickerPanel._label(self.tr(u'OPTIONS'), 'title'))
150
+ lay.addWidget(QLabel(self.tr(u'Default format (C key, click, global hotkey)')))
151
+ self.__m_format = QComboBox() # type: QComboBox
152
+ for key, label in COLOR_FORMATS:
153
+ self.__m_format.addItem(self.tr(label), key)
154
+ self.__m_format.currentIndexChanged.connect(lambda *a: (self._save(), self.setCurrentColor(self.__m_color)))
155
+ lay.addWidget(self.__m_format)
156
+ lay.addWidget(QLabel(self.tr(u'Pick from')))
157
+ self.__m_source = QComboBox() # type: QComboBox
158
+ for key, label in PICK_SOURCES:
159
+ self.__m_source.addItem(self.tr(label), key)
160
+ self.__m_source.setToolTip(self.tr(u'Zoomed: the color as displayed after upscaling / sharpening. Original: '
161
+ 'the untouched screen pixel.'))
162
+ self.__m_source.currentIndexChanged.connect(lambda *a: self._save())
163
+ lay.addWidget(self.__m_source)
164
+ lay.addWidget(QLabel(self.tr(u'Sample')))
165
+ self.__m_sample = QComboBox() # type: QComboBox
166
+ for size, label in SAMPLE_SIZES:
167
+ self.__m_sample.addItem(self.tr(label), size)
168
+ self.__m_sample.setToolTip(self.tr(u'Average a small square: steadier on anti-aliased text and textures'))
169
+ self.__m_sample.currentIndexChanged.connect(lambda *a: self._save())
170
+ lay.addWidget(self.__m_sample)
171
+ self.__m_copyOnClick = QCheckBox(self.tr(u'Copy on left click in the magnifier')) # type: QCheckBox
172
+ self.__m_copyOnClick.toggled.connect(lambda *a: self._save())
173
+ lay.addWidget(self.__m_copyOnClick)
174
+ lay.addWidget(ColorPickerPanel._label(self.tr(u'CONTRAST (WCAG)'), 'title'))
175
+ lay.addWidget(self._button(self.tr(u'Set as reference'), self._setReference,
176
+ self.tr(u'Then hover another color to see the contrast ratio')))
177
+ self.__m_contrast = ColorPickerPanel._label(self.tr(u'Set a reference color first.'), 'hint') # type: QLabel
178
+ lay.addWidget(self.__m_contrast)
179
+ lay.addWidget(ColorPickerPanel._label(self.tr(u'HISTORY'), 'title'))
180
+ self.__m_history = ColorSwatchesWidget(maxColors=32, swatchSize=24, placeholderText=self.tr(
181
+ 'Copied colors appear here'), colorClicked=lambda c: self.copyColor(c)) # type: ColorSwatchesWidget
182
+ self.__m_history.colorsChanged.connect(self._save)
183
+ lay.addWidget(self.__m_history)
184
+ row = QHBoxLayout() # type: QHBoxLayout
185
+ row.addWidget(self._button(self.tr(u'Copy history'), self.copyHistory,
186
+ self.tr(u'Copy every color of the history, one per line')))
187
+ row.addWidget(self._button(self.tr(u'Clear'), self.__m_history.clear))
188
+ lay.addLayout(row)
189
+ lay.addWidget(ColorPickerPanel._label(self.tr(
190
+ u'These options apply to every way of copying: the magnifier eyedropper and C key, its right-click menu, '
191
+ u'the zoomer color code and the screen color picker (shortcuts: Shortcuts tab). Click a history swatch '
192
+ u'to copy it again, right-click to remove it.'), 'hint'))
193
+
194
+ # ---------- Settings ----------
195
+ def _load(self):
196
+ """
197
+ :return:
198
+ """
199
+ self.__m_loading = True # type: bool
200
+ s = self.__m_settings # type: QSettings
201
+ self.__m_format.setCurrentIndex(max(0, self.__m_format.findData(u'{}'.format(s.value('format', 'hex')))))
202
+ self.__m_sample.setCurrentIndex(max(0, self.__m_sample.findData(int(s.value('sample', 1)))))
203
+ self.__m_source.setCurrentIndex(max(0, self.__m_source.findData(u'{}'.format(s.value('pickSource', 'zoomed')))))
204
+ self.__m_copyOnClick.setChecked(u'{}'.format(s.value('copyOnClick', False)).lower() in ('1', 'true', 'yes'))
205
+ history = s.value('history', '') or ''
206
+ if isinstance(history, (list, tuple)):
207
+ history = ','.join(u'{}'.format(h) for h in history)
208
+ self.__m_history.setColors([h for h in u'{}'.format(history).split(',') if QColor(h).isValid()])
209
+ self.__m_loading = False # type: bool
210
+
211
+ @pyqtSlot()
212
+ def _save(self):
213
+ """
214
+ :return:
215
+ """
216
+ if self.__m_loading:
217
+ return
218
+ s = self.__m_settings # type: QSettings
219
+ s.setValue('format', self.__m_format.currentData())
220
+ s.setValue('sample', self.__m_sample.currentData())
221
+ s.setValue('pickSource', self.__m_source.currentData())
222
+ self.optionsChanged.emit()
223
+ s.setValue('copyOnClick', self.__m_copyOnClick.isChecked())
224
+ s.setValue('history', ','.join(u'{}'.format(c.name()) for c in self.__m_history.getColors()))
225
+
226
+ # ---------- Helpers ----------
227
+ def _setReference(self):
228
+ """
229
+ :return:
230
+ """
231
+ if self.__m_color.isValid():
232
+ self.__m_reference = QColor(self.__m_color) # type: QColor
233
+ self._updateContrast()
234
+
235
+ def _updateContrast(self):
236
+ """
237
+ :return:
238
+ """
239
+ ref, cur = self.__m_reference, self.__m_color
240
+ if ref is None or not cur.isValid():
241
+ return
242
+ ratio = contrastRatio(ref, cur) # type: float
243
+ self.__m_contrast.setText(self.tr(u'{} on {}: {:.2f} : 1 ({})').format(
244
+ formatColor(cur), formatColor(ref), ratio, wcagRating(ratio)))
245
+
246
+ # ---------- Public API ----------
247
+ def formatCode(self, color):
248
+ """
249
+ THE text of a color code everywhere (Colors tab, zoomer, eyedropper bubble): the default copy format, so
250
+ the code shown is always the code copied.
251
+ :param color: QColor
252
+ :return: str | unicode | QString
253
+ """
254
+ return formatColor(color, self.getDefaultFormat())
255
+
256
+ def colorName(self, color):
257
+ """
258
+ THE color name everywhere (Colors tab and zoomer).
259
+ :param color: QColor
260
+ :return: (str | unicode | QString) 'name' (exact) or 'close to name'.
261
+ """
262
+ name, de = nearestColorName(color)
263
+ return name if de < 1.0 else self.tr(u'close to {}').format(name)
264
+
265
+ def setLiveColor(self, color, source='', zone=''):
266
+ """
267
+ Show the live color: the one the user points at, wherever it comes from.
268
+ :param color: QColor
269
+ :param source: (str | unicode | QString) 'magnifier' (mouse), 'zoomer' (crosshair) or 'picker' (screen color picker).
270
+ :param zone: (str | unicode | QString) Color zone the color is in ('' = none).
271
+ :return:
272
+ """
273
+ self.__m_color = QColor(color) if color is not None else QColor() # type: QColor
274
+ self.__m_liveSource, self.__m_liveZone = u'{}'.format(source), u'{}'.format(zone) # type: str, str
275
+ pm = QPixmap(52, 52) # type: QPixmap
276
+ pm.fill(self.__m_color if self.__m_color.isValid() else QColor('#22252E'))
277
+ self.__m_swatch.setPixmap(pm)
278
+ valid = self.__m_color.isValid() # type: bool
279
+ self.__m_hex.setText(self.formatCode(self.__m_color) if valid else '-')
280
+ self.__m_name.setText(self.colorName(self.__m_color) if valid else self.tr(
281
+ 'Point at a color: magnifier, zoomer or screen color picker'))
282
+ self.__m_zoneLabel.setText(self.tr(u'zone: {}').format(zone) if valid and zone else '')
283
+ exact = u'{}'.format(source) == 'picker' or self.getPickSource() == 'original' # type: bool # picker: pixel-exact
284
+ where = {'magnifier': self.tr(u'from the magnifier (mouse)'), 'zoomer': self.tr(u'from the zoomer (crosshair)'),
285
+ 'picker': self.tr(u'from the screen color picker')}.get(u'{}'.format(source), '') # type: str
286
+ self.__m_sourceLabel.setText(where and where + (self.tr(u' \u00b7 exact screen pixel') if exact else
287
+ self.tr(u' \u00b7 zoomed image (Pick from, below)')))
288
+ for key, value in self.__m_values.items():
289
+ value.setText(formatColor(self.__m_color, key) if valid else '-')
290
+ self._updateContrast()
291
+
292
+ @pyqtSlot(QColor)
293
+ @pyqtSlot(Qt.GlobalColor)
294
+ @pyqtSlot(int)
295
+ @pyqtSlot(str)
296
+ @pyqtSlot('QString')
297
+ def setCurrentColor(self, color):
298
+ """
299
+ :param color: QColor | Qt.GlobalColor | int | str | QString (keeps the current source / zone).
300
+ :return:
301
+ """
302
+ self.setLiveColor(color if isinstance(color, QColor) else QColor(color), self.__m_liveSource, self.__m_liveZone)
303
+
304
+ def getLiveSource(self):
305
+ """
306
+ :return: (str | unicode | QString) 'magnifier', 'zoomer', 'picker' or ''.
307
+ """
308
+ return self.__m_liveSource
309
+
310
+ def getLiveZone(self):
311
+ """
312
+ :return: str | unicode | QString
313
+ """
314
+ return self.__m_liveZone
315
+
316
+ def getCodeText(self):
317
+ """
318
+ :return: (str | unicode | QString) The code shown (and copied) for the live color.
319
+ """
320
+ return self.__m_hex.text()
321
+
322
+ def getCurrentColor(self):
323
+ """
324
+ :return: QColor
325
+ """
326
+ return QColor(self.__m_color)
327
+
328
+ def copyColor(self, color=None, fmt=None):
329
+ """
330
+ Copy a color code to the clipboard, add it to the history and announce it.
331
+ :param color: (QColor | None) None = the current color.
332
+ :param fmt: (str | None) COLOR_FORMATS key; None = the default format.
333
+ :return: (str | unicode | QString) Copied text ('' when there is no color).
334
+ """
335
+ c = QColor(color) if color is not None else QColor(self.__m_color) # type: QColor
336
+ if not c.isValid():
337
+ self.notify.emit(self.tr(u'Hover the magnifier to choose a color first.'))
338
+ return ''
339
+ text = formatColor(c, fmt or self.getDefaultFormat()) # type: str
340
+ QGuiApplication.clipboard().setText(text)
341
+ self.__m_history.addColor(c)
342
+ self.notify.emit(self.tr(u'Copied {}').format(text))
343
+ self.colorCopied.emit(c, text)
344
+ return text
345
+
346
+ @pyqtSlot()
347
+ def copyAllFormats(self):
348
+ """
349
+ :return:
350
+ """
351
+ if self.__m_color.isValid():
352
+ QGuiApplication.clipboard().setText('\n'.join(formatColor(self.__m_color, k) for k, _ in COLOR_FORMATS))
353
+ self.__m_history.addColor(self.__m_color)
354
+ self.notify.emit(self.tr(u'Copied every format of {}').format(formatColor(self.__m_color)))
355
+
356
+ @pyqtSlot()
357
+ def copyHistory(self):
358
+ """
359
+ :return:
360
+ """
361
+ colors = self.__m_history.getColors() # type: list
362
+ if colors:
363
+ QGuiApplication.clipboard().setText('\n'.join(formatColor(c, self.getDefaultFormat()) for c in colors))
364
+ self.notify.emit(self.tr(u'Copied {} colors').format(len(colors)))
365
+
366
+ def buildCopyMenu(self, color, parent=None):
367
+ """
368
+ Context menu offering the color in every format (default format first, in bold).
369
+ :param color: QColor
370
+ :param parent: QWidget | None
371
+ :return: QMenu
372
+ """
373
+ menu = QMenu(parent) # type: QMenu
374
+ title = menu.addAction(self.tr(u'{} {}').format(formatColor(color), nearestColorName(color)[0]))
375
+ title.setEnabled(False)
376
+ menu.addSeparator()
377
+ default = self.getDefaultFormat() # type: str
378
+ keys = [default] + [k for k, _ in COLOR_FORMATS if k != default] # type: list
379
+ labels = dict(COLOR_FORMATS) # type: dict
380
+ for key in keys:
381
+ act = menu.addAction(self.tr(u'Copy {} ({})').format(formatColor(color, key), self.tr(labels[key])))
382
+ act.triggered.connect(lambda checked=False, k=key: self.copyColor(color, k))
383
+ if key == default:
384
+ font = QFont(act.font()) # type: QFont
385
+ font.setBold(True)
386
+ act.setFont(font)
387
+ menu.addSeparator()
388
+ menu.addAction(self.tr(u'Copy all formats'), lambda: (self.setCurrentColor(color), self.copyAllFormats()))
389
+ menu.addAction(self.tr(u'Set as contrast reference'),
390
+ lambda: (self.setCurrentColor(color), self._setReference()))
391
+ return menu
392
+
393
+ def getDefaultFormat(self):
394
+ """
395
+ :return: (str | unicode | QString) COLOR_FORMATS key.
396
+ """
397
+ return u'{}'.format(self.__m_format.currentData() or 'hex')
398
+
399
+ def getPickSource(self):
400
+ """
401
+ :return: (str | unicode | QString) 'zoomed' (color as displayed) or 'original' (screen pixel).
402
+ """
403
+ return u'{}'.format(self.__m_source.currentData() or 'zoomed')
404
+
405
+ def getSampleSize(self):
406
+ """
407
+ :return: (int) 1, 3, 5 or 9.
408
+ """
409
+ return int(self.__m_sample.currentData() or 1)
410
+
411
+ def isCopyOnClick(self):
412
+ """
413
+ :return: bool
414
+ """
415
+ return self.__m_copyOnClick.isChecked()
416
+
417
+ def getHistory(self):
418
+ """
419
+ :return: (list[QColor]) Newest first.
420
+ """
421
+ return self.__m_history.getColors()
422
+
423
+ # ---------- Properties ----------
424
+ currentColor = pyqtProperty(QColor, fget=getCurrentColor, fset=setCurrentColor) # type: pyqtProperty
@@ -0,0 +1,16 @@
1
+ # coding=utf-8
2
+ """
3
+ colorswatches package.
4
+ """
5
+ from os.path import dirname
6
+ from sys import path
7
+
8
+ if not __package__ and dirname(__file__) not in path:
9
+ path.append(dirname(__file__))
10
+
11
+ try:
12
+ from .colorswatches import ColorSwatchesWidget
13
+ except:
14
+ from colorswatches import ColorSwatchesWidget
15
+
16
+ __all__ = ['ColorSwatchesWidget'] # type: list[str]