Index: palm/trunk/SCRIPTS/palm_gf
===================================================================
--- palm/trunk/SCRIPTS/palm_gf	(revision 4843)
+++ palm/trunk/SCRIPTS/palm_gf	(revision 4869)
@@ -1,3 +1,3 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 #--------------------------------------------------------------------------------#
@@ -20,17 +20,20 @@
 # Current revisions:
 # -----------------
-# 
-# 
+#
+#
 # Former revisions:
 # -----------------
 # $Id$
+# Modified palm_gf using python3 (edited by JR and RM)
+#
+# 4843 2021-01-15 15:22:11Z schwenkel
 # Removed PALM_BIN dependency
-# 
+#
 # 2825 2018-02-20 21:48:27Z maronga
 # Modified header
-# 
+#
 # 2718 2018-01-02 08:49:38Z maronga
 # Corrected "Former revisions" section
-# 
+#
 # 2696 2017-12-14 17:12:51Z kanani
 # Change in file header (GPL part)
@@ -44,10 +47,10 @@
 # 2116 2017-01-16 16:15:24Z maronga
 # Initial revision
-# 
-# 
+#
+#
 #
 # Description:
 # ------------
-# 
+#
 #
 # Instructions:
@@ -56,21 +59,14 @@
 #------------------------------------------------------------------------------!
 
+from PyQt5 import QtWidgets, uic
+from PyQt5.QtWidgets import QDesktopWidget
+from palm_gf_files.palm_gf_conf import cfg_write, cfg_read
 import sys
 import os
-import time
-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, Qt
-from PyQt4.QtCore import QCoreApplication
-from palm_gf_files.palm_gf_tools import MyApp3
-
-# Determine PALM directories
-# Determine PALM directories
-try: 
-   devnull = open(os.devnull, 'w')      
+from palm_gf_files.palm_gf_exec import MyThread
+from palm_gf_files.palm_gf_tools import MyTable
+
+try:
+   devnull = open(os.devnull, 'w')
    palm_dir = os.getcwd()
    palm_bin = palm_dir + '/trunk/SCRIPTS'
@@ -80,726 +76,217 @@
       # file found
       out = None
-except:   
+except:
    print ('Error. palm_gf probably called in wrong directory.')
    raise SystemExit
 
-qtCreatorFile = palm_bin + '/palm_gf_files/palm_gf.ui'
-
-Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
-
-
-class MyApp1(QtGui.QMainWindow, Ui_MainWindow):
+class AppMain(QtWidgets.QMainWindow):
     def __init__(self):
-
-
-
-        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())
-
-
-        #centerPoint = str(centerPoint)
-        #xcenter = centerPoint.split('(')[1].split(',')[0]
-        #ycenter = centerPoint.split('(')[1].split(',')[1].split(')')[0]
-        #print xcenter, ycenter
-        #centerPoint = QtCore.QPoint(int(xcenter) - 418, int(ycenter))
-        #frameGm.moveCenter(centerPoint)
-        #self.move(frameGm.topLeft())
-
-        self.setupUi(self)
-        self.startbutton.clicked.connect(self.input_check)  # 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.testbar.setVisible(False)
-        self.d_box.setVisible(False)
-        self.tpn_box.setVisible(False)
-        self.tolerance_bar.setVisible(False)
-        self.tolerance_value.setVisible(False)
-        self.view_result_button.clicked.connect(self.load_gui)
-        self.threadclass = Threadclass()
-        self.actionSetting.triggered.connect(self.settings)
-        self.question_box.clicked.connect(self.settings)
-        self.warning_label.setVisible(False)
-
-
-
-
-    def closeEvent(self, QCloseEvent):
-
-        config_wr.closing_cleanup()
-        QCloseEvent.accept()
-
-
-    def input_check(self):
-
-        if int(self.nx_min_box.value()) <= int(self.nx_max_box.value()) and int(self.ny_min_box.value()) <= int(self.nx_max_box.value()) and int(self.nz_min_box.value()) <= int(self.nz_max_box.value()):
-            self.warning_label.setVisible(False)
-            self.run_program()
-
-        else:
-
-            self.warning_label.setStyleSheet('color: red')
-            self.warning_label.setVisible(True)
-
-
-
-
-
-
-
-    def settings(self):
-
-        self.w = MyPopup()
-        #self.w.setGeometry(Qt.QRect(100, 100, 400, 200))
-        frameGm = self.frameGeometry()
-        screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
-        centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
-        frameGm.moveCenter(centerPoint)
-        self.w.move(frameGm.topLeft())
-        self.w.show()
-
-
-
-    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):
-        self.child_win = MyApp3()
-        self.child_win.show()
-
-    def run_transfer(self):
-        self.threadclass = Threadclass()
-        self.connect(self.threadclass, QtCore.SIGNAL('finish'), self.behind_run)
-        #self.connect(self.threadclass, QtCore.SIGNAL('progress'), self.up2date)
-        self.connect(self.threadclass, QtCore.SIGNAL('startqmsg'), self.takeoff)
-        self.connect(self.threadclass, QtCore.SIGNAL('check'), self.checkme)
-        self.threadclass.runx()
-
-    def run_program(self):
-
-
-        self.result_label.setText('Starting calculation...')
-        #self.QtCore.QCoreApplication.processEvents()
-        QtGui.QApplication.processEvents()
-        #self.setEnabled(False)
-        # self.Ui_MainWindow.setDisabled(True)
-        #self.qmsg_wait(0)
-        #print("bool state ", self.npex_npey_box.checkState())                                 # XXX
-        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())
-        dnpexnpey_tolerance = str(self.tolerance_value.value())
-        dnxny = str(self.dnxny_box.value())
-        myobject = MyPopup()
-        ld_thrs = myobject.load_thres.value()
-        rslt_thrs = myobject.result_thres.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:
+        super(AppMain, self).__init__()
+        uic.loadUi(palm_bin + '/palm_gf_files/palm_gf.ui', self)
+        self.center_window()
+        
+        
+        # initial hiding of results ui elements
+        self.result_visibility(False)
+        # dis/enable ui elements when un/checked
+        self.strict_matching_check.stateChanged.connect(self.strict_matching_able)
+        self.npex_npey_ratio_check.stateChanged.connect(self.npex_npey_ratio_able)
+        self.nx_ny_ratio_check.stateChanged.connect(self.nx_ny_ratio_able)
+        self.psolver_combo_box.currentIndexChanged.connect(self.fft_method_able)
+        # loading last used values into ui
+        self.startup_values()
+        # making sure max is not less than min
+        self.nx_min_box.valueChanged.connect(self.input_min_max_check)
+        self.ny_min_box.valueChanged.connect(self.input_min_max_check)
+        self.nz_min_box.valueChanged.connect(self.input_min_max_check)
+        self.proc_min_box.valueChanged.connect(self.input_min_max_check)
+        # connects main buttons to subroutines
+        self.start_button.clicked.connect(self.initialize)
+        self.view_button.clicked.connect(self.load_table)
+        self.reset_button.clicked.connect(self.reset_values)
+
+    def load_table(self):
+        # opens table Ui
+        self.table = MyTable()
+        self.table.show()
+
+    def initialize(self):
+        # translating Ui input into checks used during calculation
+        if self.psolver_combo_box.currentIndex() != 0:
+            if self.psolver_combo_box.currentIndex() == 1:
+                poisfft = True
+                switch = True
+                if self.fft_combo_box.currentIndex() == 2:
+                    temperton = True
+                else:
+                    temperton = False
+            else:
+                poisfft = False
                 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
-
-        if int(self.strict_box.checkState()) != 2:
-            tpn = 0
-
-        if int(self.npex_npey_box.checkState()) != 2:
-            dnpexnpey = 0
-            dnpexnpey_tolerance = 0
-
-        #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,dnpexnpey_tolerance, dnxny,
-                               str(poisfft), str(switch), str(temperton), str(mlt_grid), str(spctre), rslt_thrs, ld_thrs)
-        #time.sleep(1)
-        # execute_script.grid_executer() temp deactive
-        self.testbar.setVisible(True)
-        QtCore.QCoreApplication.processEvents()
-        self.run_transfer()
-
-
-    def behind_run(self):
-        trigger_bool = False
-        #print("behind_run executed")
-        checkfile = open(".palm_gf_tmp", "r")
-        #self.result_label.setText(str(checkfile.readline()))
-        res_text = str(checkfile.readline())          # XXX
-        self.result_label.setText(res_text)
-        result_nr = res_text.split(' ')[2]
-        if int(checkfile.readline()) == 1:
-            self.view_result_button.setVisible(True)
-            trigger_bool = 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)
-        parameters = config_wr.read_config()
-
-
-        if trigger_bool is True and int(result_nr) < int(parameters[18]):
-            self.result_label.setText(res_text + 'Loading Ui...')
-            self.load_gui()                                              # XXXX
-            self.result_label.setText(res_text)
-            #self.close()
-            #frameGm = self.frameGeometry()
-            #screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
-            #centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
-            #frameGm = self.frameGeometry()
-            #screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
-            #centerPoint = str(centerPoint)
-            #xcenter = centerPoint.split('(')[1].split(',')[0]
-            #ycenter = centerPoint.split('(')[1].split(',')[1].split(')')[0]
-            ##print xcenter, ycenter
-            #centerPoint = QtCore.QPoint(int(xcenter) - 292, int(ycenter))
-            #frameGm.moveCenter(centerPoint)
-            #self.move(frameGm.topLeft())
-
-
-
-
-
-
-
-    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, file)
-        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_()
-
-    def tester(self):
-        #print("tester was executed from run method")
-        pass
-
-    def qmsg_wait(self, progress):
-        global msgbox
-        msgbox = QtGui.QMessageBox()
-        layout = msgbox.layout()
-        layout.itemAtPosition(layout.rowCount() - 1, 0).widget().hide()
-        global progressx
-        progressx = QtGui.QProgressBar()
-        layout.addWidget(progressx, layout.rowCount(), 0, 1, layout.columnCount())
-
-        msgbox.setWindowTitle("Progress")
-        msgbox.Information
-        msgbox.setText("Calculating, please be patient.")
-
-        progressx.setValue(int(progress))
-        #msgbox.setModal(False)
-        msgbox.exec_()
-
-    def up2date(self, progress):
-
-        progressx.setValue(int(progress))
-        if progress == 100:
-            msgbox.done(1)
-
-    def takeoff(self):
-        #self.qmsg_wait(0)
-        pass
-
-    def checkme(self, check):
-        #print(check)
-        self.testbar.setValue(int(check))
-
-        if check == 100:
-            self.testbar.setVisible(False)
-        QtGui.QApplication.processEvents()
-
-
-
-
-
-class Threadclass(QtCore.QThread):
-    def __init__(self, parent = None):
-        super(Threadclass, self).__init__(parent)
-
-    def runx(self):
-        #print("runx exec.")
-        self.execute()
-
-
-
-    def execute(self):
-        self.emit(QtCore.SIGNAL('startqmsg'), 0)
-
-        parameters = config_wr.read_config()
-        min_procs = int(parameters[0])
-        max_procs = int(parameters[1])
-        tpn = int(parameters[2])
-        dnpexnpey = float(parameters[3])
-        dnpexnpey_tol = int(parameters[4])
-        dnxny = float(parameters[5])
-        nx_min = int(parameters[6])
-        nx_max = int(parameters[7])
-        ny_min = int(parameters[8])
-        ny_max = int(parameters[9])
-        nz_min = int(parameters[10])
-        nz_max = int(parameters[11])
-        poisfft = parameters[12]
-        switch = parameters[13]
-        tempterton = parameters[14]
-        mlt_grid = parameters[15]
-        spectr = parameters[16]
-        result_thrs = parameters[17]
-
-
-        path = "/localdata/.palm_gf_data.db"
-        pathx = parameters[19] + '/.palm_gf_data.db'
-
-
-        conn = sqlite3.connect(pathx)
-        #conn = sqlite3.connect(".palm_gf_data.db")
-        c = conn.cursor()
-        c.execute("DROP TABLE IF EXISTS grid_current")
-        c.execute("DROP TABLE IF EXISTS grid_limits")
-        c.execute(
-            "CREATE TABLE IF NOT EXISTS grid_current(nx INT, ny INT, nz INT, npex INT, npey INT, npxnpy FLOAT, np INT, ngpts INT, nxnpex FLOAT, nynpey FLOAT)")
-        c.execute(
-            "CREATE TABLE IF NOT EXISTS grid_limits(nx INT, ny INT, nz INT, npex INT, npey INT, npxnpy FLOAT, np INT, ngpts INT, nxnpex FLOAT, nynpey FLOAT)")
-        conn.commit()
-        main_bool = True
-
-
-
-
-        if poisfft == str(True):
-            poisfft = True
-        else:
-            poisfft = False
-
-        if switch == str(True):
-            switch = True
-        else:
-            switch = False
-
-        if tempterton == str(True):
-            tempterton = True
-        else:
-            tempterton = False
-
-        if mlt_grid == str(True):
-            mlt_grid = True
-        else:
-            mlt_grid = False
-
-        if spectr == str(True):
-            spectr = True
-        else:
-            spectr = False
-
-        #print(spectr, type(spectr))
-        #print(poisfft, switch, tempterton, mlt_grid, spectr)
-
-        np_used = min_procs
-        counter = 0
-
-        nx = nx_min
-        ny = ny_min
-        nz = nz_min
-
-        from math import floor
-
-        def factors(n):
-            result = []
-            for i in range(2, n + 1):  # test all integers between 2 and n
-                s = 0
-                while n / i == floor(n / float(i)):  # is n/i an integer?
-                    n = n / float(i)
-                    s += 1
-                if s > 0:
-                    for k in range(s):
-                        result.append(i)  # i is a pf s times
-                        if n == 1:
-                            return result
-
-        while np_used <= max_procs:
-            a = 1
-
-            while a <= np_used:
-                prcs_var = np_used % a
-                if prcs_var != 0:
-                    a += 1
-                elif prcs_var == 0:
-                    npex = a
-                    npey = int(np_used / npex)
-
-                    if tpn != 0:                                   # XXX
-
-                        if np_used % tpn != 0:
-                            a += 1
-                            continue
-
-                    if dnpexnpey != 0 and npex / npey != dnpexnpey:
-                        a += 1
-                        continue
-
-                    if dnpexnpey != 0:
-
-
-                        if float(npex) / float(npey) < (dnpexnpey - dnpexnpey*dnpexnpey_tol/100):
-                            a += 1
-                            continue
-
-                        if float(npex) / float(npey) > (dnpexnpey + dnpexnpey*dnpexnpey_tol/100):
-                            a += 1
-                            continue
-
-                    while nx <= nx_max:
-                        if (nx + 1) % npex != 0:
-                            nx += 1
-                            continue
-
-                        if mlt_grid is True and (nx + 1) % 2 != 0:
-                            nx += 1
-                            continue
-
-                        if switch is True and (nx + 1) % npey != 0:
-                            nx += 1
-                            continue
-                        if npex > nx:
-                            nx += 1
-                            continue
-
-                        while ny <= ny_max:
-
-                            if dnxny != 0 and float(nx) / float(ny) != float(dnxny):
-                                ny += 1
-                                continue
-                            if (ny + 1) % npey != 0:
-                                ny += 1
-                                continue
-
-                            #if mlt_grid is True and ny % 2 != 0:       mlt and mlt_noOpt have same cond.
-                            #    ny += 1
-                            #    continue
-
-                            if (ny + 1) % npex != 0 and switch is True:
-                                ny += 1
-                                continue
-                            if npey > ny:
-                                ny += 1
-                                continue
-
-                            while nz <= nz_max:
-
-                                if mlt_grid is True and nz % 2 != 0:
-                                    nz += 1
-                                    continue
-
-                                if poisfft is True and nz % npex != 0:
-                                    nz += 1
-                                    continue
-
-                                if spectr is True and nz % npey != 0:
-                                    nz += 1
-                                    continue
-
-                                if tempterton is True and nx > 1 and ny > 1:  # and nz < 1:
-
-                                    nx_list = factors(nx + 1)
-
-                                    i = 0
-                                    nx_var = nx_list[i]
-
-
-                                    while i < len(nx_list):
-                                        if nx_var != 2 or nx_var != 3 or nx_var != 5:
-                                            i += 1
-                                            continue
-
-                                        i += 1
-                                    ny_list = factors(ny + 1)
-                                    i = 0
-                                    ny_var = ny_list[i]
-                                    while i < len(ny_list):
-                                        if ny_var != 2 or ny_var != 3 or ny_var != 5:
-                                            i += 1
-                                            continue
-                                        i += 1
-
-                                counter += 1
-                                if counter > int(result_thrs):
-                                    break
-
-                                npxnpy = format(float(npex) / float(npey), '.2f')
-                                nxpex = float(nx+1) /float(npex)
-                                nypey = float(ny+1) /float(npey)
-
-                                c.execute(
-                                    """INSERT OR REPLACE INTO grid_current(nx, ny, nz, npex, npey, npxnpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
-                                    (nx, ny, nz, npex, npey, npxnpy, (npex * npey), (nx * ny * nz), nxpex, nypey))
-
-                                nz += 1
-                            nz = nz_min
-                            ny += 1
-                        ny = ny_min
-                        nx += 1
-                    nx = nx_min
-                    a += 1
-                    #  a += 1
-            np_used += 1
-            progr_act = 100*(float(np_used-1)/float(max_procs))
-            self.emit(QtCore.SIGNAL('check'), progr_act)
-            #print(np_used, max_procs, progr_act)
-            self.emit(QtCore.SIGNAL('progress'), progr_act)
-
-            conn.commit()
-
-        conn.commit()
-        #c.close()
-        #conn.close()
-        #
-        ## ********************************
-        #
-        #conn = sqlite3.connect(parameters[19] + '/.palm_gf_data.db')
-        #print parameters[19] + '/.palm_gf_data.db'
-        #c = conn.cursor()
-        try:
-            c.execute("SELECT nx FROM grid_current ORDER BY nx DESC LIMIT 1")
-            mx_nx = c.fetchone()[0]
-            # print(mx_nx)
-            c.execute("SELECT nx FROM grid_current ORDER BY nx  LIMIT 1")
-            mn_nx = c.fetchone()[0]
-            # print(mn_nx)
-            c.execute("SELECT ny FROM grid_current ORDER BY ny DESC LIMIT 1")
-            mx_ny = c.fetchone()[0]
-            # print(mx_ny)
-            c.execute("SELECT ny FROM grid_current ORDER BY ny  LIMIT 1")
-            mn_ny = c.fetchone()[0]
-            # print(mn_ny)
-            c.execute("SELECT nz FROM grid_current ORDER BY nz DESC LIMIT 1")
-            mx_nz = c.fetchone()[0]
-            # print(mx_nz)
-            c.execute("SELECT nz FROM grid_current ORDER BY nz  LIMIT 1")
-            mn_nz = c.fetchone()[0]
-            # print(mn_nz)
-            c.execute("SELECT npex FROM grid_current ORDER BY npex DESC LIMIT 1")
-            mx_npex = c.fetchone()[0]
-            # print(mx_npex)
-            c.execute("SELECT npex FROM grid_current ORDER BY npex  LIMIT 1")
-            mn_npex = c.fetchone()[0]
-            # print(mn_npex)
-            c.execute("SELECT npey FROM grid_current ORDER BY npey DESC LIMIT 1")
-            mx_npey = c.fetchone()[0]
-            # print(mx_npey)
-            c.execute("SELECT npey FROM grid_current ORDER BY npey  LIMIT 1")
-            mn_npey = c.fetchone()[0]
-            # print(mn_npey)
-            c.execute("SELECT npxnpy FROM grid_current ORDER BY npxnpy DESC LIMIT 1")
-            mx_npxnpy = c.fetchone()[0]
-            # print(mx_npxnpy)
-            c.execute("SELECT npxnpy FROM grid_current ORDER BY npxnpy  LIMIT 1")
-            mn_npxnpy = c.fetchone()[0]
-            # print(mn_npxnpy)
-            c.execute("SELECT np FROM grid_current ORDER BY np DESC LIMIT 1")
-            mx_np = c.fetchone()[0]
-            # print(mx_np)
-            c.execute("SELECT np FROM grid_current ORDER BY np LIMIT 1")
-            mn_np = c.fetchone()[0]
-            # print(mn_np)
-            c.execute("SELECT ngpts FROM grid_current ORDER BY ngpts DESC LIMIT 1")
-            mx_ngpts = c.fetchone()[0]
-            # print(mx_ngpts)
-            c.execute("SELECT ngpts FROM grid_current ORDER BY ngpts LIMIT 1")
-            mn_ngpts = c.fetchone()[0]
-            # print(mn_ngpts)
-            c.execute("SELECT nxnpex FROM grid_current ORDER BY nxnpex DESC LIMIT 1")
-            mx_nxpex = c.fetchone()[0]
-            c.execute("SELECT nxnpex FROM grid_current ORDER BY nxnpex LIMIT 1")
-            mn_nxpex = c.fetchone()[0]
-            c.execute("SELECT nynpey FROM grid_current ORDER BY nynpey DESC LIMIT 1")
-            mx_nypey = c.fetchone()[0]
-            c.execute("SELECT nynpey FROM grid_current ORDER BY nynpey LIMIT 1")
-            mn_nypey = c.fetchone()[0]
-
-
-
-            conn.commit()
-            c.execute(
-                """INSERT OR REPLACE INTO grid_limits(nx, ny, nz, npex, npey, npxnpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
-                (mn_nx, mn_ny, mn_nz, mn_npex, mn_npey, mn_npxnpy, mn_np, mn_ngpts, mn_nxpex, mn_nypey))
-
-            c.execute(
-                """INSERT OR REPLACE INTO grid_limits(nx, ny, nz, npex, npey, npxnpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
-                (mx_nx, mx_ny, mx_nz, mx_npex, mx_npey, mx_npxnpy, mx_np, mx_ngpts, mx_nxpex, mx_nypey))
-            conn.commit()
-
-            c.close()
-            conn.close()
-        except TypeError:
-
-            checkfile = open(".palm_gf_tmp", "w")
-            if counter != 0:
-                checkfile.write("Gridfinder found " + str(counter) + " results.\n1")
-            else:
-                checkfile.write("Check input, no Results found.\n0")
-            checkfile.close()
-
-        checkfile = open(".palm_gf_tmp", "w")
-        if counter != 0:
-            checkfile.write("Gridfinder found " + str(counter) + " results.\n1")
-        else:
-            checkfile.write("Check input, no Results found.\n0")
-        checkfile.close()
-        self.emit(QtCore.SIGNAL('finish'), 1)
-        #print("finished with main execute")
-
-
-
-
-
-qtpopupFile = palm_bin + '/palm_gf_files/palm_gf_settings.ui'
-Ui_Pop, QtBaseClass = uic.loadUiType(qtpopupFile)
-
-
-class MyPopup(QtGui.QWidget, Ui_Pop):
-
-    def __init__(self):
-        Qt.QWidget.__init__(self)
-        Ui_Pop.__init__(self)
-
-        self.setupUi(self)
-        self.show
-        self.savepath.clicked.connect(self.path_to_save)
-        self.begin_check()
-        self.buttonBox.accepted.connect(self.end_check)
-        self.buttonBox.rejected.connect(self.close)
-
-
-    def begin_check(self):
-        file_check = palm_dir + '/trunk/SCRIPTS/.palm_gf_config'
-        if os.path.isfile(file_check) is True:
-            parameters = config_wr.read_config_settings()
-            self.linepath.setText(parameters[0])
-            self.result_thres.setValue(int(parameters[1]))
-            self.load_thres.setValue(int(parameters[2]))
-
-    def end_check(self):
-        config_wr.write_config_settings(self.linepath.text(), self.result_thres.value(), self.load_thres.value())
-
-        self.close()
-
-
-
-
-
-    def path_to_save(self, wildcard= None):
-        import wx
-        app = wx.App(None)
-        style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
-        dialog = wx.DirDialog(None, 'Open')
-        if dialog.ShowModal() == wx.ID_OK:
-            path = str(dialog.GetPath())
-
-            print(path)
-            self.linepath.setText(path)
-
-
-
-        else:
-            path = None
-        dialog.Destroy()
-        return
-
-
-
-
-
-
+                switch = False
+
+            if self.psolver_combo_box.currentIndex() == 2:
+                multigrid = True
+            else:
+                multigrid = False
+
+            if self.spectra_box.checkState() == 2:
+                spectra = True
+                poisfft = True
+            else:
+                spectra = False
+
+            if self.nx_ny_ratio_check.checkState() == 2:
+                dnxny = self.nx_ny_ratio_box.value()
+            else:
+                dnxny = 0
+
+            if self.npex_npey_ratio_check.checkState() == 2:
+                dpxpy = self.npex_npey_ratio_box.value()
+                dpxpy_dev = self.npex_npey_deviation_box.value()
+            else:
+                dpxpy = 0
+                dpxpy_dev = 0
+
+            if self.strict_matching_check.checkState() == 2:
+                tpn = self.strict_matching_box.value()
+            else:
+                tpn = 0
+
+            # writing the config
+            cfg_write(self.nx_min_box.value(), self.nx_max_box.value(), self.ny_min_box.value(),
+                      self.ny_max_box.value(), self.nz_min_box.value(), self.nz_max_box.value(),
+                      self.proc_min_box.value(), self.proc_max_box.value(), tpn,
+                      poisfft, switch, temperton, multigrid, spectra, dnxny, dpxpy, dpxpy_dev)
+
+            self.progressbar.setVisible(True)
+            self.progressbar.setValue(0)
+            # connects PyQtsignals to subroutines
+            self.thread = MyThread()
+            self.thread.change_value.connect(self.setprogressval)
+            self.thread.completed.connect(self.result_label_update)
+            self.thread.busy.connect(self.info_label_update)
+            # starts thread to calculate
+            self.thread.start()
+
+    def info_label_update(self):
+        # standby information during search of the limits of all results
+        self.results_information_label.setText('Standby please.')
+        self.results_information_label.setVisible(True)
+
+    def result_label_update(self, counter, timer):
+        self.result_visibility(True)
+        self.progressbar.setVisible(False)
+        if int(timer) == 0:
+            self.results_information_label.setText('Success! Gridfinder found ' + str(counter) +
+                                                   ' results in less than 1 second.')
+        else:
+            self.results_information_label.setText('Success! Gridfinder found ' + str(counter) +
+                                                   ' results in ' + str(timer) + ' seconds.')
+
+    def setprogressval(self, val):
+        # updates the value of the progressbar, data received from PyQtsignal
+        self.progressbar.setValue(val)
+
+    def startup_values(self):
+        # reads the .ini and updates default values to last used values
+        if os.path.exists('./palm_gf_config.ini') is False:
+            pass
+        else:
+            value_list = cfg_read()
+            self.nx_min_box.setValue(int(value_list[0]))
+            self.nx_max_box.setValue(int(value_list[1]))
+            self.ny_min_box.setValue(int(value_list[2]))
+            self.ny_max_box.setValue(int(value_list[3]))
+            self.nz_min_box.setValue(int(value_list[4]))
+            self.nz_max_box.setValue(int(value_list[5]))
+            self.proc_min_box.setValue(int(value_list[6]))
+            self.proc_max_box.setValue(int(value_list[7]))
+            if int(value_list[8]) != 0:
+                self.strict_matching_check.setCheckState(2)
+                self.strict_matching_box.setValue(int(value_list[8]))
+            if float(value_list[9]) != 0:
+                self.nx_ny_ratio_check.setCheckState(2)
+                self.nx_ny_ratio_box.setValue(float(value_list[9]))
+            if float(value_list[10]) != 0:
+                self.npex_npey_ratio_check.setCheckState(2)
+                self.npex_npey_ratio_box.setValue(float(value_list[10]))
+                self.npex_npey_deviation_box.setValue(float(value_list[11]))
+
+    def reset_values(self):
+        # resets values to default, does not update .ini
+        self.nx_min_box.setValue(0)
+        self.nx_max_box.setValue(1)
+        self.ny_min_box.setValue(0)
+        self.ny_max_box.setValue(1)
+        self.nz_min_box.setValue(0)
+        self.nz_max_box.setValue(1)
+        self.proc_min_box.setValue(0)
+        self.proc_max_box.setValue(1)
+        self.strict_matching_check.setCheckState(0)
+        self.nx_ny_ratio_check.setCheckState(0)
+        self.nx_ny_ratio_box.setValue(1.00)
+        self.npex_npey_ratio_check.setCheckState(0)
+        self.npex_npey_ratio_box.setValue(1.00)
+        self.npex_npey_deviation_box.setValue(1)
+
+    def input_min_max_check(self):
+        # setting chosen min values as minimum of maxima
+        self.nx_max_box.setMinimum(self.nx_min_box.value())
+        self.ny_max_box.setMinimum(self.ny_min_box.value())
+        self.nz_max_box.setMinimum(self.nz_min_box.value())
+        self.proc_max_box.setMinimum(self.proc_min_box.value())
+
+    def center_window(self):
+        # moving window to middle of the screen
+        frame = self.frameGeometry()
+        center = QDesktopWidget().availableGeometry().center()
+        frame.moveCenter(center)
+        self.move(frame.topLeft())
+
+    def fft_method_able(self):
+        # enable/disable QComboBox of fft method
+        if self.psolver_combo_box.currentIndex() == 1:
+            self.fft_combo_box.setEnabled(True)
+        else:
+            self.fft_combo_box.setEnabled(False)
+            self.fft_combo_box.setCurrentIndex(0)
+
+    def nx_ny_ratio_able(self):
+        # enable/disable QSpinBox of nx/ny-ratio
+        if int(self.nx_ny_ratio_check.checkState()) == 0:
+            self.nx_ny_ratio_box.setEnabled(False)
+        else:
+            self.nx_ny_ratio_box.setEnabled(True)
+
+    def strict_matching_able(self):
+        # enable/disable QSpinBox of strict matching
+        if int(self.strict_matching_check.checkState()) == 0:
+            self.strict_matching_box.setEnabled(False)
+        else:
+            self.strict_matching_box.setEnabled(True)
+
+    def npex_npey_ratio_able(self):
+        # enable/disable UI elements of npex/npey-ratio
+        if int(self.npex_npey_ratio_check.checkState()) == 0:
+            self.npex_npey_ratio_box.setEnabled(False)
+            self.npex_npey_deviation_slider.setEnabled(False)
+            self.npex_npey_deviation_box.setEnabled(False)
+        else:
+            self.npex_npey_ratio_box.setEnabled(True)
+            self.npex_npey_deviation_slider.setEnabled(True)
+            self.npex_npey_deviation_box.setEnabled(True)
+
+    def result_visibility(self, boolean):
+        # making certain ui elements in/visible
+        self.progressbar.setVisible(boolean)
+        self.results_information_label.setVisible(boolean)
+        self.view_button.setVisible(boolean)
 
 
 if __name__ == "__main__":
-    import time
-    app = QtGui.QApplication(sys.argv)
-    window = MyApp1()
-    window.setWindowTitle('Gridfinder')
+    app = QtWidgets.QApplication(sys.argv)
+    window = AppMain()
+    window.setWindowTitle('palm_gf')
     window.show()
     sys.exit(app.exec_())
