Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 4e32720c

Přidáno uživatelem Jan Rach před téměř 4 roky(ů)

Re: #8968 - second function plotting implemented

Zobrazit rozdíly:

aswi2021vochomurka/view/main_view.py
4 4
from PyQt5 import QtCore
5 5
from PyQt5 import QtGui
6 6
from PyQt5.QtCore import QSize, QThread, QObject, pyqtSignal, QSettings
7
from PyQt5.QtWidgets import QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QScrollArea, QGridLayout
7
from PyQt5.QtWidgets import QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QScrollArea, QGridLayout, QFileDialog
8 8
from PyQt5.QtWidgets import QMenuBar, QAction, QPushButton
9 9
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
10 10

  
......
97 97

  
98 98
        self.chartsNum = 0
99 99
        self.dataDict = {}
100
        self.dataDict2 = {}
100 101
        self.canvasDict = {}
101 102
        self.figureDict = {}
102 103
        self.widgetDict = {}
......
160 161
            figure.suptitle(message.topic)
161 162
            plt.plot(self.dataDict[message.topic])
162 163

  
164
            if message.topic in self.dataDict2:
165
                plt.plot(self.dataDict2[message.topic])
166

  
163 167
            self.canvasDict[message.topic].draw()
164 168
        else:
165 169
            # new topic
......
179 183
            self.widgetDict[message.topic] = widget
180 184
            self.widgetList.append(widget)
181 185
            widget.setLayout(self.layout)
182
            button = QPushButton(':')
186
            button = QPushButton('Load')
187
            button.clicked.connect(lambda: self.getFile(message.topic))
183 188
            button.setFixedSize(QSize(40, 40))
189

  
184 190
            self.layout.addWidget(canvas)
185 191
            self.layout.addWidget(button)
186 192
            self.layout.setAlignment(button, QtCore.Qt.AlignTop)
......
190 196

  
191 197
            self.chartsNum += 1
192 198

  
199
    def getFile(self, topic: str):
200
        fname = QFileDialog.getOpenFileName(self, 'Open file',
201
                                            'c:\\', "CSV files (*.csv)")
202
        try:
203
            figure = self.figureDict[topic]
204
            figure.clear()
205

  
206
            self.dataDict2[topic] = []
207

  
208
            file1 = open(fname[0], 'r')
209
            lines = file1.readlines()
210

  
211
            count = 0
212
            for line in lines:
213
                count += 1
214
                parts = line.split(';')
215
                value = float(parts[3])
216
                self.dataDict2[topic].append(value)
217

  
218
            figure = plt.figure(figure.number)
219
            figure.suptitle(topic)
220
            plt.plot(self.dataDict[topic])
221
            plt.plot(self.dataDict2[topic])
222

  
223
            self.canvasDict[topic].draw()
224
        except:
225
            print("Loading error")
226

  
193 227
    def deletePlot(self, topic: str):
194 228
        """
195 229
        Deletes plot

Také k dispozici: Unified diff