1- from PyQt5 .QtWidgets import QDialog , QVBoxLayout , QHBoxLayout , QPushButton , QLabel , QFormLayout , QRadioButton , QMessageBox
1+ from PyQt5 .QtWidgets import QDialog , QVBoxLayout , QHBoxLayout , QPushButton , QLabel , QFormLayout , QRadioButton , QMessageBox , QFileDialog
22
33import matplotlib .pyplot as plt
44from matplotlib .backends .backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
@@ -12,13 +12,17 @@ class DataSelectionWindow(QDialog):
1212 def __init__ (self , filename ):
1313 QDialog .__init__ (self )
1414
15- self .file_name = filename
16-
1715 self .figure = plt .figure (1 )
1816 self .canvas = FigureCanvas (self .figure )
1917
2018 layout_v = QVBoxLayout ()
2119
20+ top_group = QHBoxLayout ()
21+ btn_browse = QPushButton ("Browse files" )
22+ btn_browse .clicked .connect (self .browseFiles )
23+ top_group .addWidget (btn_browse )
24+
25+ layout_v .addLayout (top_group )
2226 layout_v .addWidget (self .canvas )
2327
2428 xyz_group = QHBoxLayout ()
@@ -42,7 +46,12 @@ def __init__(self, filename):
4246
4347 self .setLayout (layout_v )
4448
45- self .refreshInputOutputData ()
49+ if filename :
50+ self .file_name = filename
51+ self .refreshInputOutputData ()
52+
53+ else :
54+ self .browseFiles ()
4655
4756 def loadLog (self ):
4857 if self .t_stop > self .t_start :
@@ -51,6 +60,14 @@ def loadLog(self):
5160 else :
5261 self .printRangeError ()
5362
63+ def browseFiles (self ):
64+ options = QFileDialog .Options ()
65+ options |= QFileDialog .DontUseNativeDialog
66+ self .file_name , _ = QFileDialog .getOpenFileName (self ,"QFileDialog.getOpenFileName()" , "" ,"ULog (*.ulg)" , options = options )
67+
68+ if self .file_name :
69+ self .refreshInputOutputData ()
70+
5471 def printRangeError (self ):
5572 msg = QMessageBox ()
5673 msg .setIcon (QMessageBox .Critical )
0 commit comments