-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_curve_widget.py
62 lines (47 loc) · 1.77 KB
/
data_curve_widget.py
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
from PySide2 import QtWidgets
import os
import numpy as np
class DataCurveWidget(QtWidgets.QWidget):
'''Widget to add plot curve
'''
def __init__(self, filename, plot_area):
super().__init__()
self.data = np.loadtxt(filename)
if self.data.shape[1] == 2:
self.plot_data = plot_area.plot(
x=self.data[:, 0], y=self.data[:, 1],
name=str(os.path.basename(
filename)))
class DataCurveListWidget(QtWidgets.QWidget):
'''Widget to hold a list of data curve
'''
def __init__(self, plot_area):
"""
docstring
"""
super().__init__()
self.plot_area = plot_area
self.layout = QtWidgets.QVBoxLayout()
toolbar = QtWidgets.QToolBar("Main toolbar")
self.layout.addWidget(toolbar)
self.setLayout(self.layout)
self.resize(100, 100)
load_data_button = QtWidgets.QAction("Load data", self)
load_data_button.triggered.connect(self.load_data_triggered)
toolbar.addAction(load_data_button)
self.last_folder = os.getcwd()
def update_last_folder(self, filename):
self.last_folder = os.path.dirname(filename)
def load_data_triggered(self):
data_filename, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file',
self.last_folder, "Data files (*.csv *.txt)")
if data_filename == "":
return
curve_widget = DataCurveWidget(data_filename, self.plot_area)
self.layout.addWidget(curve_widget)
self.update_last_folder(data_filename)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
ex = DataCurveListWidget()
sys.exit(app.exec_())