1 | #!/usr/bin/python -B |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | #--------------------------------------------------------------------------------# |
---|
4 | # This file is part of PALM. |
---|
5 | # |
---|
6 | # PALM is free software: you can redistribute it and/or modify it under the terms |
---|
7 | # of the GNU General Public License as published by the Free Software Foundation, |
---|
8 | # either version 3 of the License, or (at your option) any later version. |
---|
9 | # |
---|
10 | # PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
11 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
12 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
13 | # |
---|
14 | # You should have received a copy of the GNU General Public License along with |
---|
15 | # PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | # |
---|
17 | # Copyright 1997-2017 Leibniz Universitaet Hannover |
---|
18 | #--------------------------------------------------------------------------------# |
---|
19 | # |
---|
20 | # Current revisions: |
---|
21 | # ----------------- |
---|
22 | # Initial revision |
---|
23 | # |
---|
24 | # Former revisions: |
---|
25 | # ----------------- |
---|
26 | # $Id: palm_gf 2116 2017-01-16 16:15:24Z maronga $ |
---|
27 | # |
---|
28 | # |
---|
29 | # |
---|
30 | # Description: |
---|
31 | # ------------ |
---|
32 | # |
---|
33 | # |
---|
34 | # Instructions: |
---|
35 | # ------------- |
---|
36 | # |
---|
37 | #------------------------------------------------------------------------------! |
---|
38 | |
---|
39 | import sys |
---|
40 | import os |
---|
41 | import palm_gf_files.palm_gf_exec as execute_script |
---|
42 | import palm_gf_files.palm_gf_conf as config_wr |
---|
43 | import sqlite3 |
---|
44 | import subprocess as sub |
---|
45 | |
---|
46 | from PyQt4 import QtCore, QtGui, uic |
---|
47 | from palm_gf_files.palm_gf_tools import MyApp3 |
---|
48 | |
---|
49 | # Determine PALM directories |
---|
50 | try: |
---|
51 | devnull = open(os.devnull, 'w') |
---|
52 | out = sub.check_output("echo $PALM_BIN", shell=True, stderr=sub.STDOUT) |
---|
53 | palm_bin = out.rstrip() |
---|
54 | palm_dir = out.split("palm")[0] + "palm/" + out.split("palm")[1].split("/")[1] |
---|
55 | out = None |
---|
56 | except: |
---|
57 | print "Error. $PALM_BIN is not set." |
---|
58 | raise SystemExit |
---|
59 | |
---|
60 | qtCreatorFile = palm_bin + '/palm_gf_files/palm_gf.ui' |
---|
61 | |
---|
62 | Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) |
---|
63 | |
---|
64 | |
---|
65 | class MyApp1(QtGui.QMainWindow, Ui_MainWindow): |
---|
66 | def __init__(self, parent=None): |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | QtGui.QMainWindow.__init__(self) |
---|
71 | Ui_MainWindow.__init__(self) |
---|
72 | #self.setWindowTitle('Gridfinder') |
---|
73 | |
---|
74 | frameGm = self.frameGeometry() |
---|
75 | screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos()) |
---|
76 | centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center() |
---|
77 | frameGm.moveCenter(centerPoint) |
---|
78 | self.move(frameGm.topLeft()) |
---|
79 | |
---|
80 | self.setupUi(self) |
---|
81 | self.startbutton.clicked.connect(self.run_program) # starts grid_calculation |
---|
82 | self.psolver_box.currentIndexChanged.connect(self.vis) # triggers visibility of fft_method option |
---|
83 | self.save_button.clicked.connect(self.save_results) # saves .db file under given name |
---|
84 | self.fft_method_box.setVisible(False) |
---|
85 | self.fft_method_label.setVisible(False) |
---|
86 | self.result_headline.setVisible(False) |
---|
87 | self.result_label.setVisible(False) |
---|
88 | self.line_res_up.setVisible(False) |
---|
89 | self.line_res_down.setVisible(False) |
---|
90 | self.view_result_button.setVisible(False) |
---|
91 | self.tableWidget.setVisible(False) |
---|
92 | self.load_text_label.setVisible(False) |
---|
93 | self.nor_spinbox.setVisible(False) |
---|
94 | self.filename_line.setVisible(False) |
---|
95 | self.save_button.setVisible(False) |
---|
96 | self.view_result_button.clicked.connect(self.load_gui) |
---|
97 | |
---|
98 | #self.startbutton.clicked.connect(self.progress) |
---|
99 | #self.progressBar.setEnabled(False) |
---|
100 | #self.progressBar.setVisible(False) |
---|
101 | |
---|
102 | #def progress(self): |
---|
103 | # import time |
---|
104 | # self.progressBar.setVisible(True) |
---|
105 | # self.progressBar.setDisabled(False) |
---|
106 | # self.progressBar.setValue(10) |
---|
107 | # time.sleep(1) |
---|
108 | # self.progressBar.setValue(50) |
---|
109 | # time.sleep(1) |
---|
110 | # self.progressBar.setValue(100) |
---|
111 | # time.sleep(1) |
---|
112 | # self.progressBar.setEnabled(False) |
---|
113 | |
---|
114 | def vis(self): |
---|
115 | |
---|
116 | if str(self.psolver_box.currentIndex()) == str(1): |
---|
117 | self.fft_method_box.setVisible(True) |
---|
118 | self.fft_method_label.setVisible(True) |
---|
119 | |
---|
120 | if str(self.psolver_box.currentIndex()) != str(1): |
---|
121 | self.fft_method_box.setVisible(False) |
---|
122 | self.fft_method_label.setVisible(False) |
---|
123 | |
---|
124 | def load_gui(self): |
---|
125 | print("not yet possible") |
---|
126 | self.child_win = MyApp3() |
---|
127 | self.child_win.show() |
---|
128 | #self.load_results_2() |
---|
129 | #MyApp2(self).show() |
---|
130 | # import filter_script |
---|
131 | # upt = filter_script.MyApp2() |
---|
132 | # upt.cur_grid() |
---|
133 | |
---|
134 | def load_results(self): |
---|
135 | self.setGeometry(330, 250, 584, 622) |
---|
136 | self.tableWidget.setVisible(True) |
---|
137 | conn = sqlite3.connect(".palm_gf_data.db") |
---|
138 | c = conn.cursor() |
---|
139 | nor = int(self.nor_spinbox.value()) |
---|
140 | self.tableWidget.setRowCount(nor) |
---|
141 | c.execute("SELECT * FROM grid_current") |
---|
142 | results = c.fetchmany(nor) |
---|
143 | i = 0 |
---|
144 | j = 0 |
---|
145 | |
---|
146 | while i < nor: |
---|
147 | line = results[i] |
---|
148 | while j < 6: |
---|
149 | var = line[j] |
---|
150 | |
---|
151 | self.tableWidget.setItem(i, j, QtGui.QTableWidgetItem(str(var))) |
---|
152 | |
---|
153 | j += 1 |
---|
154 | j = 0 |
---|
155 | i += 1 |
---|
156 | |
---|
157 | c.close() |
---|
158 | conn.close() |
---|
159 | |
---|
160 | def run_program(self): |
---|
161 | self.setEnabled(False) |
---|
162 | # self.Ui_MainWindow.setDisabled(True) |
---|
163 | self.qmsg() |
---|
164 | np_min = str(self.np_min_box.value()) |
---|
165 | np_max = str(self.np_max_box.value()) |
---|
166 | nx_min = str(self.nx_min_box.value()) |
---|
167 | nx_max = str(self.nx_max_box.value()) |
---|
168 | ny_min = str(self.ny_min_box.value()) |
---|
169 | ny_max = str(self.ny_max_box.value()) |
---|
170 | nz_min = str(self.nz_min_box.value()) |
---|
171 | nz_max = str(self.nz_max_box.value()) |
---|
172 | tpn = str(self.tpn_box.value()) |
---|
173 | dnpexnpey = str(self.d_box.value()) |
---|
174 | dnxny = str(self.dnxny_box.value()) |
---|
175 | |
---|
176 | if str(self.psolver_box.currentIndex()) == str(1): |
---|
177 | poisfft = True |
---|
178 | switch = True |
---|
179 | if str(self.fft_method_box.currentIndex()) == str(2): |
---|
180 | temperton = True |
---|
181 | else: |
---|
182 | temperton = False |
---|
183 | else: |
---|
184 | poisfft = False |
---|
185 | temperton = False |
---|
186 | switch = False |
---|
187 | |
---|
188 | if str(self.psolver_box.currentIndex()) == str(2): |
---|
189 | mlt_grid = True |
---|
190 | else: |
---|
191 | mlt_grid = False |
---|
192 | |
---|
193 | if str(self.Oos_checkbox.checkState()) == str(2): |
---|
194 | spctre = True |
---|
195 | poisfft = True |
---|
196 | else: |
---|
197 | spctre = False |
---|
198 | print(poisfft, switch, temperton, mlt_grid, spctre) |
---|
199 | config_wr.write_config(np_min, np_max, nx_min, nx_max, ny_min, ny_max, nz_min, nz_max, tpn, dnpexnpey, dnxny, |
---|
200 | str(poisfft), str(switch), str(temperton), str(mlt_grid), str(spctre)) |
---|
201 | execute_script.grid_executer() |
---|
202 | #execute_script.grid_maxmin() |
---|
203 | checkfile = open(".palm_gf_tmp", "r") |
---|
204 | self.result_label.setText(str(checkfile.readline())) |
---|
205 | if int(checkfile.readline()) == 1: |
---|
206 | self.view_result_button.setVisible(True) |
---|
207 | self.result_label.setVisible(True) |
---|
208 | self.result_headline.setVisible(True) |
---|
209 | self.line_res_down.setVisible(True) |
---|
210 | self.line_res_up.setVisible(True) |
---|
211 | self.load_text_label.setVisible(False) |
---|
212 | self.nor_spinbox.setVisible(False) |
---|
213 | checkfile.close() |
---|
214 | self.setEnabled(True) |
---|
215 | self.filename_line.setVisible(True) |
---|
216 | self.save_button.setVisible(True) |
---|
217 | |
---|
218 | def load_results_2(self): |
---|
219 | |
---|
220 | database = str(".palm_gf_data.db") |
---|
221 | print(database) |
---|
222 | self.tableWidget.setVisible(True) |
---|
223 | conn = sqlite3.connect(database) # ".palm_gf_data.db" |
---|
224 | c = conn.cursor() |
---|
225 | c.execute("SELECT * FROM " + 'grid_current') # "grid_current" database[:-3] |
---|
226 | # c.execute("SELECT * FROM " + database) |
---|
227 | results = c.fetchall() |
---|
228 | |
---|
229 | self.tableWidget.setRowCount(len(results)) |
---|
230 | |
---|
231 | i = 0 |
---|
232 | j = 0 |
---|
233 | |
---|
234 | while i < len(results): |
---|
235 | line = results[i] |
---|
236 | while j < 6: |
---|
237 | var = line[j] |
---|
238 | |
---|
239 | self.tableWidget.setItem(i, j, QtGui.QTableWidgetItem(str(var))) |
---|
240 | |
---|
241 | if i == 0 and j == 0: |
---|
242 | np_min = line[0] |
---|
243 | np_max = line[0] |
---|
244 | npex_min = line[1] |
---|
245 | npex_max = line[1] |
---|
246 | npey_min = line[2] |
---|
247 | npey_max = line[2] |
---|
248 | nx_min = line[3] |
---|
249 | nx_max = line[3] |
---|
250 | ny_min = line[4] |
---|
251 | ny_max = line[4] |
---|
252 | nz_min = line[5] |
---|
253 | nz_max = line[5] |
---|
254 | else: |
---|
255 | if line[0] > np_max: |
---|
256 | np_max = line[0] |
---|
257 | if line[0] < np_min: |
---|
258 | np_min = line[0] |
---|
259 | if line[1] > npex_max: |
---|
260 | npex_max = line[1] |
---|
261 | if line[1] < npex_min: |
---|
262 | npex_min = line[1] |
---|
263 | if line[2] > npey_max: |
---|
264 | npey_max = line[2] |
---|
265 | if line[2] < npey_min: |
---|
266 | npey_min = line[2] |
---|
267 | if line[3] > nx_max: |
---|
268 | nx_max = line[3] |
---|
269 | if line[3] < nx_min: |
---|
270 | nx_min = line[3] |
---|
271 | if line[4] > ny_max: |
---|
272 | ny_max = line[4] |
---|
273 | if line[4] < ny_min: |
---|
274 | ny_min = line[4] |
---|
275 | if line[5] > nz_max: |
---|
276 | nz_max = line[5] |
---|
277 | if line[5] < nz_min: |
---|
278 | nz_min = line[5] |
---|
279 | |
---|
280 | j += 1 |
---|
281 | j = 0 |
---|
282 | i += 1 |
---|
283 | |
---|
284 | c.close() |
---|
285 | conn.close() |
---|
286 | |
---|
287 | self.np_max.setValue(np_max) |
---|
288 | |
---|
289 | self.np_min.setValue(np_min) |
---|
290 | self.npex_max.setValue(npex_max) |
---|
291 | self.npex_min.setValue(npex_min) |
---|
292 | self.npey_max.setValue(npey_max) |
---|
293 | self.npey_min.setValue(npey_min) |
---|
294 | self.nx_max.setValue(nx_max) |
---|
295 | self.nx_min.setValue(nx_min) |
---|
296 | self.ny_max.setValue(ny_max) |
---|
297 | self.ny_min.setValue(ny_min) |
---|
298 | self.nz_max.setValue(nz_max) |
---|
299 | self.nz_min.setValue(nz_min) |
---|
300 | self.np_max.setMaximum(np_max) |
---|
301 | self.np_min.setMinimum(np_min) |
---|
302 | self.npex_max.setMaximum(npex_max) |
---|
303 | self.npex_min.setMinimum(npex_min) |
---|
304 | self.npey_max.setMaximum(npey_max) |
---|
305 | self.npey_min.setMinimum(npey_min) |
---|
306 | self.nx_max.setMaximum(nx_max) |
---|
307 | self.nx_min.setMinimum(nx_min) |
---|
308 | self.ny_max.setMaximum(ny_max) |
---|
309 | self.ny_min.setMinimum(ny_min) |
---|
310 | self.nz_max.setMaximum(nz_max) |
---|
311 | self.nz_min.setMinimum(nz_min) |
---|
312 | |
---|
313 | self.nr_output_label.setText(str(len(results)) + ' results') |
---|
314 | |
---|
315 | |
---|
316 | |
---|
317 | def get_path(wildcard): |
---|
318 | import wx |
---|
319 | app = wx.App(None) |
---|
320 | style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST |
---|
321 | dialog = wx.FileDialog(None, 'Open', wildcard='*.db') |
---|
322 | if dialog.ShowModal() == wx.ID_OK: |
---|
323 | path = dialog.GetPath() |
---|
324 | print(path) |
---|
325 | else: |
---|
326 | path = None |
---|
327 | dialog.Destroy() |
---|
328 | return |
---|
329 | |
---|
330 | |
---|
331 | |
---|
332 | def save_results(self): |
---|
333 | |
---|
334 | #self.get_path() |
---|
335 | |
---|
336 | |
---|
337 | |
---|
338 | import os |
---|
339 | import shutil |
---|
340 | prvs = '.palm_gf_data.db' |
---|
341 | new = str(self.filename_line.text()) |
---|
342 | print(new) |
---|
343 | shutil.copy(prvs, new) |
---|
344 | print(prvs, new) |
---|
345 | |
---|
346 | def qmsg(self): |
---|
347 | msgbox = QtGui.QMessageBox() |
---|
348 | msgbox.setWindowTitle("Information") |
---|
349 | # msgbox.setVisible(False) |
---|
350 | msgbox.Information |
---|
351 | msgbox.setText("Calculating, please be patient.") |
---|
352 | # msgbox. |
---|
353 | msgbox.setModal(True) |
---|
354 | msgbox.exec_() |
---|
355 | |
---|
356 | |
---|
357 | if __name__ == "__main__": |
---|
358 | import time |
---|
359 | app = QtGui.QApplication(sys.argv) |
---|
360 | window = MyApp1() |
---|
361 | window.setWindowTitle('Gridfinder') |
---|
362 | window.show() |
---|
363 | sys.exit(app.exec_()) |
---|