-
Notifications
You must be signed in to change notification settings - Fork 16
/
gauge.py
723 lines (562 loc) · 25.4 KB
/
gauge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# Sihab Sahariar (Fixed, 2023)
import math
try:
from PyQt4.QtGui import QMainWindow
from PyQt4.QtGui import QWidget
from PyQt4.QtGui import QApplication
from PyQt4.QtGui import QPolygon, QPolygonF, QColor, QPen, QFont
from PyQt4.QtGui import QPainter, QFontMetrics, QConicalGradient
# QtGui -> QPolygon, QPolygonF, QColor, QPen, QFont,
# -> QWidget
# -> QApplication
from PyQt4.QtCore import Qt, QTime, QTimer, QPoint, QPointF, SIGNAL, QRect, QSize
from PyQt4.QtCore import QObject, pyqtSignal
# QtCore -> Qt.NoPen, QTime, QTimer, QPoint, QPointF, QRect, QSize
used_Qt_Version = 4
print("Successful import Qt4 @ gauge.py")
# Antialysing may be problem with Qt4
print("ToDo: Fix error output QPainter.Antialiasing")
except:
try:
# print("Try5: analoggaugewidget.py")
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QApplication
# QtWidgets -> QWidget
# QtWidgets -> QApplication
from PyQt5.QtGui import QPolygon, QPolygonF, QColor, QPen, QFont
from PyQt5.QtGui import QPainter, QFontMetrics, QConicalGradient
# QtGui -> QPolygon, QPolygonF, QColor, QPen, QFont, QPainter, QFontMetrics, QConicalGradient
from PyQt5.QtCore import Qt ,QTime, QTimer, QPoint, QPointF, QRect, QSize
from PyQt5.QtCore import QObject, pyqtSignal
# QtCore -> Qt.NoPen ,QTime, QTimer, QPoint, QPointF, QRect, QSize
used_Qt_Version = 5
print("Successful import Qt5 @ gauge.py")
except:
print("Error Import Qt 4 & 5 @ analoggaugewidget.py")
exit()
class AnalogGaugeWidget(QWidget):
"""Fetches rows from a Bigtable.
Args:
none
"""
valueChanged = pyqtSignal(int)
def __init__(self, parent=None):
super(AnalogGaugeWidget, self).__init__(parent)
self.use_timer_event = False
self.black = QColor(0, 0, 0, 255)
# self.valueColor = QColor(50, 50, 50, 255)
# self.set_valueColor(50, 50, 50, 255)
# self.NeedleColor = QColor(50, 50, 50, 255)
self.set_NeedleColor(50, 50, 50, 255)
self.NeedleColorReleased = self.NeedleColor
# self.NeedleColorDrag = QColor(255, 0, 00, 255)
self.set_NeedleColorDrag(255, 0, 00, 255)
self.set_ScaleValueColor(50, 50, 50, 255)
self.set_DisplayValueColor(50, 50, 50, 255)
# self.CenterPointColor = QColor(50, 50, 50, 255)
self.set_CenterPointColor(50, 50, 50, 255)
# self.valueColor = black
# self.black = QColor(0, 0, 0, 255)
self.value_needle_count = 1
self.value_needle = QObject
self.change_value_needle_style([QPolygon([
QPoint(4, 4),
QPoint(-4, 4),
QPoint(-3, -120),
QPoint(0, -126),
QPoint(3, -120)
])])
self.value_min = 0
self.value_max = 1000
self.value = self.value_min
self.value_offset = 0
self.value_needle_snapzone = 0.05
self.last_value = 0
# self.value2 = 0
# self.value2Color = QColor(0, 0, 0, 255)
self.gauge_color_outer_radius_factor = 1
self.gauge_color_inner_radius_factor = 0.95
self.center_horizontal_value = 0
self.center_vertical_value = 0
self.debug1 = None
self.debug2 = None
self.scale_angle_start_value = 135
self.scale_angle_size = 270
self.angle_offset = 0
# self.scala_main_count = 10
self.set_scala_main_count(10)
self.scala_subdiv_count = 5
self.pen = QPen(QColor(0, 0, 0))
self.font = QFont('Decorative', 20)
self.scale_polygon_colors = []
self.set_scale_polygon_colors([[.00, Qt.red],
[.1, Qt.yellow],
[.15, Qt.green],
[1, Qt.transparent]])
# initialize Scale value text
# self.enable_scale_text = True
self.set_enable_ScaleText(True)
self.scale_fontname = "Decorative"
self.initial_scale_fontsize = 15
self.scale_fontsize = self.initial_scale_fontsize
# initialize Main value text
self.enable_value_text = True
self.value_fontname = "Decorative"
self.initial_value_fontsize = 40
self.value_fontsize = self.initial_value_fontsize
self.text_radius_factor = 0.7
# En/disable scale / fill
# self.enable_barGraph = True
self.set_enable_barGraph(True)
# self.enable_filled_Polygon = True
self.set_enable_filled_Polygon(True)
self.enable_CenterPoint = True
self.enable_fine_scaled_marker = True
self.enable_big_scaled_marker = True
self.needle_scale_factor = 0.8
self.enable_Needle_Polygon = True
# necessary for resize
self.setMouseTracking(False)
if self.use_timer_event:
timer = QTimer(self)
timer.timeout.connect(self.update)
timer.start(10)
else:
self.update()
self.setWindowTitle("Analog Gauge")
# self.connect(self, SIGNAL("resize()"), self.rescaleMethod)
# self.resize(300 , 300)
self.rescale_method()
def rescale_method(self):
# print("slotMethod")
if self.width() <= self.height():
self.widget_diameter = self.width()
else:
self.widget_diameter = self.height()
self.change_value_needle_style([QPolygon([
QPoint(4, 30),
QPoint(-4, 30),
QPoint(-2, - self.widget_diameter / 2 * self.needle_scale_factor),
QPoint(0, - self.widget_diameter / 2 * self.needle_scale_factor - 6),
QPoint(2, - self.widget_diameter / 2 * self.needle_scale_factor)
])])
# needle = [QPolygon([
# QPoint(4, 4),
# QPoint(-4, 4),
# QPoint(-3, -120),
# QPoint(0, -126),
# QPoint(3, -120)])]
# print(str(type(needle)).split("'")[1])
#
# needle = [2]
# print(str(type(needle[0])).split("'")[1])
self.scale_fontsize = self.initial_scale_fontsize * self.widget_diameter / 400
self.value_fontsize = self.initial_value_fontsize * self.widget_diameter / 400
# print("slotMethod end")
pass
def creator(self):
print("Sihab Sahariar | www.github.com/sihabsahariar")
def change_value_needle_style(self, design):
# prepared for multiple needle instrument
self.value_needle = []
for i in design:
self.value_needle.append(i)
if not self.use_timer_event:
self.update()
def update_value(self, value, mouse_controlled = False):
# if not mouse_controlled:
# self.value = value
#
# if mouse_controlled:
# self.valueChanged.emit(int(value))
if value <= self.value_min:
self.value = self.value_min
elif value >= self.value_max:
self.value = self.value_max
else:
self.value = value
# self.paintEvent("")
self.valueChanged.emit(int(value))
# print(self.value)
if not self.use_timer_event:
self.update()
def update_angle_offset(self, offset):
self.angle_offset = offset
if not self.use_timer_event:
self.update()
def center_horizontal(self, value):
self.center_horizontal_value = value
# print("horizontal: " + str(self.center_horizontal_value))
def center_vertical(self, value):
self.center_vertical_value = value
# print("vertical: " + str(self.center_vertical_value))
def set_NeedleColor(self, R=50, G=50, B=50, Transparency=255):
# Red: R = 0 - 255
# Green: G = 0 - 255
# Blue: B = 0 - 255
# Transparency = 0 - 255
self.NeedleColor = QColor(R, G, B, Transparency)
self.NeedleColorReleased = self.NeedleColor
if not self.use_timer_event:
self.update()
def set_NeedleColorDrag(self, R=50, G=50, B=50, Transparency=255):
# Red: R = 0 - 255
# Green: G = 0 - 255
# Blue: B = 0 - 255
# Transparency = 0 - 255
self.NeedleColorDrag = QColor(R, G, B, Transparency)
if not self.use_timer_event:
self.update()
def set_ScaleValueColor(self, R=50, G=50, B=50, Transparency=255):
# Red: R = 0 - 255
# Green: G = 0 - 255
# Blue: B = 0 - 255
# Transparency = 0 - 255
self.ScaleValueColor = QColor(R, G, B, Transparency)
if not self.use_timer_event:
self.update()
def set_DisplayValueColor(self, R=50, G=50, B=50, Transparency=255):
# Red: R = 0 - 255
# Green: G = 0 - 255
# Blue: B = 0 - 255
# Transparency = 0 - 255
self.DisplayValueColor = QColor(R, G, B, Transparency)
if not self.use_timer_event:
self.update()
def set_CenterPointColor(self, R=50, G=50, B=50, Transparency=255):
self.CenterPointColor = QColor(R, G, B, Transparency)
if not self.use_timer_event:
self.update()
def set_enable_Needle_Polygon(self, enable = True):
self.enable_Needle_Polygon = enable
if not self.use_timer_event:
self.update()
def set_enable_ScaleText(self, enable = True):
self.enable_scale_text = enable
if not self.use_timer_event:
self.update()
def set_enable_barGraph(self, enable = True):
self.enable_barGraph = enable
if not self.use_timer_event:
self.update()
def set_enable_value_text(self, enable = True):
self.enable_value_text = enable
if not self.use_timer_event:
self.update()
def set_enable_CenterPoint(self, enable = True):
self.enable_CenterPoint = enable
if not self.use_timer_event:
self.update()
def set_enable_filled_Polygon(self, enable = True):
self.enable_filled_Polygon = enable
if not self.use_timer_event:
self.update()
def set_enable_big_scaled_grid(self, enable = True):
self.enable_big_scaled_marker = enable
if not self.use_timer_event:
self.update()
def set_enable_fine_scaled_marker(self, enable = True):
self.enable_fine_scaled_marker = enable
if not self.use_timer_event:
self.update()
def set_scala_main_count(self, count):
if count < 1:
count = 1
self.scala_main_count = count
if not self.use_timer_event:
self.update()
def set_MinValue(self, min):
if self.value < min:
self.value = min
if min >= self.value_max:
self.value_min = self.value_max - 1
else:
self.value_min = min
if not self.use_timer_event:
self.update()
def set_MaxValue(self, max):
if self.value > max:
self.value = max
if max <= self.value_min:
self.value_max = self.value_min + 1
else:
self.value_max = max
if not self.use_timer_event:
self.update()
def set_start_scale_angle(self, value):
# Value range in DEG: 0 - 360
self.scale_angle_start_value = value
# print("startFill: " + str(self.scale_angle_start_value))
if not self.use_timer_event:
self.update()
def set_total_scale_angle_size(self, value):
self.scale_angle_size = value
# print("stopFill: " + str(self.scale_angle_size))
if not self.use_timer_event:
self.update()
def set_gauge_color_outer_radius_factor(self, value):
self.gauge_color_outer_radius_factor = float(value) / 1000
# print(self.gauge_color_outer_radius_factor)
if not self.use_timer_event:
self.update()
def set_gauge_color_inner_radius_factor(self, value):
self.gauge_color_inner_radius_factor = float(value) / 1000
# print(self.gauge_color_inner_radius_factor)
if not self.use_timer_event:
self.update()
def set_scale_polygon_colors(self, color_array):
# print(type(color_array))
if 'list' in str(type(color_array)):
self.scale_polygon_colors = color_array
elif color_array == None:
self.scale_polygon_colors = [[.0, Qt.transparent]]
else:
self.scale_polygon_colors = [[.0, Qt.transparent]]
if not self.use_timer_event:
self.update()
###############################################################################################
# Get Methods
###############################################################################################
def get_value_max(self):
return self.value_max
###############################################################################################
# Painter
###############################################################################################
def create_polygon_pie(self, outer_radius, inner_raduis, start, lenght):
polygon_pie = QPolygonF()
n = 360 # angle steps size for full circle
# changing n value will causes drawing issues
w = 360 / n # angle per step
# create outer circle line from "start"-angle to "start + lenght"-angle
x = 0
y = 0
if not self.enable_barGraph:
# float_value = ((lenght / (self.value_max - self.value_min)) * (self.value - self.value_min))
lenght = int(round((lenght / (self.value_max - self.value_min)) * (self.value - self.value_min)))
# print("f: %s, l: %s" %(float_value, lenght))
pass
# mymax = 0
for i in range(lenght+1): # add the points of polygon
t = w * i + start - self.angle_offset
x = outer_radius * math.cos(math.radians(t))
y = outer_radius * math.sin(math.radians(t))
polygon_pie.append(QPointF(x, y))
# create inner circle line from "start + lenght"-angle to "start"-angle
for i in range(lenght+1): # add the points of polygon
# print("2 " + str(i))
t = w * (lenght - i) + start - self.angle_offset
x = inner_raduis * math.cos(math.radians(t))
y = inner_raduis * math.sin(math.radians(t))
polygon_pie.append(QPointF(x, y))
# close outer line
polygon_pie.append(QPointF(x, y))
return polygon_pie
def draw_filled_polygon(self, outline_pen_with=0):
if not self.scale_polygon_colors == None:
painter_filled_polygon = QPainter(self)
painter_filled_polygon.setRenderHint(QPainter.Antialiasing)
painter_filled_polygon.translate(self.width() / 2, self.height() / 2)
painter_filled_polygon.setPen(Qt.NoPen)
self.pen.setWidth(outline_pen_with)
if outline_pen_with > 0:
painter_filled_polygon.setPen(self.pen)
colored_scale_polygon = self.create_polygon_pie(
((self.widget_diameter / 2) - (self.pen.width() / 2)) * self.gauge_color_outer_radius_factor,
(((self.widget_diameter / 2) - (self.pen.width() / 2)) * self.gauge_color_inner_radius_factor),
self.scale_angle_start_value, self.scale_angle_size)
gauge_rect = QRect(QPoint(0, 0), QSize(self.widget_diameter / 2 - 1, self.widget_diameter - 1))
grad = QConicalGradient(QPointF(0, 0), - self.scale_angle_size - self.scale_angle_start_value +
self.angle_offset - 1)
for eachcolor in self.scale_polygon_colors:
grad.setColorAt(eachcolor[0], eachcolor[1])
# grad.setColorAt(.00, Qt.red)
# grad.setColorAt(.1, Qt.yellow)
# grad.setColorAt(.15, Qt.green)
# grad.setColorAt(1, Qt.transparent)
painter_filled_polygon.setBrush(grad)
# self.brush = QBrush(QColor(255, 0, 255, 255))
# painter_filled_polygon.setBrush(self.brush)
painter_filled_polygon.drawPolygon(colored_scale_polygon)
# return painter_filled_polygon
def draw_big_scaled_markter(self):
my_painter = QPainter(self)
my_painter.setRenderHint(QPainter.Antialiasing)
my_painter.translate(self.width() / 2, self.height() / 2)
# my_painter.setPen(Qt.NoPen)
self.pen = QPen(QColor(0, 0, 0, 255))
self.pen.setWidth(2)
# # if outline_pen_with > 0:
my_painter.setPen(self.pen)
my_painter.rotate(self.scale_angle_start_value - self.angle_offset)
steps_size = (float(self.scale_angle_size) / float(self.scala_main_count))
scale_line_outer_start = self.widget_diameter/2
scale_line_lenght = (self.widget_diameter / 2) - (self.widget_diameter / 20)
# print(stepszize)
for i in range(self.scala_main_count+1):
my_painter.drawLine(scale_line_lenght, 0, scale_line_outer_start, 0)
my_painter.rotate(steps_size)
def create_scale_marker_values_text(self):
painter = QPainter(self)
# painter.setRenderHint(QPainter.HighQualityAntialiasing)
painter.setRenderHint(QPainter.Antialiasing)
painter.translate(self.width() / 2, self.height() / 2)
# painter.save()
font = QFont(self.scale_fontname, self.scale_fontsize)
fm = QFontMetrics(font)
pen_shadow = QPen()
pen_shadow.setBrush(self.ScaleValueColor)
painter.setPen(pen_shadow)
text_radius_factor = 0.8
text_radius = self.widget_diameter/2 * text_radius_factor
scale_per_div = int((self.value_max - self.value_min) / self.scala_main_count)
angle_distance = (float(self.scale_angle_size) / float(self.scala_main_count))
for i in range(self.scala_main_count + 1):
# text = str(int((self.value_max - self.value_min) / self.scala_main_count * i))
text = str(int(self.value_min + scale_per_div * i))
w = fm.width(text) + 1
h = fm.height()
painter.setFont(QFont(self.scale_fontname, self.scale_fontsize))
angle = angle_distance * i + float(self.scale_angle_start_value - self.angle_offset)
x = text_radius * math.cos(math.radians(angle))
y = text_radius * math.sin(math.radians(angle))
# print(w, h, x, y, text)
text = [x - int(w/2), y - int(h/2), int(w), int(h), Qt.AlignCenter, text]
painter.drawText(text[0], text[1], text[2], text[3], text[4], text[5])
# painter.restore()
def create_fine_scaled_marker(self):
# Description_dict = 0
my_painter = QPainter(self)
my_painter.setRenderHint(QPainter.Antialiasing)
my_painter.translate(self.width() / 2, self.height() / 2)
my_painter.setPen(Qt.black)
my_painter.rotate(self.scale_angle_start_value - self.angle_offset)
steps_size = (float(self.scale_angle_size) / float(self.scala_main_count * self.scala_subdiv_count))
scale_line_outer_start = self.widget_diameter/2
scale_line_lenght = (self.widget_diameter / 2) - (self.widget_diameter / 40)
for i in range((self.scala_main_count * self.scala_subdiv_count)+1):
my_painter.drawLine(scale_line_lenght, 0, scale_line_outer_start, 0)
my_painter.rotate(steps_size)
def create_values_text(self):
painter = QPainter(self)
# painter.setRenderHint(QPainter.HighQualityAntialiasing)
painter.setRenderHint(QPainter.Antialiasing)
painter.translate(self.width() / 2, self.height() / 2)
# painter.save()
# xShadow = 3.0
# yShadow = 3.0
font = QFont(self.value_fontname, self.value_fontsize)
fm = QFontMetrics(font)
pen_shadow = QPen()
pen_shadow.setBrush(self.DisplayValueColor)
painter.setPen(pen_shadow)
text_radius = self.widget_diameter / 2 * self.text_radius_factor
# angle_distance = (float(self.scale_angle_size) / float(self.scala_main_count))
# for i in range(self.scala_main_count + 1):
text = str(int(self.value))
w = fm.width(text) + 1
h = fm.height()
painter.setFont(QFont(self.value_fontname, self.value_fontsize))
angle_end = float(self.scale_angle_start_value + self.scale_angle_size - 360)
angle = (angle_end - self.scale_angle_start_value) / 2 + self.scale_angle_start_value
x = text_radius * math.cos(math.radians(angle))
y = text_radius * math.sin(math.radians(angle))
# print(w, h, x, y, text)
text = [x - int(w/2), y - int(h/2), int(w), int(h), Qt.AlignCenter, text]
painter.drawText(text[0], text[1], text[2], text[3], text[4], text[5])
# painter.restore()
def draw_big_needle_center_point(self, diameter=30):
painter = QPainter(self)
# painter.setRenderHint(QtGui.QPainter.HighQualityAntialiasing)
painter.setRenderHint(QPainter.Antialiasing)
painter.translate(self.width() / 2, self.height() / 2)
painter.setPen(Qt.NoPen)
# painter.setPen(Qt.NoPen)
painter.setBrush(self.CenterPointColor)
# diameter = diameter # self.widget_diameter/6
painter.drawEllipse(int(-diameter / 2), int(-diameter / 2), int(diameter), int(diameter))
def draw_needle(self):
painter = QPainter(self)
# painter.setRenderHint(QtGui.QPainter.HighQualityAntialiasing)
painter.setRenderHint(QPainter.Antialiasing)
painter.translate(self.width() / 2, self.height() / 2)
painter.setPen(Qt.NoPen)
painter.setBrush(self.NeedleColor)
painter.rotate(((self.value - self.value_offset - self.value_min) * self.scale_angle_size /
(self.value_max - self.value_min)) + 90 + self.scale_angle_start_value)
painter.drawConvexPolygon(self.value_needle[0])
###############################################################################################
# Events
###############################################################################################
def resizeEvent(self, event):
self.rescale_method()
# self.emit(QtCore.SIGNAL("resize()"))
# print("resizeEvent")
def paintEvent(self, event):
if self.enable_filled_Polygon:
self.draw_filled_polygon()
# draw scale marker lines
if self.enable_fine_scaled_marker:
self.create_fine_scaled_marker()
if self.enable_big_scaled_marker:
self.draw_big_scaled_markter()
# draw scale marker value text
if self.enable_scale_text:
self.create_scale_marker_values_text()
# Display Value
if self.enable_value_text:
self.create_values_text()
# draw needle 1
if self.enable_Needle_Polygon:
self.draw_needle()
# Draw Center Point
if self.enable_CenterPoint:
self.draw_big_needle_center_point(diameter=(self.widget_diameter / 6))
###############################################################################################
# MouseEvents
###############################################################################################
def setMouseTracking(self, flag):
def recursive_set(parent):
for child in parent.findChildren(QObject):
try:
child.setMouseTracking(flag)
except:
pass
recursive_set(child)
QWidget.setMouseTracking(self, flag)
recursive_set(self)
def mouseReleaseEvent(self, QMouseEvent):
# print("released")
self.NeedleColor = self.NeedleColorReleased
if not self.use_timer_event:
self.update()
pass
def mouseMoveEvent(self, event):
x, y = event.x() - (self.width() / 2), event.y() - (self.height() / 2)
if not x == 0:
angle = math.atan2(y, x) / math.pi * 180
value = (float(math.fmod(angle - self.scale_angle_start_value + 720, 360)) / \
(float(self.scale_angle_size) / float(self.value_max - self.value_min))) + self.value_min
temp = value
fmod = float(math.fmod(angle - self.scale_angle_start_value + 720, 360))
state = 0
if (self.value - (self.value_max - self.value_min) * self.value_needle_snapzone) <= \
value <= \
(self.value + (self.value_max - self.value_min) * self.value_needle_snapzone):
self.NeedleColor = self.NeedleColorDrag
state = 9
# if value >= self.value_max and self.last_value < (self.value_max - self.value_min) / 2:
if value >= self.value_max and self.last_value < (self.value_max - self.value_min) / 2:
state = 1
value = self.value_max
self.last_value = self.value_min
self.valueChanged.emit(int(value))
elif value >= self.value_max >= self.last_value:
state = 2
value = self.value_max
self.last_value = self.value_max
self.valueChanged.emit(int(value))
else:
state = 3
self.last_value = value
self.valueChanged.emit(int(value))