Skip to content

Commit ac5bca9

Browse files
committed
added ability to set delimiter and decimal for parsing
1 parent 50a5952 commit ac5bca9

File tree

3 files changed

+162
-67
lines changed

3 files changed

+162
-67
lines changed

DataFile.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,24 @@ def __initSettings(self):
194194

195195
self.settings.setLayout(self.GLayout)
196196

197+
def __reparseData(self, dialog):
198+
sep = dialog.findChild(QtWidgets.QLineEdit, "sepLineEdit").text()
199+
dec = dialog.findChild(QtWidgets.QLineEdit, "decimalLineEdit").text()
200+
if not sep or not dec:
201+
return
202+
203+
self.config["seperator"] = sep
204+
self.config["decimal"] = dec
205+
206+
dialog.close()
207+
del dialog
208+
209+
self.__readData(sep=self.config["seperator"], decimal=self.config["decimal"])
210+
self.__selectData()
211+
197212
def __selectData(self):
198213
dialog = uic.loadUi(Config.getResource("./ui/file_open_dialog.ui"))
199214
dialog.setWindowTitle(os.path.basename(self.filename))
200-
xComboBox = dialog.findChild(QtWidgets.QComboBox, "xComboBox")
201-
yComboBox = dialog.findChild(QtWidgets.QComboBox, "yComboBox")
202215

203216
# dialog cannot be cancelled on first assignment
204217
if self.config["xColumn"] == -1 or self.config["yColumn"] == -1:
@@ -210,6 +223,8 @@ def __selectData(self):
210223

211224
itemList = self.data.columns.values.tolist()
212225

226+
xComboBox = dialog.findChild(QtWidgets.QComboBox, "xComboBox")
227+
yComboBox = dialog.findChild(QtWidgets.QComboBox, "yComboBox")
213228
xComboBox.addItems(itemList)
214229
yComboBox.addItems(itemList)
215230

@@ -223,6 +238,12 @@ def __selectData(self):
223238
else:
224239
yComboBox.setCurrentIndex(1 if len(itemList) > 0 else 0)
225240

241+
dialog.findChild(QtWidgets.QLineEdit, "sepLineEdit").setText(str(self.config["seperator"]))
242+
dialog.findChild(QtWidgets.QLineEdit, "decimalLineEdit").setText(str(self.config["decimal"]))
243+
244+
reparseBtn = dialog.findChild(QtWidgets.QPushButton, "reparseBtn")
245+
reparseBtn.clicked.connect(lambda: self.__reparseData(dialog))
246+
226247
ret = dialog.exec_()
227248
dialog.close()
228249

@@ -253,12 +274,12 @@ def __toggleSettings(self):
253274

254275
self.sigUpdateUI.emit()
255276

256-
def __readData(self):
277+
def __readData(self, sep=Config.SEPERATOR, decimal=Config.DECIMAL):
257278
if not os.path.isfile(self.filename):
258279
self.data = pd.DataFrame([0, 0.001], [0, 0])
259280
return
260281

261-
self.data = pd.read_csv(self.filename, sep=Config.SEPERATOR, decimal=Config.DECIMAL, header=0, skipinitialspace=True)
282+
self.data = pd.read_csv(self.filename, sep=sep, decimal=decimal, header=0, skipinitialspace=True)
262283

263284
# applies all calculations and interpolation
264285
def recalculate(self):

ListItem.py

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def __init__(self, color, config=None, parent=None):
3838
"yOffset": 0,
3939
"xColumn": -1,
4040
"yColumn": -1,
41+
"seperator": Config.SEPERATOR,
42+
"decimal": Config.DECIMAL,
4143
"color": color,
4244
"width": 3,
4345
"interpolation": "linear",

ui/file_open_dialog.ui

+135-63
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<rect>
1010
<x>0</x>
1111
<y>0</y>
12-
<width>260</width>
13-
<height>133</height>
12+
<width>294</width>
13+
<height>249</height>
1414
</rect>
1515
</property>
1616
<property name="windowTitle">
@@ -19,67 +19,139 @@
1919
<property name="modal">
2020
<bool>true</bool>
2121
</property>
22-
<widget class="QDialogButtonBox" name="buttonBox">
23-
<property name="geometry">
24-
<rect>
25-
<x>10</x>
26-
<y>90</y>
27-
<width>241</width>
28-
<height>32</height>
29-
</rect>
30-
</property>
31-
<property name="cursor">
32-
<cursorShape>PointingHandCursor</cursorShape>
33-
</property>
34-
<property name="orientation">
35-
<enum>Qt::Horizontal</enum>
36-
</property>
37-
<property name="standardButtons">
38-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
39-
</property>
40-
</widget>
41-
<widget class="QWidget" name="formLayoutWidget">
42-
<property name="geometry">
43-
<rect>
44-
<x>10</x>
45-
<y>10</y>
46-
<width>241</width>
47-
<height>81</height>
48-
</rect>
49-
</property>
50-
<layout class="QFormLayout" name="formLayout">
51-
<item row="0" column="0">
52-
<widget class="QLabel" name="xAchseLabel">
53-
<property name="text">
54-
<string>x-Achse</string>
55-
</property>
56-
</widget>
57-
</item>
58-
<item row="0" column="1">
59-
<widget class="QComboBox" name="xComboBox"/>
60-
</item>
61-
<item row="1" column="0">
62-
<widget class="QLabel" name="yAchseLabel">
63-
<property name="text">
64-
<string>y-Achse</string>
65-
</property>
66-
</widget>
67-
</item>
68-
<item row="1" column="1">
69-
<widget class="QComboBox" name="yComboBox">
70-
<property name="sizePolicy">
71-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
72-
<horstretch>0</horstretch>
73-
<verstretch>0</verstretch>
74-
</sizepolicy>
75-
</property>
76-
<property name="cursor">
77-
<cursorShape>PointingHandCursor</cursorShape>
78-
</property>
79-
</widget>
80-
</item>
81-
</layout>
82-
</widget>
22+
<layout class="QVBoxLayout" name="verticalLayout">
23+
<item>
24+
<layout class="QFormLayout" name="formLayout">
25+
<item row="0" column="0">
26+
<widget class="QLabel" name="sepLabel">
27+
<property name="text">
28+
<string>Seperator</string>
29+
</property>
30+
</widget>
31+
</item>
32+
<item row="0" column="1">
33+
<widget class="QLineEdit" name="sepLineEdit">
34+
<property name="maxLength">
35+
<number>1</number>
36+
</property>
37+
<property name="placeholderText">
38+
<string>;</string>
39+
</property>
40+
<property name="clearButtonEnabled">
41+
<bool>false</bool>
42+
</property>
43+
</widget>
44+
</item>
45+
<item row="1" column="0">
46+
<widget class="QLabel" name="decimalLabel">
47+
<property name="text">
48+
<string>Decimal</string>
49+
</property>
50+
</widget>
51+
</item>
52+
<item row="1" column="1">
53+
<widget class="QLineEdit" name="decimalLineEdit">
54+
<property name="maxLength">
55+
<number>1</number>
56+
</property>
57+
<property name="placeholderText">
58+
<string>.</string>
59+
</property>
60+
<property name="clearButtonEnabled">
61+
<bool>false</bool>
62+
</property>
63+
</widget>
64+
</item>
65+
<item row="2" column="1">
66+
<widget class="QPushButton" name="reparseBtn">
67+
<property name="sizePolicy">
68+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
69+
<horstretch>0</horstretch>
70+
<verstretch>0</verstretch>
71+
</sizepolicy>
72+
</property>
73+
<property name="cursor">
74+
<cursorShape>PointingHandCursor</cursorShape>
75+
</property>
76+
<property name="text">
77+
<string>Reparse</string>
78+
</property>
79+
</widget>
80+
</item>
81+
<item row="3" column="1">
82+
<widget class="Line" name="line">
83+
<property name="sizePolicy">
84+
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
85+
<horstretch>1</horstretch>
86+
<verstretch>0</verstretch>
87+
</sizepolicy>
88+
</property>
89+
<property name="minimumSize">
90+
<size>
91+
<width>100</width>
92+
<height>0</height>
93+
</size>
94+
</property>
95+
<property name="autoFillBackground">
96+
<bool>false</bool>
97+
</property>
98+
<property name="frameShadow">
99+
<enum>QFrame::Raised</enum>
100+
</property>
101+
<property name="midLineWidth">
102+
<number>1</number>
103+
</property>
104+
<property name="orientation">
105+
<enum>Qt::Horizontal</enum>
106+
</property>
107+
</widget>
108+
</item>
109+
<item row="5" column="0">
110+
<widget class="QLabel" name="xAchseLabel">
111+
<property name="text">
112+
<string>x-Achse</string>
113+
</property>
114+
</widget>
115+
</item>
116+
<item row="5" column="1">
117+
<widget class="QComboBox" name="xComboBox"/>
118+
</item>
119+
<item row="6" column="0">
120+
<widget class="QLabel" name="yAchseLabel">
121+
<property name="text">
122+
<string>y-Achse</string>
123+
</property>
124+
</widget>
125+
</item>
126+
<item row="6" column="1">
127+
<widget class="QComboBox" name="yComboBox">
128+
<property name="sizePolicy">
129+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
130+
<horstretch>0</horstretch>
131+
<verstretch>0</verstretch>
132+
</sizepolicy>
133+
</property>
134+
<property name="cursor">
135+
<cursorShape>PointingHandCursor</cursorShape>
136+
</property>
137+
</widget>
138+
</item>
139+
</layout>
140+
</item>
141+
<item>
142+
<widget class="QDialogButtonBox" name="buttonBox">
143+
<property name="cursor">
144+
<cursorShape>PointingHandCursor</cursorShape>
145+
</property>
146+
<property name="orientation">
147+
<enum>Qt::Horizontal</enum>
148+
</property>
149+
<property name="standardButtons">
150+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
151+
</property>
152+
</widget>
153+
</item>
154+
</layout>
83155
</widget>
84156
<resources/>
85157
<connections>

0 commit comments

Comments
 (0)