#!/usr/bin/python -B # -*- coding: utf-8 -*- #--------------------------------------------------------------------------------# # This file is part of PALM. # # PALM is free software: you can redistribute it and/or modify it under the terms # of the GNU General Public License as published by the Free Software Foundation, # either version 3 of the License, or (at your option) any later version. # # PALM is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # PALM. If not, see . # # Copyright 1997-2017 Leibniz Universitaet Hannover #--------------------------------------------------------------------------------# # # Current revisions: # ----------------- # Initial revision # # Former revisions: # ----------------- # $Id: palm_gf 2116 2017-01-16 16:15:24Z maronga $ # # # # Description: # ------------ # # # Instructions: # ------------- # #------------------------------------------------------------------------------! import sys import os import palm_gf_files.palm_gf_exec as execute_script import palm_gf_files.palm_gf_conf as config_wr import sqlite3 import subprocess as sub from PyQt4 import QtCore, QtGui, uic from palm_gf_files.palm_gf_tools import MyApp3 # Determine PALM directories try: devnull = open(os.devnull, 'w') out = sub.check_output("echo $PALM_BIN", shell=True, stderr=sub.STDOUT) palm_bin = out.rstrip() palm_dir = out.split("palm")[0] + "palm/" + out.split("palm")[1].split("/")[1] out = None except: print "Error. $PALM_BIN is not set." raise SystemExit qtCreatorFile = palm_bin + '/palm_gf_files/palm_gf.ui' Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) class MyApp1(QtGui.QMainWindow, Ui_MainWindow): def __init__(self, parent=None): QtGui.QMainWindow.__init__(self) Ui_MainWindow.__init__(self) #self.setWindowTitle('Gridfinder') frameGm = self.frameGeometry() screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos()) centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center() frameGm.moveCenter(centerPoint) self.move(frameGm.topLeft()) self.setupUi(self) self.startbutton.clicked.connect(self.run_program) # starts grid_calculation self.psolver_box.currentIndexChanged.connect(self.vis) # triggers visibility of fft_method option self.save_button.clicked.connect(self.save_results) # saves .db file under given name self.fft_method_box.setVisible(False) self.fft_method_label.setVisible(False) self.result_headline.setVisible(False) self.result_label.setVisible(False) self.line_res_up.setVisible(False) self.line_res_down.setVisible(False) self.view_result_button.setVisible(False) self.tableWidget.setVisible(False) self.load_text_label.setVisible(False) self.nor_spinbox.setVisible(False) self.filename_line.setVisible(False) self.save_button.setVisible(False) self.view_result_button.clicked.connect(self.load_gui) #self.startbutton.clicked.connect(self.progress) #self.progressBar.setEnabled(False) #self.progressBar.setVisible(False) #def progress(self): # import time # self.progressBar.setVisible(True) # self.progressBar.setDisabled(False) # self.progressBar.setValue(10) # time.sleep(1) # self.progressBar.setValue(50) # time.sleep(1) # self.progressBar.setValue(100) # time.sleep(1) # self.progressBar.setEnabled(False) def vis(self): if str(self.psolver_box.currentIndex()) == str(1): self.fft_method_box.setVisible(True) self.fft_method_label.setVisible(True) if str(self.psolver_box.currentIndex()) != str(1): self.fft_method_box.setVisible(False) self.fft_method_label.setVisible(False) def load_gui(self): print("not yet possible") self.child_win = MyApp3() self.child_win.show() #self.load_results_2() #MyApp2(self).show() # import filter_script # upt = filter_script.MyApp2() # upt.cur_grid() def load_results(self): self.setGeometry(330, 250, 584, 622) self.tableWidget.setVisible(True) conn = sqlite3.connect(".palm_gf_data.db") c = conn.cursor() nor = int(self.nor_spinbox.value()) self.tableWidget.setRowCount(nor) c.execute("SELECT * FROM grid_current") results = c.fetchmany(nor) i = 0 j = 0 while i < nor: line = results[i] while j < 6: var = line[j] self.tableWidget.setItem(i, j, QtGui.QTableWidgetItem(str(var))) j += 1 j = 0 i += 1 c.close() conn.close() def run_program(self): self.setEnabled(False) # self.Ui_MainWindow.setDisabled(True) self.qmsg() np_min = str(self.np_min_box.value()) np_max = str(self.np_max_box.value()) nx_min = str(self.nx_min_box.value()) nx_max = str(self.nx_max_box.value()) ny_min = str(self.ny_min_box.value()) ny_max = str(self.ny_max_box.value()) nz_min = str(self.nz_min_box.value()) nz_max = str(self.nz_max_box.value()) tpn = str(self.tpn_box.value()) dnpexnpey = str(self.d_box.value()) dnxny = str(self.dnxny_box.value()) if str(self.psolver_box.currentIndex()) == str(1): poisfft = True switch = True if str(self.fft_method_box.currentIndex()) == str(2): temperton = True else: temperton = False else: poisfft = False temperton = False switch = False if str(self.psolver_box.currentIndex()) == str(2): mlt_grid = True else: mlt_grid = False if str(self.Oos_checkbox.checkState()) == str(2): spctre = True poisfft = True else: spctre = False print(poisfft, switch, temperton, mlt_grid, spctre) config_wr.write_config(np_min, np_max, nx_min, nx_max, ny_min, ny_max, nz_min, nz_max, tpn, dnpexnpey, dnxny, str(poisfft), str(switch), str(temperton), str(mlt_grid), str(spctre)) execute_script.grid_executer() #execute_script.grid_maxmin() checkfile = open(".palm_gf_tmp", "r") self.result_label.setText(str(checkfile.readline())) if int(checkfile.readline()) == 1: self.view_result_button.setVisible(True) self.result_label.setVisible(True) self.result_headline.setVisible(True) self.line_res_down.setVisible(True) self.line_res_up.setVisible(True) self.load_text_label.setVisible(False) self.nor_spinbox.setVisible(False) checkfile.close() self.setEnabled(True) self.filename_line.setVisible(True) self.save_button.setVisible(True) def load_results_2(self): database = str(".palm_gf_data.db") print(database) self.tableWidget.setVisible(True) conn = sqlite3.connect(database) # ".palm_gf_data.db" c = conn.cursor() c.execute("SELECT * FROM " + 'grid_current') # "grid_current" database[:-3] # c.execute("SELECT * FROM " + database) results = c.fetchall() self.tableWidget.setRowCount(len(results)) i = 0 j = 0 while i < len(results): line = results[i] while j < 6: var = line[j] self.tableWidget.setItem(i, j, QtGui.QTableWidgetItem(str(var))) if i == 0 and j == 0: np_min = line[0] np_max = line[0] npex_min = line[1] npex_max = line[1] npey_min = line[2] npey_max = line[2] nx_min = line[3] nx_max = line[3] ny_min = line[4] ny_max = line[4] nz_min = line[5] nz_max = line[5] else: if line[0] > np_max: np_max = line[0] if line[0] < np_min: np_min = line[0] if line[1] > npex_max: npex_max = line[1] if line[1] < npex_min: npex_min = line[1] if line[2] > npey_max: npey_max = line[2] if line[2] < npey_min: npey_min = line[2] if line[3] > nx_max: nx_max = line[3] if line[3] < nx_min: nx_min = line[3] if line[4] > ny_max: ny_max = line[4] if line[4] < ny_min: ny_min = line[4] if line[5] > nz_max: nz_max = line[5] if line[5] < nz_min: nz_min = line[5] j += 1 j = 0 i += 1 c.close() conn.close() self.np_max.setValue(np_max) self.np_min.setValue(np_min) self.npex_max.setValue(npex_max) self.npex_min.setValue(npex_min) self.npey_max.setValue(npey_max) self.npey_min.setValue(npey_min) self.nx_max.setValue(nx_max) self.nx_min.setValue(nx_min) self.ny_max.setValue(ny_max) self.ny_min.setValue(ny_min) self.nz_max.setValue(nz_max) self.nz_min.setValue(nz_min) self.np_max.setMaximum(np_max) self.np_min.setMinimum(np_min) self.npex_max.setMaximum(npex_max) self.npex_min.setMinimum(npex_min) self.npey_max.setMaximum(npey_max) self.npey_min.setMinimum(npey_min) self.nx_max.setMaximum(nx_max) self.nx_min.setMinimum(nx_min) self.ny_max.setMaximum(ny_max) self.ny_min.setMinimum(ny_min) self.nz_max.setMaximum(nz_max) self.nz_min.setMinimum(nz_min) self.nr_output_label.setText(str(len(results)) + ' results') def get_path(wildcard): import wx app = wx.App(None) style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST dialog = wx.FileDialog(None, 'Open', wildcard='*.db') if dialog.ShowModal() == wx.ID_OK: path = dialog.GetPath() print(path) else: path = None dialog.Destroy() return def save_results(self): #self.get_path() import os import shutil prvs = '.palm_gf_data.db' new = str(self.filename_line.text()) print(new) shutil.copy(prvs, new) print(prvs, new) def qmsg(self): msgbox = QtGui.QMessageBox() msgbox.setWindowTitle("Information") # msgbox.setVisible(False) msgbox.Information msgbox.setText("Calculating, please be patient.") # msgbox. msgbox.setModal(True) msgbox.exec_() if __name__ == "__main__": import time app = QtGui.QApplication(sys.argv) window = MyApp1() window.setWindowTitle('Gridfinder') window.show() sys.exit(app.exec_())