1 | import sys |
---|
2 | import os |
---|
3 | import sqlite3 |
---|
4 | from PyQt4 import QtCore, QtGui, uic |
---|
5 | import subprocess as sub |
---|
6 | |
---|
7 | out = sub.check_output("echo $PALM_BIN", shell=True, stderr=sub.STDOUT) |
---|
8 | palm_bin = out.rstrip() |
---|
9 | |
---|
10 | qtCreatorFile = palm_bin + '/palm_gf_files/palm_gf_table.ui' |
---|
11 | |
---|
12 | Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) |
---|
13 | |
---|
14 | class MyApp3(QtGui.QMainWindow, Ui_MainWindow): |
---|
15 | |
---|
16 | class MyTableWidgetItem(QtGui.QTableWidgetItem): |
---|
17 | def __init__(self, text, sortKey): |
---|
18 | QtGui.QTableWidgetItem.__init__(self, text, QtGui.QTableWidgetItem.UserType) |
---|
19 | self.sortKey = sortKey |
---|
20 | |
---|
21 | def __lt__(self, other): |
---|
22 | return self.sortKey < other.sortKey |
---|
23 | |
---|
24 | |
---|
25 | def __init__(self): # def __init__(self, parent=None): |
---|
26 | QtGui.QMainWindow.__init__(self) |
---|
27 | Ui_MainWindow.__init__(self) |
---|
28 | |
---|
29 | framegm = self.frameGeometry() |
---|
30 | screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos()) |
---|
31 | centerpoint = QtGui.QApplication.desktop().screenGeometry(screen).center() |
---|
32 | framegm.moveCenter(centerpoint) |
---|
33 | self.move(framegm.topLeft()) |
---|
34 | self.setupUi(self) |
---|
35 | self.pushButton_3.clicked.connect(self.load_result) |
---|
36 | #self.nx_min.valueChanged.connect(self.check) |
---|
37 | self.load_trigger() |
---|
38 | self.pushButton.clicked.connect(self.filter_results) |
---|
39 | self.Sortnow_button.clicked.connect(self.sort_order) |
---|
40 | self.pushButton_2.clicked.connect(self.load_trigger) |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | def load_trigger(self): |
---|
45 | dtb = str('.palm_gf_data.db') |
---|
46 | con = sqlite3.connect(dtb) |
---|
47 | c = con.cursor() |
---|
48 | c.execute("SELECT * FROM " + 'grid_limits') |
---|
49 | mini = c.fetchone() |
---|
50 | max = c.fetchone() |
---|
51 | self.nx_min.setValue(mini[0]) |
---|
52 | self.nx_max.setValue(max[0]) |
---|
53 | self.ny_min.setValue(mini[1]) |
---|
54 | self.ny_max.setValue(max[1]) |
---|
55 | self.nz_min.setValue(mini[2]) |
---|
56 | self.nz_max.setValue(max[2]) |
---|
57 | self.npex_min.setValue(mini[3]) |
---|
58 | self.npex_max.setValue(max[3]) |
---|
59 | self.npey_min.setValue(mini[4]) |
---|
60 | self.npey_max.setValue(max[4]) |
---|
61 | self.npxnpy_min.setValue(mini[5]) |
---|
62 | self.npxnpy_max.setValue(max[5]) |
---|
63 | self.np_min.setValue(mini[6]) |
---|
64 | self.np_max.setValue(max[6]) |
---|
65 | self.ngpts_min.setValue(mini[7]) |
---|
66 | self.ngpts_max.setValue(max[7]) |
---|
67 | |
---|
68 | self.nx_min.setMinimum(mini[0]) |
---|
69 | self.nx_max.setMaximum(max[0]) |
---|
70 | self.ny_min.setMinimum(mini[1]) |
---|
71 | self.ny_max.setMaximum(max[1]) |
---|
72 | self.nz_min.setMinimum(mini[2]) |
---|
73 | self.nz_max.setMaximum(max[2]) |
---|
74 | self.npex_min.setMinimum(mini[3]) |
---|
75 | self.npex_max.setMaximum(max[3]) |
---|
76 | self.npey_min.setMinimum(mini[4]) |
---|
77 | self.npey_max.setMaximum(max[4]) |
---|
78 | self.npxnpy_min.setMinimum(mini[5]) |
---|
79 | self.npxnpy_max.setMaximum(max[5]) |
---|
80 | self.np_min.setMinimum(mini[6]) |
---|
81 | self.np_max.setMaximum(max[6]) |
---|
82 | self.ngpts_min.setMinimum(mini[7]) |
---|
83 | self.ngpts_max.setMaximum(max[7]) |
---|
84 | self.ngpts_min.setMaximum(max[7]) |
---|
85 | self.ngpts_max.setMinimum(mini[7]) |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | con.commit() |
---|
90 | c.close() |
---|
91 | con.close() |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | def check(self): |
---|
97 | dtb = str('.palm_gf_data.db') |
---|
98 | con = sqlite3.connect(dtb) |
---|
99 | c = con.cursor() |
---|
100 | c.execute("SELECT * FROM " + 'grid_limits') |
---|
101 | mini = c.fetchone() |
---|
102 | max = c.fetchone() |
---|
103 | if self.nx_min.value() < mini[0]: |
---|
104 | |
---|
105 | self.nx_min.setValue(mini[0]) |
---|
106 | |
---|
107 | |
---|
108 | def process1(self): |
---|
109 | self.calc_label.setText('loading...') |
---|
110 | QtGui.QApplication.processEvents() |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | def load_result(self): |
---|
115 | self.setEnabled(False) |
---|
116 | QtGui.QApplication.processEvents() |
---|
117 | self.load_trigger() |
---|
118 | self.process1() |
---|
119 | database = str('.palm_gf_data.db') |
---|
120 | conn = sqlite3.connect(database) |
---|
121 | c = conn.cursor() |
---|
122 | c.execute("SELECT * FROM " + 'grid_current') |
---|
123 | results = c.fetchall() |
---|
124 | |
---|
125 | self.tableWidget.setRowCount(len(results)) |
---|
126 | |
---|
127 | i = 0 |
---|
128 | j = 0 |
---|
129 | k = 0 |
---|
130 | |
---|
131 | while i < len(results): |
---|
132 | line = results[i] |
---|
133 | while j < 8: |
---|
134 | var = line[j] |
---|
135 | |
---|
136 | self.tableWidget.setItem(i, j, self.MyTableWidgetItem(str(var), j+i)) |
---|
137 | #item = self.MyTableWidgetItem(str(var), k) |
---|
138 | #self.tableWidget.setItem(i, j, item) |
---|
139 | |
---|
140 | j += 1 |
---|
141 | #if j == 3: |
---|
142 | #print(k) |
---|
143 | #k += 1 |
---|
144 | #k -= 7 |
---|
145 | k += 1 |
---|
146 | j = 0 |
---|
147 | i += 1 |
---|
148 | |
---|
149 | c.close() |
---|
150 | conn.close() |
---|
151 | self.calc_label.setText('loading completed') |
---|
152 | self.label_11.setText(str(len(results)) + ' results ') |
---|
153 | self.setEnabled(True) |
---|
154 | QtGui.QApplication.processEvents() |
---|
155 | |
---|
156 | def filter_results(self): |
---|
157 | self.setEnabled(False) |
---|
158 | self.calc_label.setText('calculating...') |
---|
159 | QtGui.QApplication.processEvents() |
---|
160 | database = str('.palm_gf_data.db') |
---|
161 | conn = sqlite3.connect(database) |
---|
162 | c = conn.cursor() |
---|
163 | c.execute("SELECT * FROM " + "grid_current") |
---|
164 | results = c.fetchall() |
---|
165 | #print(results) |
---|
166 | |
---|
167 | self.tableWidget.setRowCount(len(results)) |
---|
168 | |
---|
169 | i = 0 |
---|
170 | j = 0 |
---|
171 | row_cnt = -1 |
---|
172 | while i < len(results): |
---|
173 | line = results[i] |
---|
174 | |
---|
175 | if line[0] <= self.nx_max.value(): |
---|
176 | |
---|
177 | if line[0] >= self.nx_min.value(): |
---|
178 | |
---|
179 | if line[1] <= self.ny_max.value(): |
---|
180 | |
---|
181 | if line[1] >= self.ny_min.value(): |
---|
182 | |
---|
183 | if line[2] <= self.nz_max.value(): |
---|
184 | |
---|
185 | if line[2] >= self.nz_min.value(): |
---|
186 | |
---|
187 | if line[3] <= self.npex_max.value(): |
---|
188 | |
---|
189 | if line[3] >= self.npex_min.value(): |
---|
190 | |
---|
191 | if line[4] <= self.npey_max.value(): |
---|
192 | |
---|
193 | if line[4] >= self.npey_min.value(): |
---|
194 | |
---|
195 | if line[5] <= self.npxnpy_max.value(): |
---|
196 | |
---|
197 | if line[5] >= self.npxnpy_min.value(): |
---|
198 | |
---|
199 | if line[6] <= self.np_max.value(): |
---|
200 | |
---|
201 | if line[6] >= self.np_min.value(): |
---|
202 | |
---|
203 | if line[7] <= self.ngpts_max.value(): |
---|
204 | |
---|
205 | if line[7] >= self.ngpts_min.value(): |
---|
206 | |
---|
207 | row_cnt += 1 |
---|
208 | while j < 8: |
---|
209 | var = line[j] |
---|
210 | self.tableWidget.setItem(row_cnt, j, self.MyTableWidgetItem(str(var), i)) |
---|
211 | |
---|
212 | j += 1 |
---|
213 | |
---|
214 | j = 0 |
---|
215 | i += 1 |
---|
216 | |
---|
217 | c.close() |
---|
218 | conn.close() |
---|
219 | self.tableWidget.setRowCount(row_cnt + 1) |
---|
220 | self.setEnabled(True) |
---|
221 | self.calc_label.setText('calculation completed') |
---|
222 | self.label_11.setText(str(row_cnt + 1) + ' results') |
---|
223 | QtGui.QApplication.processEvents() |
---|
224 | |
---|
225 | |
---|
226 | |
---|
227 | |
---|
228 | |
---|
229 | def sort_order(self): |
---|
230 | |
---|
231 | sorted = 0 |
---|
232 | fnx_mn = self.nx_min.value() |
---|
233 | fnx_mx = self.nx_max.value() |
---|
234 | fny_mn = self.ny_min.value() |
---|
235 | fny_mx = self.ny_max.value() |
---|
236 | fnz_mn = self.nz_min.value() |
---|
237 | fnz_mx = self.nz_max.value() |
---|
238 | fnpex_mn = self.npex_min.value() |
---|
239 | fnpex_mx = self.npex_max.value() |
---|
240 | fnpey_mn = self.npex_min.value() |
---|
241 | fnpey_mx = self.npey_max.value() |
---|
242 | fnpxnpy_mn = self.npxnpy_min.value() |
---|
243 | fnpxnpy_mx = self.npxnpy_max.value() |
---|
244 | fnp_mn = self.np_min.value() |
---|
245 | fnp_mx = self.np_max.value() |
---|
246 | fngpts_mn = self.ngpts_min.value() |
---|
247 | fngpts_mx = self.ngpts_max.value() |
---|
248 | |
---|
249 | if str(self.Sortvariable_box.currentIndex()) == str(1): |
---|
250 | |
---|
251 | |
---|
252 | sorted_col = "nx" |
---|
253 | if str(self.Sortvariable_box.currentIndex()) == str(2): |
---|
254 | |
---|
255 | sorted_col = "ny" |
---|
256 | if str(self.Sortvariable_box.currentIndex()) == str(3): |
---|
257 | |
---|
258 | sorted_col = "nz" |
---|
259 | if str(self.Sortvariable_box.currentIndex()) == str(4): |
---|
260 | |
---|
261 | sorted_col = "npex" |
---|
262 | if str(self.Sortvariable_box.currentIndex()) == str(5): |
---|
263 | |
---|
264 | sorted_col = "npey" |
---|
265 | if str(self.Sortvariable_box.currentIndex()) == str(6): |
---|
266 | |
---|
267 | sorted_col = "npxnpy" |
---|
268 | if str(self.Sortvariable_box.currentIndex()) == str(7): |
---|
269 | |
---|
270 | sorted_col = "np" |
---|
271 | if str(self.Sortvariable_box.currentIndex()) == str(8): |
---|
272 | |
---|
273 | sorted_col = "ngpts" |
---|
274 | |
---|
275 | print(self.Sortvariable_box.currentIndex()) |
---|
276 | |
---|
277 | if str(self.Sortorder_box.currentIndex()) == str(1): |
---|
278 | |
---|
279 | order = " ASC" |
---|
280 | |
---|
281 | if str(self.Sortorder_box.currentIndex()) == str(2): |
---|
282 | |
---|
283 | order = " DESC" |
---|
284 | |
---|
285 | |
---|
286 | |
---|
287 | |
---|
288 | |
---|
289 | |
---|
290 | |
---|
291 | |
---|
292 | conn = sqlite3.connect(".palm_gf_data.db") |
---|
293 | c = conn.cursor() |
---|
294 | c.execute("SELECT * FROM grid_current WHERE nx <= " + str(fnx_mx) + " AND nx >= " + str(fnx_mn) + " AND ny <= " + str(fny_mx) + " AND ny >= " + str(fny_mn) + " AND nz <= " + str(fnz_mx) + |
---|
295 | " AND nz >= " + str(fnz_mn) + " AND npex <= " + str(fnpex_mx) + " AND npex >= " + |
---|
296 | str(fnpex_mn) + " AND npey <= " + str(fnpey_mx) + " AND npey >= " + str(fnpey_mn) + " AND " |
---|
297 | "npxnpy <= " + str(fnpxnpy_mx) + " AND npxnpy >= " + str(fnpxnpy_mn) + " AND np <= " + str(fnp_mx) + " AND np >= " + str(fnp_mn) + " AND ngpts <= " + str(fngpts_mx) + " AND ngpts >= " + str(fngpts_mn) + |
---|
298 | " ORDER BY " + str(sorted_col) + str(order)) |
---|
299 | |
---|
300 | |
---|
301 | |
---|
302 | sorted = c.fetchall() |
---|
303 | |
---|
304 | c.close() |
---|
305 | conn.close() |
---|
306 | self.tableWidget.setRowCount(len(sorted)) |
---|
307 | |
---|
308 | for row_indx in range(0,len(sorted)): |
---|
309 | |
---|
310 | for col_indx in range(0,8): |
---|
311 | row = sorted[row_indx] |
---|
312 | value = row[col_indx] |
---|
313 | self.tableWidget.setItem(row_indx, col_indx, QtGui.QTableWidgetItem(str(value))) |
---|
314 | |
---|
315 | |
---|
316 | |
---|
317 | |
---|
318 | |
---|
319 | |
---|
320 | print(len(sorted)) |
---|
321 | #print(sorted) |
---|
322 | |
---|
323 | |
---|
324 | |
---|
325 | |
---|
326 | if __name__ == "__main__": |
---|
327 | app = QtGui.QApplication(sys.argv) |
---|
328 | window = MyApp3() |
---|
329 | window.setWindowTitle('Gridfilter') |
---|
330 | window.show() |
---|
331 | sys.exit(app.exec_()) |
---|
332 | |
---|