Revize ff2d1b99
Přidáno uživatelem Jan Rach před téměř 4 roky(ů)
aswi2021vochomurka/view/main_view.py | ||
---|---|---|
23 | 23 |
disconnected = pyqtSignal() |
24 | 24 |
error = pyqtSignal(Exception) |
25 | 25 |
newMessage = pyqtSignal(Message) |
26 |
closeTopic = pyqtSignal(str) |
|
26 | 27 |
subscriber: Subscriber = None |
27 | 28 |
params: SubscriberParams |
28 | 29 |
|
... | ... | |
48 | 49 |
|
49 | 50 |
def onMessage(self, message: Message): |
50 | 51 |
self.newMessage.emit(message) |
51 |
# self.window.plot(message) |
|
52 | 52 |
|
53 | 53 |
def onCloseTopic(self, topic: str): |
54 |
pass |
|
54 |
print("Close topic") |
|
55 |
self.closeTopic.emit(topic) |
|
56 |
#pass |
|
55 | 57 |
|
56 | 58 |
|
57 | 59 |
class MainView(QMainWindow): |
... | ... | |
66 | 68 |
|
67 | 69 |
self.dataIndex = 0 |
68 | 70 |
self.dataDict = {} |
69 |
|
|
70 | 71 |
self.canvasDict = {} |
71 | 72 |
self.figureDict = {} |
73 |
self.widgetDict = {} |
|
74 |
|
|
75 |
self.widgetList = [] |
|
72 | 76 |
|
73 | 77 |
# self.toolbar = NavigationToolbar(self.canvas, self) |
74 | 78 |
|
... | ... | |
126 | 130 |
|
127 | 131 |
figure = plt.figure(figsize=[500, 500]) |
128 | 132 |
canvas = FigureCanvas(figure) |
129 |
layout = QHBoxLayout() |
|
133 |
self.layout = QHBoxLayout()
|
|
130 | 134 |
|
131 | 135 |
plt.plot(self.dataDict[message.topic]) |
132 | 136 |
|
... | ... | |
134 | 138 |
self.figureDict[message.topic] = figure |
135 | 139 |
|
136 | 140 |
widget = QWidget() |
137 |
widget.setLayout(layout) |
|
141 |
self.widgetDict[message.topic] = widget |
|
142 |
self.widgetList.append(widget) |
|
143 |
widget.setLayout(self.layout) |
|
138 | 144 |
button = QPushButton(':') |
139 | 145 |
button.setFixedSize(QSize(40, 40)) |
140 |
layout.addWidget(canvas) |
|
141 |
layout.addWidget(button) |
|
142 |
layout.setAlignment(button, QtCore.Qt.AlignTop) |
|
146 |
self.layout.addWidget(canvas)
|
|
147 |
self.layout.addWidget(button)
|
|
148 |
self.layout.setAlignment(button, QtCore.Qt.AlignTop)
|
|
143 | 149 |
widget.setMinimumSize(QSize(500, 500)) |
144 | 150 |
|
145 | 151 |
self.grid.addWidget(widget, int(self.chartsNum / 2), self.chartsNum % 2) |
146 | 152 |
|
147 | 153 |
self.chartsNum += 1 |
148 | 154 |
|
155 |
def deletePlot(self, topic: str): |
|
156 |
widget = self.widgetDict[topic] |
|
157 |
self.widgetList.remove(widget) |
|
158 |
widget.setParent(None) |
|
159 |
|
|
160 |
del self.widgetDict[topic] |
|
161 |
del self.canvasDict[topic] |
|
162 |
del self.figureDict[topic] |
|
163 |
del self.dataDict[topic] |
|
164 |
|
|
165 |
self.reorganizePlots() |
|
166 |
|
|
167 |
def reorganizePlots(self): |
|
168 |
count = 0 |
|
169 |
for widget in self.widgetList: |
|
170 |
self.grid.addWidget(widget, int(count / 2), count % 2) |
|
171 |
count += 1 |
|
172 |
|
|
173 |
self.chartsNum -= 1 |
|
174 |
|
|
149 | 175 |
def closeEvent(self, a0: QtGui.QCloseEvent) -> None: |
150 | 176 |
self.worker.stop() |
151 | 177 |
|
... | ... | |
172 | 198 |
self.worker.newMessage.connect( |
173 | 199 |
lambda message: self.plot(message) |
174 | 200 |
) |
201 |
self.worker.closeTopic.connect( |
|
202 |
lambda topic: self.deletePlot(topic) |
|
203 |
) |
|
175 | 204 |
self.worker.window = self |
176 | 205 |
self.workerThread.start() |
177 | 206 |
|
Také k dispozici: Unified diff
Re: #9016 - Topic close plot reaction implemented