Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
ArrowDial.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3import typing,math
4
5from PyQt5.QtCore import Qt,QPoint,QPointF
6from PyQt5.QtWidgets import QWidget,QDial,QMainWindow,QApplication
7from PyQt5.QtGui import QColor,QPainter,QPaintEvent,QBrush,QPen
8
9# Custom Arrow dial based on:
10# http://thecodeinn.blogspot.com/2015/02/customizing-qdials-in-qt-part-1.html
11# http://thecodeinn.blogspot.com/2015/03/customizing-qdials-in-qt-part-2.html
12
13class ArrowDial(QDial):
14
15 # Points defining the arrow, in a 200x200 square, pointing Downward, with coordinates:
16 #
17 # (-100,-100) - - - - - ( 0,-100) - - - - - ( 100,-100)
18 # | _ |
19 # | | | |
20 # | | | |
21 # | | | |
22 # | | | |
23 # (-100, 0) ( 0, 0) ( 100, 0)
24 # | | | |
25 # | | | |
26 # | _| |_ |
27 # | \ / |
28 # | \_/ |
29 # (-100, 100) - - - - - ( 0, 100) - - - - - ( 100, 100)
30
31 ARROW_POINTS = [
32 QPoint(0,80), # Head point
33 QPoint(6,60), # Right triangle
34 QPoint(2,60), # Head-line right
35 QPoint(2,-70), # End right
36 QPoint(-2,-70),# End left
37 QPoint(-2,60), # Head-line left
38 QPoint(-6,60), # Left triangle
39 ]
40
41 # Use a 4-point arrow(head) instead:
42 # |V|
43 # | |
44 # v
45
46 ARROW_4POINTS = [
47 QPoint(0,80), # Tip
48 QPoint(8,-80), # Right base
49 QPoint(0,-75), # Chevron
50 QPoint(-8,-80), # Left base
51 ]
52
53 def __init__(self, parent:QWidget = None):
54 super().__init__(parent)
55
56 self._reverseArrow = False
57
58
59
60 @property
61 def reverseArrow(self) -> bool:
62 return self._reverseArrow
63
64 @reverseArrow.setter
65 def reverseArrow(self,val:bool):
66 self._reverseArrow = val
67
68
69
70 def resizeEvent(self, re):
71 pass
72
73 def paintEvent(self, pe:typing.Optional[QPaintEvent]):
74
75 painter = QPainter(self)
76
77 # painter.setBrush(QColor(0,0,0,255))
78 # painter.drawRect(0,0,self.width(),self.height())
79
80
82 painter.translate(self.width() / 2, self.height() / 2)
83
84 # Rescale to a Square 200x200
85 side = min(self.width(), self.height())
86 painter.scale(side / 200.0, side / 200.0)
87
88
90 edgeColor = QColor(255,255,255,255)
91 fillColor = QColor(0,0,0,255)
92
93 pen = painter.pen()
95 pen.setColor(edgeColor)
97 painter.setBrush(fillColor)
98
99 # Antialiasing
101
102
104
105 val = self.value()
106 minimum = self.minimum()
107 maximum = self.maximum()
108 percent = (val - minimum)/(maximum-minimum)
109 angle = 360*percent
110
111 if self._reverseArrow:
112 painter.rotate(angle+180)
113 else:
114 painter.rotate(angle)
115
117
119
120
121
122 if self.notchesVisible():
123 # Majors (0°,90°,180°,270°) aka (N,E,S,W)
125
126 for _ in range(4):
127 painter.drawRect(-2,85,4,13)
129
131
132 # Halves (45°,135°, 225°,315°) aka (NE,SE,SW,NW)
133
135
137
138 for _ in range(4):
139 painter.drawRect(-1,90,2,8)
141
143
144 # Minors (10°s which are not Majors)
145
147
148 for i in range(0,360,10):
149 if i % 90 != 0:
150 painter.drawRect(-1,94,2,4)
152
154
155
157
158
159
160
161if __name__ == '__main__':
162 app = QApplication([])
163 window = QMainWindow()
166 app.exec()
paintEvent(self, typing.Optional[QPaintEvent] pe)
Definition ArrowDial.py:73
__init__(self, QWidget parent=None)
Definition ArrowDial.py:53
bool reverseArrow(self)
Setters and Getters #####.
Definition ArrowDial.py:61
resizeEvent(self, re)
Painting #####.
Definition ArrowDial.py:70
uint16_t foo
Definition main_demo5.c:58