-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_info.py
More file actions
139 lines (106 loc) · 4.66 KB
/
debug_info.py
File metadata and controls
139 lines (106 loc) · 4.66 KB
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
from PyQt5.QtWidgets import QWidget, QFrame, QHBoxLayout, QVBoxLayout, QLabel, QVBoxLayout, QPushButton
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter, QPen, QColor, QFont
# TODO: Написать пару классов для вывода всего дебага в slam_brain и для вывода требуемых графиов
class BottomDebugMenu(QWidget):
def __init__(self, parent, geometry, robot_value):
super().__init__(parent)
self.robot_value = robot_value
self.progress_bars = []
self.main_geometry = geometry
self.buildDebuger()
def buildDebuger(self):
self.setStyleSheet("border:3px solid rgb(0, 0, 0);")
self.setFixedSize(self.main_geometry[0] + 300, self.main_geometry[1] * 0.3)
self.not_taked_debug = []
self.booked_debug = []
self.progressed_debug = []
#vbox = QVBoxLayout()
hbox = self.robotInfo()
test_label = QLabel('TEST!!!')
#vbox.addLayout(hbox)
self.setLayout(hbox)
def updateDebugInfo(self, not_taked=[], booked=[], progressed=[]):
if not_taked:
self.not_taked_debug = not_taked
def robotInfo(self):
hbox = QHBoxLayout()
# Создание прогрессбара на каждого робота, что бы мониторить пройденное ими расстояние
for x in range(self.robot_value):
vbox = QVBoxLayout()
vbox.addWidget(QLabel('Robot {0}'.format(x)))
new_progress_bar = ProgressBar()
new_progress_bar.setFixedSize(150, self.main_geometry[1] * 0.28)
self.progress_bars.append(new_progress_bar)
vbox.addWidget(new_progress_bar)
hbox.addLayout(vbox)
# Прогресс бар для вывода расстояния пройденного всеми роботами
vbox = QVBoxLayout()
vbox.addWidget(QLabel('Total way length'))
new_progress_bar = ProgressBar()
new_progress_bar.setFixedSize(150, self.main_geometry[1] * 0.28)
self.progress_bars.append(new_progress_bar)
vbox.addWidget(new_progress_bar)
hbox.addLayout(vbox)
# Пройденное количество тактов алгоритма
vbox = QVBoxLayout()
vbox.addWidget(QLabel('The number of cycles'))
new_progress_bar = ProgressBar()
new_progress_bar.setFixedSize(150, self.main_geometry[1] * 0.28)
self.progress_bars.append(new_progress_bar)
vbox.addWidget(new_progress_bar)
hbox.addLayout(vbox)
return hbox
class ProgressBar(QFrame):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setMinimumSize(20, 35)
self.value = 0
self.num = [15, 10, 5]
self.font_size = round((self.width() + self.height()) / 100)
self.paint_font = QFont('Serif', self.font_size, QFont.Light)
def setValue(self, value):
self.value = value
self.repaint()
def incrementValue(self):
self.value += 1
self.repaint()
def paintEvent(self, e):
qp = QPainter()
qp.begin(self)
self.drawBar(qp)
qp.end()
def drawBar(self, qp):
qp.setFont(self.paint_font)
w = self.width()
h = self.height()
line_step = int(round(h / 4))
qp.setPen(QPen(QColor(60, 179, 113)))
qp.setBrush(QColor(60, 179, 113))
cur_heigth = self.value * (h / (self.num[0] + self.num[2]))
if h / self.num[0] + self.num[2] > 1:
drow_heigth = h - cur_heigth
qp.drawRect(3, drow_heigth, w - 7, cur_heigth )
qp.setPen(QPen(Qt.black, 1, Qt.SolidLine))
qp.setBrush(Qt.NoBrush)
qp.drawRect(0, 0, w - 2, h - 3)
i = 0
for step in range(line_step, line_step * 4, line_step):
if step - self.font_size < h - cur_heigth < step + self.font_size:
pass
else:
self.drawMetric(qp, step, str(self.num[i]), w)
i += 1
qp.setPen(QPen(Qt.blue, 2, Qt.SolidLine))
self.drawMetric(qp, h - cur_heigth, str(self.value), w)
# Переназначение максимума бара
if self.value > (self.num[0] + self.num[2]) * 0.8:
self.num = [x * 4 for x in self.num]
def drawMetric(self, qp, heigth, text, w):
qp.drawLine(0, heigth + 1, int(w * 0.1), heigth + 1)
qp.drawLine(w, heigth + 1, int(w * 0.9), heigth + 1)
metrics = qp.fontMetrics()
fw = metrics.width(text)
qp.drawText(w / 2 - fw / 2, heigth + self.font_size / 1.7, text)