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