Ignore:
Timestamp:
Feb 8, 2021 4:14:27 PM (3 years ago)
Author:
schwenkel
Message:

update palm_gf to python3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SCRIPTS/palm_gf

    r4843 r4869  
    1 #!/usr/bin/env python
     1#!/usr/bin/env python3
    22# -*- coding: utf-8 -*-
    33#--------------------------------------------------------------------------------#
     
    2020# Current revisions:
    2121# -----------------
    22 # 
    23 # 
     22#
     23#
    2424# Former revisions:
    2525# -----------------
    2626# $Id$
     27# Modified palm_gf using python3 (edited by JR and RM)
     28#
     29# 4843 2021-01-15 15:22:11Z schwenkel
    2730# Removed PALM_BIN dependency
    28 # 
     31#
    2932# 2825 2018-02-20 21:48:27Z maronga
    3033# Modified header
    31 # 
     34#
    3235# 2718 2018-01-02 08:49:38Z maronga
    3336# Corrected "Former revisions" section
    34 # 
     37#
    3538# 2696 2017-12-14 17:12:51Z kanani
    3639# Change in file header (GPL part)
     
    4447# 2116 2017-01-16 16:15:24Z maronga
    4548# Initial revision
    46 # 
    47 # 
     49#
     50#
    4851#
    4952# Description:
    5053# ------------
    51 # 
     54#
    5255#
    5356# Instructions:
     
    5659#------------------------------------------------------------------------------!
    5760
     61from PyQt5 import QtWidgets, uic
     62from PyQt5.QtWidgets import QDesktopWidget
     63from palm_gf_files.palm_gf_conf import cfg_write, cfg_read
    5864import sys
    5965import os
    60 import time
    61 import palm_gf_files.palm_gf_exec as execute_script
    62 import palm_gf_files.palm_gf_conf as config_wr
    63 import sqlite3
    64 import subprocess as sub
    65 
    66 
    67 from PyQt4 import QtCore, QtGui, uic, Qt
    68 from PyQt4.QtCore import QCoreApplication
    69 from palm_gf_files.palm_gf_tools import MyApp3
    70 
    71 # Determine PALM directories
    72 # Determine PALM directories
    73 try:
    74    devnull = open(os.devnull, 'w')     
     66from palm_gf_files.palm_gf_exec import MyThread
     67from palm_gf_files.palm_gf_tools import MyTable
     68
     69try:
     70   devnull = open(os.devnull, 'w')
    7571   palm_dir = os.getcwd()
    7672   palm_bin = palm_dir + '/trunk/SCRIPTS'
     
    8076      # file found
    8177      out = None
    82 except:   
     78except:
    8379   print ('Error. palm_gf probably called in wrong directory.')
    8480   raise SystemExit
    8581
    86 qtCreatorFile = palm_bin + '/palm_gf_files/palm_gf.ui'
    87 
    88 Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
    89 
    90 
    91 class MyApp1(QtGui.QMainWindow, Ui_MainWindow):
     82class AppMain(QtWidgets.QMainWindow):
    9283    def __init__(self):
    93 
    94 
    95 
    96         QtGui.QMainWindow.__init__(self)
    97         Ui_MainWindow.__init__(self)
    98         #self.setWindowTitle('Gridfinder')
    99 
    100         frameGm = self.frameGeometry()
    101         screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
    102         centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
    103         frameGm.moveCenter(centerPoint)
    104         self.move(frameGm.topLeft())
    105 
    106 
    107         #centerPoint = str(centerPoint)
    108         #xcenter = centerPoint.split('(')[1].split(',')[0]
    109         #ycenter = centerPoint.split('(')[1].split(',')[1].split(')')[0]
    110         #print xcenter, ycenter
    111         #centerPoint = QtCore.QPoint(int(xcenter) - 418, int(ycenter))
    112         #frameGm.moveCenter(centerPoint)
    113         #self.move(frameGm.topLeft())
    114 
    115         self.setupUi(self)
    116         self.startbutton.clicked.connect(self.input_check)  # starts grid_calculation
    117         self.psolver_box.currentIndexChanged.connect(self.vis)  # triggers visibility of fft_method option
    118         self.save_button.clicked.connect(self.save_results)  # saves .db file under given name
    119         self.fft_method_box.setVisible(False)
    120         self.fft_method_label.setVisible(False)
    121         self.result_headline.setVisible(False)
    122         self.result_label.setVisible(False)
    123         #self.line_res_up.setVisible(False)
    124         self.line_res_down.setVisible(False)
    125         self.view_result_button.setVisible(False)
    126         #self.tableWidget.setVisible(False)
    127         self.load_text_label.setVisible(False)
    128         self.nor_spinbox.setVisible(False)
    129         self.filename_line.setVisible(False)
    130         self.save_button.setVisible(False)
    131         self.testbar.setVisible(False)
    132         self.d_box.setVisible(False)
    133         self.tpn_box.setVisible(False)
    134         self.tolerance_bar.setVisible(False)
    135         self.tolerance_value.setVisible(False)
    136         self.view_result_button.clicked.connect(self.load_gui)
    137         self.threadclass = Threadclass()
    138         self.actionSetting.triggered.connect(self.settings)
    139         self.question_box.clicked.connect(self.settings)
    140         self.warning_label.setVisible(False)
    141 
    142 
    143 
    144 
    145     def closeEvent(self, QCloseEvent):
    146 
    147         config_wr.closing_cleanup()
    148         QCloseEvent.accept()
    149 
    150 
    151     def input_check(self):
    152 
    153         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()):
    154             self.warning_label.setVisible(False)
    155             self.run_program()
    156 
    157         else:
    158 
    159             self.warning_label.setStyleSheet('color: red')
    160             self.warning_label.setVisible(True)
    161 
    162 
    163 
    164 
    165 
    166 
    167 
    168     def settings(self):
    169 
    170         self.w = MyPopup()
    171         #self.w.setGeometry(Qt.QRect(100, 100, 400, 200))
    172         frameGm = self.frameGeometry()
    173         screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
    174         centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
    175         frameGm.moveCenter(centerPoint)
    176         self.w.move(frameGm.topLeft())
    177         self.w.show()
    178 
    179 
    180 
    181     def vis(self):
    182 
    183         if str(self.psolver_box.currentIndex()) == str(1):
    184             self.fft_method_box.setVisible(True)
    185             self.fft_method_label.setVisible(True)
    186 
    187         if str(self.psolver_box.currentIndex()) != str(1):
    188             self.fft_method_box.setVisible(False)
    189             self.fft_method_label.setVisible(False)
    190 
    191     def load_gui(self):
    192         self.child_win = MyApp3()
    193         self.child_win.show()
    194 
    195     def run_transfer(self):
    196         self.threadclass = Threadclass()
    197         self.connect(self.threadclass, QtCore.SIGNAL('finish'), self.behind_run)
    198         #self.connect(self.threadclass, QtCore.SIGNAL('progress'), self.up2date)
    199         self.connect(self.threadclass, QtCore.SIGNAL('startqmsg'), self.takeoff)
    200         self.connect(self.threadclass, QtCore.SIGNAL('check'), self.checkme)
    201         self.threadclass.runx()
    202 
    203     def run_program(self):
    204 
    205 
    206         self.result_label.setText('Starting calculation...')
    207         #self.QtCore.QCoreApplication.processEvents()
    208         QtGui.QApplication.processEvents()
    209         #self.setEnabled(False)
    210         # self.Ui_MainWindow.setDisabled(True)
    211         #self.qmsg_wait(0)
    212         #print("bool state ", self.npex_npey_box.checkState())                                 # XXX
    213         np_min = str(self.np_min_box.value())
    214         np_max = str(self.np_max_box.value())
    215         nx_min = str(self.nx_min_box.value())
    216         nx_max = str(self.nx_max_box.value())
    217         ny_min = str(self.ny_min_box.value())
    218         ny_max = str(self.ny_max_box.value())
    219         nz_min = str(self.nz_min_box.value())
    220         nz_max = str(self.nz_max_box.value())
    221         tpn = str(self.tpn_box.value())
    222         dnpexnpey = str(self.d_box.value())
    223         dnpexnpey_tolerance = str(self.tolerance_value.value())
    224         dnxny = str(self.dnxny_box.value())
    225         myobject = MyPopup()
    226         ld_thrs = myobject.load_thres.value()
    227         rslt_thrs = myobject.result_thres.value()
    228 
    229         if str(self.psolver_box.currentIndex()) == str(1):
    230             poisfft = True
    231             switch = True
    232             if str(self.fft_method_box.currentIndex()) == str(2):
    233                 temperton = True
    234             else:
     84        super(AppMain, self).__init__()
     85        uic.loadUi(palm_bin + '/palm_gf_files/palm_gf.ui', self)
     86        self.center_window()
     87       
     88       
     89        # initial hiding of results ui elements
     90        self.result_visibility(False)
     91        # dis/enable ui elements when un/checked
     92        self.strict_matching_check.stateChanged.connect(self.strict_matching_able)
     93        self.npex_npey_ratio_check.stateChanged.connect(self.npex_npey_ratio_able)
     94        self.nx_ny_ratio_check.stateChanged.connect(self.nx_ny_ratio_able)
     95        self.psolver_combo_box.currentIndexChanged.connect(self.fft_method_able)
     96        # loading last used values into ui
     97        self.startup_values()
     98        # making sure max is not less than min
     99        self.nx_min_box.valueChanged.connect(self.input_min_max_check)
     100        self.ny_min_box.valueChanged.connect(self.input_min_max_check)
     101        self.nz_min_box.valueChanged.connect(self.input_min_max_check)
     102        self.proc_min_box.valueChanged.connect(self.input_min_max_check)
     103        # connects main buttons to subroutines
     104        self.start_button.clicked.connect(self.initialize)
     105        self.view_button.clicked.connect(self.load_table)
     106        self.reset_button.clicked.connect(self.reset_values)
     107
     108    def load_table(self):
     109        # opens table Ui
     110        self.table = MyTable()
     111        self.table.show()
     112
     113    def initialize(self):
     114        # translating Ui input into checks used during calculation
     115        if self.psolver_combo_box.currentIndex() != 0:
     116            if self.psolver_combo_box.currentIndex() == 1:
     117                poisfft = True
     118                switch = True
     119                if self.fft_combo_box.currentIndex() == 2:
     120                    temperton = True
     121                else:
     122                    temperton = False
     123            else:
     124                poisfft = False
    235125                temperton = False
    236         else:
    237             poisfft = False
    238             temperton = False
    239             switch = False
    240 
    241         if str(self.psolver_box.currentIndex()) == str(2):
    242             mlt_grid = True
    243         else:
    244             mlt_grid = False
    245 
    246         if str(self.Oos_checkbox.checkState()) == str(2):
    247             spctre = True
    248             poisfft = True
    249         else:
    250             spctre = False
    251 
    252         if int(self.strict_box.checkState()) != 2:
    253             tpn = 0
    254 
    255         if int(self.npex_npey_box.checkState()) != 2:
    256             dnpexnpey = 0
    257             dnpexnpey_tolerance = 0
    258 
    259         #print(poisfft, switch, temperton, mlt_grid, spctre)
    260         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,
    261                                str(poisfft), str(switch), str(temperton), str(mlt_grid), str(spctre), rslt_thrs, ld_thrs)
    262         #time.sleep(1)
    263         # execute_script.grid_executer() temp deactive
    264         self.testbar.setVisible(True)
    265         QtCore.QCoreApplication.processEvents()
    266         self.run_transfer()
    267 
    268 
    269     def behind_run(self):
    270         trigger_bool = False
    271         #print("behind_run executed")
    272         checkfile = open(".palm_gf_tmp", "r")
    273         #self.result_label.setText(str(checkfile.readline()))
    274         res_text = str(checkfile.readline())          # XXX
    275         self.result_label.setText(res_text)
    276         result_nr = res_text.split(' ')[2]
    277         if int(checkfile.readline()) == 1:
    278             self.view_result_button.setVisible(True)
    279             trigger_bool = True
    280         self.result_label.setVisible(True)
    281         self.result_headline.setVisible(True)
    282         self.line_res_down.setVisible(True)
    283         #self.line_res_up.setVisible(True)
    284         self.load_text_label.setVisible(False)
    285         self.nor_spinbox.setVisible(False)
    286         checkfile.close()
    287         #self.setEnabled(True)
    288         self.filename_line.setVisible(True)
    289         self.save_button.setVisible(True)
    290         parameters = config_wr.read_config()
    291 
    292 
    293         if trigger_bool is True and int(result_nr) < int(parameters[18]):
    294             self.result_label.setText(res_text + 'Loading Ui...')
    295             self.load_gui()                                              # XXXX
    296             self.result_label.setText(res_text)
    297             #self.close()
    298             #frameGm = self.frameGeometry()
    299             #screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
    300             #centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
    301             #frameGm = self.frameGeometry()
    302             #screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
    303             #centerPoint = str(centerPoint)
    304             #xcenter = centerPoint.split('(')[1].split(',')[0]
    305             #ycenter = centerPoint.split('(')[1].split(',')[1].split(')')[0]
    306             ##print xcenter, ycenter
    307             #centerPoint = QtCore.QPoint(int(xcenter) - 292, int(ycenter))
    308             #frameGm.moveCenter(centerPoint)
    309             #self.move(frameGm.topLeft())
    310 
    311 
    312 
    313 
    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 
    325             print(path, file)
    326         else:
    327             path = None
    328         dialog.Destroy()
    329         return
    330 
    331 
    332 
    333     def save_results(self):
    334 
    335         #self.get_path()
    336 
    337 
    338 
    339         import os
    340         import shutil
    341         prvs = '.palm_gf_data.db'
    342         new = str(self.filename_line.text())
    343         print(new)
    344         shutil.copy(prvs, new)
    345         print(prvs, new)
    346 
    347     def qmsg(self):
    348         msgbox = QtGui.QMessageBox()
    349         msgbox.setWindowTitle("Information")
    350         # msgbox.setVisible(False)
    351         msgbox.Information
    352         msgbox.setText("Calculating, please be patient.")
    353         # msgbox.
    354         msgbox.setModal(True)
    355         msgbox.exec_()
    356 
    357     def tester(self):
    358         #print("tester was executed from run method")
    359         pass
    360 
    361     def qmsg_wait(self, progress):
    362         global msgbox
    363         msgbox = QtGui.QMessageBox()
    364         layout = msgbox.layout()
    365         layout.itemAtPosition(layout.rowCount() - 1, 0).widget().hide()
    366         global progressx
    367         progressx = QtGui.QProgressBar()
    368         layout.addWidget(progressx, layout.rowCount(), 0, 1, layout.columnCount())
    369 
    370         msgbox.setWindowTitle("Progress")
    371         msgbox.Information
    372         msgbox.setText("Calculating, please be patient.")
    373 
    374         progressx.setValue(int(progress))
    375         #msgbox.setModal(False)
    376         msgbox.exec_()
    377 
    378     def up2date(self, progress):
    379 
    380         progressx.setValue(int(progress))
    381         if progress == 100:
    382             msgbox.done(1)
    383 
    384     def takeoff(self):
    385         #self.qmsg_wait(0)
    386         pass
    387 
    388     def checkme(self, check):
    389         #print(check)
    390         self.testbar.setValue(int(check))
    391 
    392         if check == 100:
    393             self.testbar.setVisible(False)
    394         QtGui.QApplication.processEvents()
    395 
    396 
    397 
    398 
    399 
    400 class Threadclass(QtCore.QThread):
    401     def __init__(self, parent = None):
    402         super(Threadclass, self).__init__(parent)
    403 
    404     def runx(self):
    405         #print("runx exec.")
    406         self.execute()
    407 
    408 
    409 
    410     def execute(self):
    411         self.emit(QtCore.SIGNAL('startqmsg'), 0)
    412 
    413         parameters = config_wr.read_config()
    414         min_procs = int(parameters[0])
    415         max_procs = int(parameters[1])
    416         tpn = int(parameters[2])
    417         dnpexnpey = float(parameters[3])
    418         dnpexnpey_tol = int(parameters[4])
    419         dnxny = float(parameters[5])
    420         nx_min = int(parameters[6])
    421         nx_max = int(parameters[7])
    422         ny_min = int(parameters[8])
    423         ny_max = int(parameters[9])
    424         nz_min = int(parameters[10])
    425         nz_max = int(parameters[11])
    426         poisfft = parameters[12]
    427         switch = parameters[13]
    428         tempterton = parameters[14]
    429         mlt_grid = parameters[15]
    430         spectr = parameters[16]
    431         result_thrs = parameters[17]
    432 
    433 
    434         path = "/localdata/.palm_gf_data.db"
    435         pathx = parameters[19] + '/.palm_gf_data.db'
    436 
    437 
    438         conn = sqlite3.connect(pathx)
    439         #conn = sqlite3.connect(".palm_gf_data.db")
    440         c = conn.cursor()
    441         c.execute("DROP TABLE IF EXISTS grid_current")
    442         c.execute("DROP TABLE IF EXISTS grid_limits")
    443         c.execute(
    444             "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)")
    445         c.execute(
    446             "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)")
    447         conn.commit()
    448         main_bool = True
    449 
    450 
    451 
    452 
    453         if poisfft == str(True):
    454             poisfft = True
    455         else:
    456             poisfft = False
    457 
    458         if switch == str(True):
    459             switch = True
    460         else:
    461             switch = False
    462 
    463         if tempterton == str(True):
    464             tempterton = True
    465         else:
    466             tempterton = False
    467 
    468         if mlt_grid == str(True):
    469             mlt_grid = True
    470         else:
    471             mlt_grid = False
    472 
    473         if spectr == str(True):
    474             spectr = True
    475         else:
    476             spectr = False
    477 
    478         #print(spectr, type(spectr))
    479         #print(poisfft, switch, tempterton, mlt_grid, spectr)
    480 
    481         np_used = min_procs
    482         counter = 0
    483 
    484         nx = nx_min
    485         ny = ny_min
    486         nz = nz_min
    487 
    488         from math import floor
    489 
    490         def factors(n):
    491             result = []
    492             for i in range(2, n + 1):  # test all integers between 2 and n
    493                 s = 0
    494                 while n / i == floor(n / float(i)):  # is n/i an integer?
    495                     n = n / float(i)
    496                     s += 1
    497                 if s > 0:
    498                     for k in range(s):
    499                         result.append(i)  # i is a pf s times
    500                         if n == 1:
    501                             return result
    502 
    503         while np_used <= max_procs:
    504             a = 1
    505 
    506             while a <= np_used:
    507                 prcs_var = np_used % a
    508                 if prcs_var != 0:
    509                     a += 1
    510                 elif prcs_var == 0:
    511                     npex = a
    512                     npey = int(np_used / npex)
    513 
    514                     if tpn != 0:                                   # XXX
    515 
    516                         if np_used % tpn != 0:
    517                             a += 1
    518                             continue
    519 
    520                     if dnpexnpey != 0 and npex / npey != dnpexnpey:
    521                         a += 1
    522                         continue
    523 
    524                     if dnpexnpey != 0:
    525 
    526 
    527                         if float(npex) / float(npey) < (dnpexnpey - dnpexnpey*dnpexnpey_tol/100):
    528                             a += 1
    529                             continue
    530 
    531                         if float(npex) / float(npey) > (dnpexnpey + dnpexnpey*dnpexnpey_tol/100):
    532                             a += 1
    533                             continue
    534 
    535                     while nx <= nx_max:
    536                         if (nx + 1) % npex != 0:
    537                             nx += 1
    538                             continue
    539 
    540                         if mlt_grid is True and (nx + 1) % 2 != 0:
    541                             nx += 1
    542                             continue
    543 
    544                         if switch is True and (nx + 1) % npey != 0:
    545                             nx += 1
    546                             continue
    547                         if npex > nx:
    548                             nx += 1
    549                             continue
    550 
    551                         while ny <= ny_max:
    552 
    553                             if dnxny != 0 and float(nx) / float(ny) != float(dnxny):
    554                                 ny += 1
    555                                 continue
    556                             if (ny + 1) % npey != 0:
    557                                 ny += 1
    558                                 continue
    559 
    560                             #if mlt_grid is True and ny % 2 != 0:       mlt and mlt_noOpt have same cond.
    561                             #    ny += 1
    562                             #    continue
    563 
    564                             if (ny + 1) % npex != 0 and switch is True:
    565                                 ny += 1
    566                                 continue
    567                             if npey > ny:
    568                                 ny += 1
    569                                 continue
    570 
    571                             while nz <= nz_max:
    572 
    573                                 if mlt_grid is True and nz % 2 != 0:
    574                                     nz += 1
    575                                     continue
    576 
    577                                 if poisfft is True and nz % npex != 0:
    578                                     nz += 1
    579                                     continue
    580 
    581                                 if spectr is True and nz % npey != 0:
    582                                     nz += 1
    583                                     continue
    584 
    585                                 if tempterton is True and nx > 1 and ny > 1:  # and nz < 1:
    586 
    587                                     nx_list = factors(nx + 1)
    588 
    589                                     i = 0
    590                                     nx_var = nx_list[i]
    591 
    592 
    593                                     while i < len(nx_list):
    594                                         if nx_var != 2 or nx_var != 3 or nx_var != 5:
    595                                             i += 1
    596                                             continue
    597 
    598                                         i += 1
    599                                     ny_list = factors(ny + 1)
    600                                     i = 0
    601                                     ny_var = ny_list[i]
    602                                     while i < len(ny_list):
    603                                         if ny_var != 2 or ny_var != 3 or ny_var != 5:
    604                                             i += 1
    605                                             continue
    606                                         i += 1
    607 
    608                                 counter += 1
    609                                 if counter > int(result_thrs):
    610                                     break
    611 
    612                                 npxnpy = format(float(npex) / float(npey), '.2f')
    613                                 nxpex = float(nx+1) /float(npex)
    614                                 nypey = float(ny+1) /float(npey)
    615 
    616                                 c.execute(
    617                                     """INSERT OR REPLACE INTO grid_current(nx, ny, nz, npex, npey, npxnpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
    618                                     (nx, ny, nz, npex, npey, npxnpy, (npex * npey), (nx * ny * nz), nxpex, nypey))
    619 
    620                                 nz += 1
    621                             nz = nz_min
    622                             ny += 1
    623                         ny = ny_min
    624                         nx += 1
    625                     nx = nx_min
    626                     a += 1
    627                     #  a += 1
    628             np_used += 1
    629             progr_act = 100*(float(np_used-1)/float(max_procs))
    630             self.emit(QtCore.SIGNAL('check'), progr_act)
    631             #print(np_used, max_procs, progr_act)
    632             self.emit(QtCore.SIGNAL('progress'), progr_act)
    633 
    634             conn.commit()
    635 
    636         conn.commit()
    637         #c.close()
    638         #conn.close()
    639         #
    640         ## ********************************
    641         #
    642         #conn = sqlite3.connect(parameters[19] + '/.palm_gf_data.db')
    643         #print parameters[19] + '/.palm_gf_data.db'
    644         #c = conn.cursor()
    645         try:
    646             c.execute("SELECT nx FROM grid_current ORDER BY nx DESC LIMIT 1")
    647             mx_nx = c.fetchone()[0]
    648             # print(mx_nx)
    649             c.execute("SELECT nx FROM grid_current ORDER BY nx  LIMIT 1")
    650             mn_nx = c.fetchone()[0]
    651             # print(mn_nx)
    652             c.execute("SELECT ny FROM grid_current ORDER BY ny DESC LIMIT 1")
    653             mx_ny = c.fetchone()[0]
    654             # print(mx_ny)
    655             c.execute("SELECT ny FROM grid_current ORDER BY ny  LIMIT 1")
    656             mn_ny = c.fetchone()[0]
    657             # print(mn_ny)
    658             c.execute("SELECT nz FROM grid_current ORDER BY nz DESC LIMIT 1")
    659             mx_nz = c.fetchone()[0]
    660             # print(mx_nz)
    661             c.execute("SELECT nz FROM grid_current ORDER BY nz  LIMIT 1")
    662             mn_nz = c.fetchone()[0]
    663             # print(mn_nz)
    664             c.execute("SELECT npex FROM grid_current ORDER BY npex DESC LIMIT 1")
    665             mx_npex = c.fetchone()[0]
    666             # print(mx_npex)
    667             c.execute("SELECT npex FROM grid_current ORDER BY npex  LIMIT 1")
    668             mn_npex = c.fetchone()[0]
    669             # print(mn_npex)
    670             c.execute("SELECT npey FROM grid_current ORDER BY npey DESC LIMIT 1")
    671             mx_npey = c.fetchone()[0]
    672             # print(mx_npey)
    673             c.execute("SELECT npey FROM grid_current ORDER BY npey  LIMIT 1")
    674             mn_npey = c.fetchone()[0]
    675             # print(mn_npey)
    676             c.execute("SELECT npxnpy FROM grid_current ORDER BY npxnpy DESC LIMIT 1")
    677             mx_npxnpy = c.fetchone()[0]
    678             # print(mx_npxnpy)
    679             c.execute("SELECT npxnpy FROM grid_current ORDER BY npxnpy  LIMIT 1")
    680             mn_npxnpy = c.fetchone()[0]
    681             # print(mn_npxnpy)
    682             c.execute("SELECT np FROM grid_current ORDER BY np DESC LIMIT 1")
    683             mx_np = c.fetchone()[0]
    684             # print(mx_np)
    685             c.execute("SELECT np FROM grid_current ORDER BY np LIMIT 1")
    686             mn_np = c.fetchone()[0]
    687             # print(mn_np)
    688             c.execute("SELECT ngpts FROM grid_current ORDER BY ngpts DESC LIMIT 1")
    689             mx_ngpts = c.fetchone()[0]
    690             # print(mx_ngpts)
    691             c.execute("SELECT ngpts FROM grid_current ORDER BY ngpts LIMIT 1")
    692             mn_ngpts = c.fetchone()[0]
    693             # print(mn_ngpts)
    694             c.execute("SELECT nxnpex FROM grid_current ORDER BY nxnpex DESC LIMIT 1")
    695             mx_nxpex = c.fetchone()[0]
    696             c.execute("SELECT nxnpex FROM grid_current ORDER BY nxnpex LIMIT 1")
    697             mn_nxpex = c.fetchone()[0]
    698             c.execute("SELECT nynpey FROM grid_current ORDER BY nynpey DESC LIMIT 1")
    699             mx_nypey = c.fetchone()[0]
    700             c.execute("SELECT nynpey FROM grid_current ORDER BY nynpey LIMIT 1")
    701             mn_nypey = c.fetchone()[0]
    702 
    703 
    704 
    705             conn.commit()
    706             c.execute(
    707                 """INSERT OR REPLACE INTO grid_limits(nx, ny, nz, npex, npey, npxnpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
    708                 (mn_nx, mn_ny, mn_nz, mn_npex, mn_npey, mn_npxnpy, mn_np, mn_ngpts, mn_nxpex, mn_nypey))
    709 
    710             c.execute(
    711                 """INSERT OR REPLACE INTO grid_limits(nx, ny, nz, npex, npey, npxnpy, np, ngpts, nxnpex, nynpey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
    712                 (mx_nx, mx_ny, mx_nz, mx_npex, mx_npey, mx_npxnpy, mx_np, mx_ngpts, mx_nxpex, mx_nypey))
    713             conn.commit()
    714 
    715             c.close()
    716             conn.close()
    717         except TypeError:
    718 
    719             checkfile = open(".palm_gf_tmp", "w")
    720             if counter != 0:
    721                 checkfile.write("Gridfinder found " + str(counter) + " results.\n1")
    722             else:
    723                 checkfile.write("Check input, no Results found.\n0")
    724             checkfile.close()
    725 
    726         checkfile = open(".palm_gf_tmp", "w")
    727         if counter != 0:
    728             checkfile.write("Gridfinder found " + str(counter) + " results.\n1")
    729         else:
    730             checkfile.write("Check input, no Results found.\n0")
    731         checkfile.close()
    732         self.emit(QtCore.SIGNAL('finish'), 1)
    733         #print("finished with main execute")
    734 
    735 
    736 
    737 
    738 
    739 qtpopupFile = palm_bin + '/palm_gf_files/palm_gf_settings.ui'
    740 Ui_Pop, QtBaseClass = uic.loadUiType(qtpopupFile)
    741 
    742 
    743 class MyPopup(QtGui.QWidget, Ui_Pop):
    744 
    745     def __init__(self):
    746         Qt.QWidget.__init__(self)
    747         Ui_Pop.__init__(self)
    748 
    749         self.setupUi(self)
    750         self.show
    751         self.savepath.clicked.connect(self.path_to_save)
    752         self.begin_check()
    753         self.buttonBox.accepted.connect(self.end_check)
    754         self.buttonBox.rejected.connect(self.close)
    755 
    756 
    757     def begin_check(self):
    758         file_check = palm_dir + '/trunk/SCRIPTS/.palm_gf_config'
    759         if os.path.isfile(file_check) is True:
    760             parameters = config_wr.read_config_settings()
    761             self.linepath.setText(parameters[0])
    762             self.result_thres.setValue(int(parameters[1]))
    763             self.load_thres.setValue(int(parameters[2]))
    764 
    765     def end_check(self):
    766         config_wr.write_config_settings(self.linepath.text(), self.result_thres.value(), self.load_thres.value())
    767 
    768         self.close()
    769 
    770 
    771 
    772 
    773 
    774     def path_to_save(self, wildcard= None):
    775         import wx
    776         app = wx.App(None)
    777         style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
    778         dialog = wx.DirDialog(None, 'Open')
    779         if dialog.ShowModal() == wx.ID_OK:
    780             path = str(dialog.GetPath())
    781 
    782             print(path)
    783             self.linepath.setText(path)
    784 
    785 
    786 
    787         else:
    788             path = None
    789         dialog.Destroy()
    790         return
    791 
    792 
    793 
    794 
    795 
    796 
     126                switch = False
     127
     128            if self.psolver_combo_box.currentIndex() == 2:
     129                multigrid = True
     130            else:
     131                multigrid = False
     132
     133            if self.spectra_box.checkState() == 2:
     134                spectra = True
     135                poisfft = True
     136            else:
     137                spectra = False
     138
     139            if self.nx_ny_ratio_check.checkState() == 2:
     140                dnxny = self.nx_ny_ratio_box.value()
     141            else:
     142                dnxny = 0
     143
     144            if self.npex_npey_ratio_check.checkState() == 2:
     145                dpxpy = self.npex_npey_ratio_box.value()
     146                dpxpy_dev = self.npex_npey_deviation_box.value()
     147            else:
     148                dpxpy = 0
     149                dpxpy_dev = 0
     150
     151            if self.strict_matching_check.checkState() == 2:
     152                tpn = self.strict_matching_box.value()
     153            else:
     154                tpn = 0
     155
     156            # writing the config
     157            cfg_write(self.nx_min_box.value(), self.nx_max_box.value(), self.ny_min_box.value(),
     158                      self.ny_max_box.value(), self.nz_min_box.value(), self.nz_max_box.value(),
     159                      self.proc_min_box.value(), self.proc_max_box.value(), tpn,
     160                      poisfft, switch, temperton, multigrid, spectra, dnxny, dpxpy, dpxpy_dev)
     161
     162            self.progressbar.setVisible(True)
     163            self.progressbar.setValue(0)
     164            # connects PyQtsignals to subroutines
     165            self.thread = MyThread()
     166            self.thread.change_value.connect(self.setprogressval)
     167            self.thread.completed.connect(self.result_label_update)
     168            self.thread.busy.connect(self.info_label_update)
     169            # starts thread to calculate
     170            self.thread.start()
     171
     172    def info_label_update(self):
     173        # standby information during search of the limits of all results
     174        self.results_information_label.setText('Standby please.')
     175        self.results_information_label.setVisible(True)
     176
     177    def result_label_update(self, counter, timer):
     178        self.result_visibility(True)
     179        self.progressbar.setVisible(False)
     180        if int(timer) == 0:
     181            self.results_information_label.setText('Success! Gridfinder found ' + str(counter) +
     182                                                   ' results in less than 1 second.')
     183        else:
     184            self.results_information_label.setText('Success! Gridfinder found ' + str(counter) +
     185                                                   ' results in ' + str(timer) + ' seconds.')
     186
     187    def setprogressval(self, val):
     188        # updates the value of the progressbar, data received from PyQtsignal
     189        self.progressbar.setValue(val)
     190
     191    def startup_values(self):
     192        # reads the .ini and updates default values to last used values
     193        if os.path.exists('./palm_gf_config.ini') is False:
     194            pass
     195        else:
     196            value_list = cfg_read()
     197            self.nx_min_box.setValue(int(value_list[0]))
     198            self.nx_max_box.setValue(int(value_list[1]))
     199            self.ny_min_box.setValue(int(value_list[2]))
     200            self.ny_max_box.setValue(int(value_list[3]))
     201            self.nz_min_box.setValue(int(value_list[4]))
     202            self.nz_max_box.setValue(int(value_list[5]))
     203            self.proc_min_box.setValue(int(value_list[6]))
     204            self.proc_max_box.setValue(int(value_list[7]))
     205            if int(value_list[8]) != 0:
     206                self.strict_matching_check.setCheckState(2)
     207                self.strict_matching_box.setValue(int(value_list[8]))
     208            if float(value_list[9]) != 0:
     209                self.nx_ny_ratio_check.setCheckState(2)
     210                self.nx_ny_ratio_box.setValue(float(value_list[9]))
     211            if float(value_list[10]) != 0:
     212                self.npex_npey_ratio_check.setCheckState(2)
     213                self.npex_npey_ratio_box.setValue(float(value_list[10]))
     214                self.npex_npey_deviation_box.setValue(float(value_list[11]))
     215
     216    def reset_values(self):
     217        # resets values to default, does not update .ini
     218        self.nx_min_box.setValue(0)
     219        self.nx_max_box.setValue(1)
     220        self.ny_min_box.setValue(0)
     221        self.ny_max_box.setValue(1)
     222        self.nz_min_box.setValue(0)
     223        self.nz_max_box.setValue(1)
     224        self.proc_min_box.setValue(0)
     225        self.proc_max_box.setValue(1)
     226        self.strict_matching_check.setCheckState(0)
     227        self.nx_ny_ratio_check.setCheckState(0)
     228        self.nx_ny_ratio_box.setValue(1.00)
     229        self.npex_npey_ratio_check.setCheckState(0)
     230        self.npex_npey_ratio_box.setValue(1.00)
     231        self.npex_npey_deviation_box.setValue(1)
     232
     233    def input_min_max_check(self):
     234        # setting chosen min values as minimum of maxima
     235        self.nx_max_box.setMinimum(self.nx_min_box.value())
     236        self.ny_max_box.setMinimum(self.ny_min_box.value())
     237        self.nz_max_box.setMinimum(self.nz_min_box.value())
     238        self.proc_max_box.setMinimum(self.proc_min_box.value())
     239
     240    def center_window(self):
     241        # moving window to middle of the screen
     242        frame = self.frameGeometry()
     243        center = QDesktopWidget().availableGeometry().center()
     244        frame.moveCenter(center)
     245        self.move(frame.topLeft())
     246
     247    def fft_method_able(self):
     248        # enable/disable QComboBox of fft method
     249        if self.psolver_combo_box.currentIndex() == 1:
     250            self.fft_combo_box.setEnabled(True)
     251        else:
     252            self.fft_combo_box.setEnabled(False)
     253            self.fft_combo_box.setCurrentIndex(0)
     254
     255    def nx_ny_ratio_able(self):
     256        # enable/disable QSpinBox of nx/ny-ratio
     257        if int(self.nx_ny_ratio_check.checkState()) == 0:
     258            self.nx_ny_ratio_box.setEnabled(False)
     259        else:
     260            self.nx_ny_ratio_box.setEnabled(True)
     261
     262    def strict_matching_able(self):
     263        # enable/disable QSpinBox of strict matching
     264        if int(self.strict_matching_check.checkState()) == 0:
     265            self.strict_matching_box.setEnabled(False)
     266        else:
     267            self.strict_matching_box.setEnabled(True)
     268
     269    def npex_npey_ratio_able(self):
     270        # enable/disable UI elements of npex/npey-ratio
     271        if int(self.npex_npey_ratio_check.checkState()) == 0:
     272            self.npex_npey_ratio_box.setEnabled(False)
     273            self.npex_npey_deviation_slider.setEnabled(False)
     274            self.npex_npey_deviation_box.setEnabled(False)
     275        else:
     276            self.npex_npey_ratio_box.setEnabled(True)
     277            self.npex_npey_deviation_slider.setEnabled(True)
     278            self.npex_npey_deviation_box.setEnabled(True)
     279
     280    def result_visibility(self, boolean):
     281        # making certain ui elements in/visible
     282        self.progressbar.setVisible(boolean)
     283        self.results_information_label.setVisible(boolean)
     284        self.view_button.setVisible(boolean)
    797285
    798286
    799287if __name__ == "__main__":
    800     import time
    801     app = QtGui.QApplication(sys.argv)
    802     window = MyApp1()
    803     window.setWindowTitle('Gridfinder')
     288    app = QtWidgets.QApplication(sys.argv)
     289    window = AppMain()
     290    window.setWindowTitle('palm_gf')
    804291    window.show()
    805292    sys.exit(app.exec_())
Note: See TracChangeset for help on using the changeset viewer.