Revize 847100d1
Přidáno uživatelem Martin Forejt před téměř 4 roky(ů)
- ID 847100d13630e1b9f800683f5d9644b2127049ba
- Rodič 70b83aa2
aswi2021vochomurka/view/main_view.py | ||
---|---|---|
1 | 1 |
import logging |
2 |
import math |
|
3 | 2 |
|
3 |
import matplotlib.pyplot as plt |
|
4 |
from PyQt5 import QtCore |
|
4 | 5 |
from PyQt5.QtCore import QSize, QThread, QObject, pyqtSignal |
5 |
from PyQt5.QtWidgets import QMainWindow, QPlainTextEdit, QDialog, QHBoxLayout, QGridLayout |
|
6 |
from PyQt5.QtWidgets import QDialog, QPushButton, QVBoxLayout |
|
7 |
from PyQt5.QtWidgets import QHBoxLayout, QGridLayout, QScrollArea, QWidget |
|
8 |
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas |
|
6 | 9 |
|
7 | 10 |
from aswi2021vochomurka.model.Message import Message |
8 | 11 |
from aswi2021vochomurka.service.mqtt.mqtt_subscriber import MQTTSubscriber |
9 | 12 |
from aswi2021vochomurka.service.subscriber import Subscriber |
10 | 13 |
from aswi2021vochomurka.service.subscriber_callback import SubscriberCallback |
11 | 14 |
from aswi2021vochomurka.service.subscriber_params import SubscriberParams, ConnectionParams |
12 |
|
|
13 |
from PyQt5.QtWidgets import QDialog, QApplication, QPushButton, QVBoxLayout |
|
14 |
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas |
|
15 |
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar |
|
16 |
import matplotlib.pyplot as plt |
|
17 |
|
|
18 | 15 |
from aswi2021vochomurka.view.logger_view import LoggerView |
19 | 16 |
|
20 | 17 |
|
... | ... | |
47 | 44 |
|
48 | 45 |
def onMessage(self, message: Message): |
49 | 46 |
self.newMessage.emit(message) |
50 |
#self.window.plot(message) |
|
47 |
# self.window.plot(message)
|
|
51 | 48 |
|
52 | 49 |
def onCloseTopic(self, topic: str): |
53 | 50 |
pass |
... | ... | |
69 | 66 |
self.canvasDict = {} |
70 | 67 |
self.figureDict = {} |
71 | 68 |
|
72 |
#self.toolbar = NavigationToolbar(self.canvas, self) |
|
69 |
# self.toolbar = NavigationToolbar(self.canvas, self)
|
|
73 | 70 |
|
74 |
#self.setMinimumSize(QSize(440, 240)) |
|
71 |
# self.setMinimumSize(QSize(440, 240))
|
|
75 | 72 |
self.setMinimumSize(QSize(1200, 800)) |
76 | 73 |
self.setWindowTitle("MQTT demo") |
77 | 74 |
|
... | ... | |
84 | 81 |
|
85 | 82 |
layout = QVBoxLayout() |
86 | 83 |
layout.addWidget(logger.widget) |
87 |
#layout.addWidget(self.toolbar) |
|
84 |
# layout.addWidget(self.toolbar)
|
|
88 | 85 |
|
89 | 86 |
self.setLayout(layout) |
90 | 87 |
|
91 |
self.grid = QGridLayout() |
|
92 |
|
|
93 |
layout.addLayout(self.grid) |
|
88 |
scrollArea = QScrollArea(self) |
|
89 |
scrollArea.setWidgetResizable(True) |
|
90 |
scrollContent = QWidget() |
|
91 |
self.grid = QGridLayout(scrollContent) |
|
92 |
scrollArea.setWidget(scrollContent) |
|
93 |
layout.addWidget(scrollArea) |
|
94 | 94 |
|
95 | 95 |
self.init_subscriber() |
96 | 96 |
|
... | ... | |
110 | 110 |
|
111 | 111 |
figure = plt.figure(figsize=[500, 500]) |
112 | 112 |
canvas = FigureCanvas(figure) |
113 |
layout = QHBoxLayout() |
|
113 | 114 |
|
114 | 115 |
plt.plot(self.dataDict[message.topic]) |
115 | 116 |
|
116 | 117 |
self.canvasDict[message.topic] = canvas |
117 | 118 |
self.figureDict[message.topic] = figure |
118 | 119 |
|
119 |
self.grid.addWidget(canvas, int(self.chartsNum / 2), self.chartsNum % 2) |
|
120 |
widget = QWidget() |
|
121 |
widget.setLayout(layout) |
|
122 |
button = QPushButton(':') |
|
123 |
button.setFixedSize(QSize(40, 40)) |
|
124 |
layout.addWidget(canvas) |
|
125 |
layout.addWidget(button) |
|
126 |
layout.setAlignment(button, QtCore.Qt.AlignTop) |
|
127 |
widget.setMinimumSize(QSize(500, 500)) |
|
128 |
|
|
129 |
self.grid.addWidget(widget, int(self.chartsNum / 2), self.chartsNum % 2) |
|
120 | 130 |
|
121 | 131 |
self.chartsNum += 1 |
122 | 132 |
|
... | ... | |
130 | 140 |
) |
131 | 141 |
self.worker.window = self |
132 | 142 |
self.workerThread.start() |
133 |
#lambda message: self.b.insertPlainText(message + "\n") |
Také k dispozici: Unified diff
Re: #8923 - add scroll, button to graph