#!/usr/bin/env python # -*- coding: utf-8 -*- #--------------------------------------------------------------------------------# # This file is part of the PALM model system. # # 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-2018 Leibniz Universitaet Hannover #--------------------------------------------------------------------------------# # # Current revisions: # ----------------- # # # Former revisions: # ----------------- # $Id: palmrungui 4411 2020-02-18 14:28:02Z hellstea $ # Added new features: individual tag for submitted runs, automatic finding of # configuration, start of palmbuild from GUI # # 4405 2020-02-12 19:11:11Z maronga # Major revisions: New layout. Merged with palm job manager (palm_jm). # Minor revisions: Misc. bugs fixed. # # 4394 2020-02-04 21:40:38Z maronga # Bugfix: harmonized naming convention of configuration files # # 4393 2020-02-04 21:24:48Z maronga # Removed PALM_BIN dependency and os calls # # 3487 2018-11-05 07:18:02Z maronga # Renamed options -d and -h to -r and -c. # # 2825 2018-02-20 21:48:27Z maronga # Adjusted to work with newest version of palmrun # # 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) # # 2484 2017-09-20 14:22:42Z maronga # Added PALM logo # # 2480 2017-09-19 06:24:14Z maronga # option -A (project account number) added # # 2477 2017-09-18 08:42:29Z maronga # Renamed restart run appendix from "f" to "r". Bugfix for displaying restart runs.> # Revised list of recently submitted jobs # # 2413 2017-09-06 12:48:29Z maronga # Renamed to palmrungui and adapted for use with palmrun instead of mrun. # # 2316 2017-07-20 07:53:42Z maronga # Initial revision in python # # # # Description: # ------------ # Graphical user interface for the palmrun script. # @author Felix Gaschler # @author Björn Maronga (maronga@muk.uni-hannover.de) # # Instructions: # ------------- # #------------------------------------------------------------------------------! import sys import subprocess from PyQt4 import QtCore, QtGui, uic from PyQt4.QtCore import QProcess,pyqtSlot,SIGNAL,SLOT from time import strftime import os import shutil # Determine PALM directories try: devnull = open(os.devnull, 'w') palm_dir = os.getcwd() palm_bin = palm_dir + '/trunk/SCRIPTS' job_dir = palm_dir + '/JOBS' user_dir = palm_dir + '/USER_CODE' with open(palm_bin + '/palmrungui', 'r') as fh: # file found out = None except: print "Error. palmrungui probably called in wrong directory." raise SystemExit palmrunline = "" set_list = [] Ui_MainWindow = uic.loadUiType("%s/palmrungui_files/mainwindow.ui" % (palm_bin))[0] Ui_helpDialog = uic.loadUiType("%s/palmrungui_files/help.ui" % (palm_bin))[0] Ui_aboutDialog = uic.loadUiType("%s/palmrungui_files/about.ui" % (palm_bin))[0] class HelpDialog(QtGui.QDialog,Ui_helpDialog): def __init__(self, parent=None): super(HelpDialog,self).__init__() self.setupUi(self) class AboutDialog(QtGui.QDialog,Ui_aboutDialog): def __init__(self, parent=None): super(AboutDialog,self).__init__() self.setupUi(self) class Mainwindow(QtGui.QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super(Mainwindow, self).__init__() self.setupUi(self) self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png")) self.recent_jobs(50) self.load_jobs() # look up configuration files and add to combo box self.group_execution.findChild(QtGui.QComboBox,"combo_configuration").addItem("") for files in os.listdir(palm_dir): if files.startswith(".palm.config"): tmpstring = filter(None,files.split(".palm.config."))[0] self.group_execution.findChild(QtGui.QComboBox,"combo_configuration").addItem(tmpstring) commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline") commandline.setText("") self.tabWidget.setCurrentIndex(0) filename = "%s/.palmrungui.default" % (palm_dir) if os.path.exists(filename): pass else: return file = open(filename, "r") if ( file is not None ): # File opened successfully palmrunline = file.readline() #if neue zeile zeichen palmrunline = palmrunline[:len(palmrunline)-1] file.close() # In case a palmrunline was found, load it to mainwindow if ( palmrunline != ""): palmrunline = palmrunline[17:] commandline.setText(palmrunline) self.setup_gui(palmrunline) QtGui.QApplication.processEvents() # starts xterm with palmrun commandline ####################################### def startpalmrun(self): palmrunline = str(self.groupBox.findChild(QtGui.QLineEdit,"commandline").text()) userline = str(self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text()) # Check for empty line palmrunline_save = palmrunline if (userline != ""): palmrunline = "%s %s" % (palmrunline,userline) history_line = palmrunline # Disable the main window self.tabWidget.setEnabled(False) self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False) self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(False) self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("wait...") self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText("Executing palmrun in xterm...") # Wait until all commands have been executed (ugly) ? #for i in range(0,21): # qApp->processEvents() # Start xterm as QProcess palmrun = QProcess() palmrun.setProcessChannelMode(QProcess.MergedChannels) # mergedChannels palmrun.setWorkingDirectory(palm_dir) geomet = self.frameGeometry() posx = geomet.x()+geomet.width() posy = geomet.y() s = " -title \"Executing palmrun...\" -fa \"Monospace\" -fs 11 -geometry \"80x38+%d+%d\" -e \"" % (posx,posy) palmrunline = "%s%s;echo -n '--> Press enter to continue...';read yesno\"processEvents() # Start xterm as QProcess palmbuild = QProcess() palmbuild.setProcessChannelMode(QProcess.MergedChannels) # mergedChannels palmbuild.setWorkingDirectory(palm_dir) geomet = self.frameGeometry() posx = geomet.x()+geomet.width() posy = geomet.y() s = " -title \"Executing palmbuild...\" -fa \"Monospace\" -fs 11 -geometry \"80x38+%d+%d\" -e \"" % (posx,posy) palmbuildline = "%s%s;echo -n '--> Press enter to continue...';read yesno\"=0 and count=1: listitem = history[i-1][17:len(history[i-1])-1] listitem = filter(None,listitem.split(" -r"))[1] listitem = filter(None,listitem.split(" -"))[0] listitem = listitem.replace(" ","") # Select command line with correct timestamp and jobname if (history[i-1][:16] == timestamp and listitem == jobname): palmrunline = history[i-1] palmrunline = palmrunline[17:] palmrunline = palmrunline[:len(palmrunline)-1] palmrunline = filter(None,palmrunline.split("("))[0] self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) tag = history[i-1].split('\n')[0] tag = filter(None,tag.split("("))[1] tag = tag.replace(")","") self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setText(tag) self.setup_gui(palmrunline) self.list_jobname.item(itemint).setSelected(True) return i = i-1 # Change run identifer (initial, restart, coupled...) ###################################################### def change_rc_list(self): drop_job = self.group_execution.findChild(QtGui.QComboBox,"drop_job").currentText() self.change_commandline("a","") # Enable PE distribution for atmosphere/ocean if ( drop_job == "Restart run (coupled atmosphere ocean)" or drop_job == "Initial run (coupled atmosphere ocean)"): drop_atmos = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").text() drop_ocean = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").text() s = "%s %s" % (drop_atmos,drop_ocean) self.change_commandline("Y",s) if ( drop_job == "Restart run" or drop_job == "Restart run (coupled atmosphere ocean)"): self.change_commandline("r","") # Check of ocean runs else: self.delete_commandline("Y") if (drop_job == "Precursor run (ocean)"): self.activate_flag("y") else: self.deactivate_flag("y") # changes commandline depending on parameters ########################################################## def change_commandline(self, id_str, fwt_str): fwt_str = str(fwt_str) initialize = False palmrunline = str(self.groupBox.findChild(QtGui.QLineEdit,"commandline").text()) s = " -%s " % (id_str) splitline = filter(None,palmrunline.split(s)) if ( len(splitline) == 0 ): splitline.append("palmrun") splitline.append(" ") initialize = True elif ( len(splitline) == 1 ): splitline.append(" ") param = splitline[1].split("-") # Change in parameter "r" (jobname) if (id_str == "r"): filename = str(self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").text()) s = filename.split("JOBS/") param[0] = s[len(s)-1] if ( initialize == True ):#and self.group_runcontrol.isEnabled() == True ): self.group_execution.setEnabled(True) self.group_execution.findChild(QtGui.QComboBox,"drop_job").setEnabled(True) self.group_advanced.setEnabled(True) self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True) self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(True) self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True) elif ( param[0] == ""): self.group_execution.setEnabled(False) self.group_execution.findChild(QtGui.QComboBox,"drop_job").setEnabled(False) self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False) self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(False) self.group_advanced.setEnabled(False) self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True) self.delete_commandline("r") self.change_commandline("a","remove") return 1 else: # Check if _p3dr file is available, otherwise notice user drop_job = self.group_execution.findChild(QtGui.QComboBox,"drop_job").currentText() if ( self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").checkState() == 2 or drop_job == "Restart run" or drop_job == "Restart run (coupled atmosphere ocean)" ): jobname = self.group_execution.findChild(QtGui.QLineEdit, "line_jobname").text() restartfile = "%s/JOBS/%s/INPUT/%s_p3dr" % (palm_dir,jobname,jobname) if (os.path.exists(restartfile) == True): self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("") if ( drop_job == "Restart run (coupled atmosphere ocean)" ): restartfileo = "%s/JOBS/%s/INPUT/%s_p3dor" % (palm_dir,jobname,jobname) if (os.path.exists(restartfileo) == True): self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("hooo") else: self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("Warning: No p3dor file found!") else: self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("Warning: No p3dr file found!") self.group_execution.setEnabled(True) self.drop_job.setEnabled(True) self.group_advanced.setEnabled(True) # Change in parameter "a" (run control list) elif (id_str == "a"): drop_job = self.group_execution.findChild(QtGui.QComboBox,"drop_job").currentText() rc_flag = "#" if (drop_job == "Initial run"): rc_flag = "#" elif (drop_job == "Restart run"): rc_flag = "r" elif (drop_job == "Precursor run (atmosphere)"): rc_flag = "#" elif (drop_job == "Precursor run (ocean)"): rc_flag = "o#" elif (drop_job == "Initial run (coupled atmosphere ocean)"): rc_flag = "#" elif (drop_job == "Restart run (coupled atmosphere ocean)"): rc_flag = "r" param[0] = "\"d3%s" % (rc_flag) if (drop_job == "Restart run (coupled atmosphere ocean)" or drop_job == "Initial run (coupled atmosphere ocean)"): if (rc_flag == "#"): rc_flag = "o#" else: rc_flag = "or" param[0] = "%s d3%s" % (param[0],rc_flag) status_restarts = self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").checkState() if (status_restarts == 2): param[0]="%s restart" % (param[0]) # Check if _p3dr file is available, otherwise notice user if (status_restarts == 2): jobname = str(self.group_execution.findChild(QtGui.QLineEdit, "line_jobname").text()) restartfile = "%s/JOBS/%s/INPUT/%s_p3dr" % (palm_dir,jobname,jobname) if (os.path.exists(restartfile) == True): self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("") else: self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("Warning: No p3dr file found!") else: self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("") status_cycfill = self.group_execution.findChild(QtGui.QCheckBox,"check_cycfill").checkState() if (status_cycfill == 2): param[0]="%s fill" % (param[0]) status_svf = self.group_execution.findChild(QtGui.QCheckBox,"check_svf").checkState() if (status_svf == 2): param[0]="%s svf" % (param[0]) param[0]="%s\"" % (param[0]) if ( fwt_str == "remove"): self.delete_commandline(id_str) return 1 else: self.button_start.setEnabled(True) self.action_save.setEnabled(True) self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True) # Change in any other parameter else: if ( fwt_str != ""): param[0] = "\"%s\"" % (fwt_str) else: self.delete_commandline(id_str) return 1 # Join the new palmrunline splitline[1]= " -".join(param) s = " -%s " % (id_str) newpalmrunline = s.join(splitline) # Pr the new palmrunline to mainwindow newpalmrunline = newpalmrunline.replace(" "," ") self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(newpalmrunline) # change lineinput depending on sender ################################################################################### def change_lineinput(self): if ( self.sender() == self.group_execution.findChild(QtGui.QComboBox, "combo_configuration") ): tmptext = self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").currentText() if tmptext.isEmpty(): self.change_commandline("c"," ") self.group_execution.findChild(QtGui.QPushButton,'button_palmbuild').setEnabled(False) else: self.change_commandline("c",tmptext) self.group_execution.findChild(QtGui.QPushButton,'button_palmbuild').setEnabled(True) elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_q")): tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_q").text() self.change_commandline("q",tmptext) elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_account")): tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_account").text() self.change_commandline("A",tmptext) elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_pe")): tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_pe").text() self.change_commandline("X",tmptext) elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_tpn")): tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_tpn").text() self.change_commandline("T",tmptext) elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_time")): tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_time").text() self.change_commandline("t",tmptext) elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_M")): tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_M").text() self.change_commandline("M",tmptext) elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_m")): tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_m").text() self.change_commandline("m",tmptext) elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_D")): tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_D").text() self.change_commandline("D",tmptext) elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_c")): tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_c").text() if ( tmptext == ".palmrungui.config"): tmptext = "" self.change_commandline("c",tmptext) elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_s")): tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_s").text() self.change_commandline("s",tmptext) elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_w")): tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_w").text() self.change_commandline("w",tmptext) elif ( self.sender() == self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos") or self.sender() == self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean")): t1 = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").text() t2 = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").text() tmptext = "%s %s" % (t1,t2) self.change_commandline("Y",tmptext) # try catch sowas in der art pe1 = 0 pe2 = 0 try: pe1 = int(t1) except ValueError: pass try: pe2 = int(t2) except ValueError: pass PE_total = pe1+pe2 self.group_execution.findChild(QtGui.QLineEdit,"line_pe").setText(str(PE_total)) self.change_commandline("X",str(PE_total)) # deletes parameter from commandline ##################################################################################### def delete_commandline(self, id_str): # Read palmrunline commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline") palmrunline = str(commandline.text()) s = " -%s" % (id_str) splitline = filter(None,palmrunline.split(s)) if ( len(splitline) == 1): return 1 else: param = splitline[1].split("-") param[0] = "" splitline[1]= " -".join(param) newpalmrunline = "".join(splitline) newpalmrunline = newpalmrunline.replace(" "," ") # Print new palmrunline to screen commandline.setText(newpalmrunline) # controls flags ################################################################################### def check_flags(self): status = self.group_execution.findChild(QtGui.QCheckBox,"check_delete_tmp_files" ).checkState() if (status == 2): self.activate_flag("B") else: self.deactivate_flag("B") status = self.group_execution.findChild(QtGui.QCheckBox,"check_verbose" ).checkState() if (status == 2): self.activate_flag("v") else: self.deactivate_flag("v") status = self.group_advanced.findChild(QtGui.QCheckBox,"check_b" ).checkState() if (status == 2): self.activate_flag("b") else: self.deactivate_flag("b") status = self.group_advanced.findChild(QtGui.QCheckBox,"check_F" ).checkState() if (status == 2): self.activate_flag("F") else: self.deactivate_flag("F") status = self.group_advanced.findChild(QtGui.QCheckBox,"check_I" ).checkState() if (status == 2): self.activate_flag("I") else: self.deactivate_flag("I") status = self.group_advanced.findChild(QtGui.QCheckBox,"check_k" ).checkState() if (status == 2): self.activate_flag("k") else: self.deactivate_flag("k") status = self.group_advanced.findChild(QtGui.QCheckBox,"check_O" ).checkState() if (status == 2): self.activate_flag("O") else: self.deactivate_flag("O") status = self.group_advanced.findChild(QtGui.QCheckBox,"check_x" ).checkState() if (status == 2): self.activate_flag("x") else: self.deactivate_flag("x") status = self.group_advanced.findChild(QtGui.QCheckBox,"check_Z" ).checkState() if (status == 2): self.activate_flag("Z") else: self.deactivate_flag("Z") # changes flag to parameter ################################################################################## def activate_flag(self, id_str): commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline") palmrunline = str(commandline.text()) s = " -%s" % (id_str) splitline = filter(None,palmrunline.split(s)) if ( len(splitline) == 1): splitline.append("") s = " -%s" % (id_str) newpalmrunline = s.join(splitline) newpalmrunline = newpalmrunline.replace(" "," ") commandline.setText(newpalmrunline) # deletes flag in commandline #################################################################################### def deactivate_flag(self, id_str): commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline") palmrunline = str(commandline.text()) s = " -%s" % (id_str) splitline = filter(None,palmrunline.split(s)) newpalmrunline = "".join(splitline) newpalmrunline = newpalmrunline.replace(" "," ") commandline.setText(newpalmrunline) # Clears window ################################################################################# def reset_window(self): self.setupUi(self) self.tabWidget.setCurrentIndex(0) self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png")) self.recent_jobs(50) self.load_jobs() # Safes current commandline and user Parameters to .sav file ################################################################################# def save_to_file(self): user_string = self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text() cmd_string = self.groupBox.findChild(QtGui.QLineEdit,"commandline").text() string_to_file = cmd_string if (user_string != ""): string_to_file = "%s%s" % (string_to_file,user_string) #filename = QtGui.QInputDialog.getText(self, "Save File naming Dialog", "Insert filename", QtGui.QLineEdit.Normal) filename = str(QtGui.QFileDialog.getSaveFileName(self, "Save File","filename.sav")) extension = ".sav" filename = "%s%s" % (filename, "") tmstamp = strftime("%Y/%m/%d %H:%M") file = open(filename,"w") s = "%s %s" % (tmstamp, string_to_file) file.write(s) file.close() # Safes current commandline and user parameters to default file ################################################################################ def save_default(self): user_string = self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text() cmd_string = self.groupBox.findChild(QtGui.QLineEdit,"commandline").text() string_to_file = cmd_string if (user_string != ""): string_to_file = "%s%s" % (string_to_file,user_string) filename ="%s/.palmrungui.default" % (palm_dir) tmstamp = strftime("%Y/%m/%d %H:%M") file = open(filename,"w") s = "%s %s" % (tmstamp, string_to_file) file.write(s) file.close() # Executes command which starts watchdog (start palm_wd) ######################################################## def start_watchdog(self): subprocess.Popen(["nohup","palm_wd",">>","/dev/null", "2>&1","&"]) # Opens "help" dialog ################################# def help(self): dialog = HelpDialog() dialog.exec_() # Opens "about" dialog ################################## def about_gui(self): dialog = AboutDialog() dialog.exec_() # commandline to buttons etc ############################## def setup_gui(self, palmrun_str): #self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png")) # Some initial settings user = "" coupled_run = False ocean_run = False nojob = False #Split parameters in palmrunline splitline = palmrun_str.split(" -") if ( splitline[0] != "palmrun"): return 1 else: self.group_execution.setEnabled(True) # Loop for all parameters in palmrunline i = len(splitline)-1 while i >= 1: # Determine parameter splitparameter = splitline[i].split(" ") parameter = splitparameter[0] splitparameter.pop(0) options = " ".join(splitparameter) options = options.replace("\"","") # Check for suitable switch if ( parameter == "r"): if ( options != ""): self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").setText(options) nojob = False else: nojob = True elif ( parameter == "c"): tmpindex = self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").findText(options,QtCore.Qt.MatchExactly) if tmpindex != -1: self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").setCurrentIndex(tmpindex) else: self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").setCurrentIndex(0) elif ( parameter == "q"): self.group_execution.findChild(QtGui.QLineEdit,"line_q").setText(options) elif ( parameter == "A"): self.group_execution.findChild(QtGui.QLineEdit,"line_account").setText(options) elif ( parameter == "X"): self.group_execution.findChild(QtGui.QLineEdit,"line_pe").setText(options) elif ( parameter == "T"): self.group_execution.findChild(QtGui.QLineEdit,"line_tpn").setText(options) elif ( parameter == "t"): self.group_execution.findChild(QtGui.QLineEdit,"line_time").setText(options) elif ( parameter == "B"): self.group_execution.findChild(QtGui.QCheckBox,"check_delete_tmp_files").setChecked(True) elif ( parameter == "v"): self.group_execution.findChild(QtGui.QCheckBox,"check_verbose").setChecked(True) elif ( parameter == "b"): self.group_advanced.findChild(QtGui.QCheckBox,"check_b").setChecked(True) elif ( parameter == "F"): self.group_advanced.findChild(QtGui.QCheckBox,"check_F").setChecked(True) elif ( parameter == "I"): self.group_advanced.findChild(QtGui.QCheckBox,"check_I").setChecked(True) elif ( parameter == "k"): self.group_advanced.findChild(QtGui.QCheckBox,"check_k").setChecked(True) elif ( parameter == "O"): self.group_advanced.findChild(QtGui.QCheckBox,"check_O").setChecked(True) elif ( parameter == "x"): self.group_advanced.findChild(QtGui.QCheckBox,"check_x").setChecked(True) elif ( parameter == "Z"): self.group_advanced.findChild(QtGui.QCheckBox,"check_Z").setChecked(True) elif ( parameter == "m"): self.group_advanced.findChild(QtGui.QLineEdit,"line_m").setText(options) elif ( parameter == "M"): self.group_advanced.findChild(QtGui.QLineEdit,"line_M").setText(options) elif ( parameter == "D"): self.group_advanced.findChild(QtGui.QLineEdit,"line_D").setText(options) elif ( parameter == "c"): self.group_advanced.findChild(QtGui.QLineEdit,"line_c").setText(options) elif ( parameter == "s"): self.group_advanced.findChild(QtGui.QLineEdit,"line_s").setText(options) elif ( parameter == "w"): self.group_advanced.findChild(QtGui.QLineEdit,"line_w").setText(options) # Determine settings for coupled restart runs elif ( parameter == "Y"): optionssplit = options.split(" ") group_coupled = self.group_execution.findChild(QtGui.QGroupBox,"group_coupled") group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setEnabled(True) group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setEnabled(True) group_coupled.findChild(QtGui.QLabel,"label_coupled1").setEnabled(True) group_coupled.findChild(QtGui.QLabel,"label_coupled2").setEnabled(True) group_coupled.findChild(QtGui.QLabel,"label_coupled3").setEnabled(True) group_coupled.findChild(QtGui.QLabel,"label_coupling").setEnabled(True) if (optionssplit.count() == 2): group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setEnabled(optionssplit[0]) group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setEnabled(optionssplit[1]) else: group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setText("") group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setText("") coupled_run = True elif ( parameter == "y"): self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(3) # Determine settings for the run control list elif ( parameter == "a"): optionssplit = options.split(" ") options_2 = None options_all = None j = 0 while j < len(optionssplit): options_all = optionssplit[j] options_2 = optionssplit[j][:2] if (options_2 == "d3"): if (options_all[:3][-1] == "#"): self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(0) elif (options_all[:3][-1] == "r"): self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(1) elif (options_all[:3][-1] == "o"): ocean_run = True if (options_all == "restart"): self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").setChecked(True) # Check if _pdf file is available, otherwise notice user jobname = str(self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").text()) restartfile = "%sJOBS/%s/INPUT/%s_p3dr" % (palm_dir,jobname,jobname) if (os.path.exists(restartfile) == True): self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("") else: self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("Warning: No p3dr file \found!") j = j+1 # All unknown parameters are set as extra user parameters else: print parameter user = "%s-%s \"%s\" " % (user,parameter,options) splitline.removeAt(i) i = i-1 # Change drop box state in case of ocean precursor or coupled restart runs if ( ocean_run == True ): if ( coupled_run == True ): self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(4) else: self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(3) if ( user != ""): self.group_advanced.findChild(QtGui.QLineEdit,"line_user").setText(user) # Join palmrunline and post it to mainwindow palmrunline = " -".join(splitline) self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) # Disable mainwindow if no job was found, otherwise enable if ( nojob == True ): self.group_execution.setEnabled(False) self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False) self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(False) self.group_execution.findChild(QtGui.QComboBox, "drop_job").setEnabled(False) self.group_advanced.setEnabled(False) self.check_advanced.setEnabled(False) self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(False) else: self.group_execution.setEnabled(True) self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True) self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(True) self.group_execution.findChild(QtGui.QComboBox, "drop_job").setEnabled(True) self.group_advanced.setEnabled(True) self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True) self.tabWidget.setCurrentIndex(0) # open saved commandline ################################## def open_from_file(self): # Select filename and open it filename = QtGui.QFileDialog.getOpenFileName(self, "Open File","Save files (*.sav)") if ( filename != ""): file = open(filename, "r") if ( file is not None ): # File opened successfully palmrunline = file.read() file.close() # In case a palmrunline was found, load it to mainwindow if ( palmrunline != ""): palmrunline = palmrunline[17:] self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) self.setup_gui(palmrunline) # open saved commandline ################################## def open_last(self): # Select filename and open it filename = "%s/.palmrungui.history" % (palm_dir) if os.path.exists(filename): pass else: return file = open(filename, "r") if ( file is not None ): # File opened successfully lines = file.readlines() palmrunline = lines[len(lines)-1] palmrunline = palmrunline[:len(palmrunline)-1] file.close() # In case a palmrunline was found, load it to mainwindow if ( palmrunline != ""): palmrunline = palmrunline[17:len(palmrunline)] self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) self.setup_gui(palmrunline) def update_all(self): self.setEnabled(False) self.list_input.clear() self.list_user.clear() self.list_monitoring.clear() self.list_output.clear() self.load_jobs() self.setEnabled(True) # Load jobs into list def load_jobs(self): self.list_jobs.clear() self.push_copy.setEnabled(False) self.push_create_set.setEnabled(False) self.line_path.setText(job_dir + "/") list_of_files = os.listdir(job_dir) for i in range(0,len(list_of_files)): tmp_file = job_dir + "/" + list_of_files[i] if ( os.path.isdir(tmp_file) ): self.list_jobs.addItem(str(list_of_files[i])) # Update input and user code lists def update_input(self): self.list_input.clear() self.list_user.clear() self.list_monitoring.clear() self.list_output.clear() self.push_copy.setEnabled(True) self.push_create_set.setEnabled(True) job_to_show = job_dir + "/" + self.list_jobs.currentItem().text() + "/INPUT" if ( os.path.isdir(job_to_show) ): list_of_files = os.listdir(job_to_show) for i in range(0,len(list_of_files)): tmp_file = job_to_show + "/" + list_of_files[i] if ( os.path.isfile(tmp_file) ): self.list_input.addItem(str(list_of_files[i])) job_to_show = job_dir + "/" + self.list_jobs.currentItem().text() + "/USER_CODE" if ( os.path.isdir(job_to_show) ): list_of_files = os.listdir(job_to_show) for i in range(0,len(list_of_files)): tmp_file = job_to_show + "/" + list_of_files[i] if ( os.path.isfile(tmp_file) ): self.list_user.addItem(str(list_of_files[i])) job_to_show = job_dir + "/" + self.list_jobs.currentItem().text() + "/MONITORING" if ( os.path.isdir(job_to_show) ): list_of_files = os.listdir(job_to_show) for i in range(0,len(list_of_files)): tmp_file = job_to_show + "/" + list_of_files[i] if ( os.path.isfile(tmp_file) ): self.list_monitoring.addItem(str(list_of_files[i])) job_to_show = job_dir + "/" + self.list_jobs.currentItem().text() + "/OUTPUT" if ( os.path.isdir(job_to_show) ): list_of_files = os.listdir(job_to_show) for i in range(0,len(list_of_files)): tmp_file = job_to_show + "/" + list_of_files[i] if ( os.path.isfile(tmp_file) ): self.list_output.addItem(str(list_of_files[i])) self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").setText(self.list_jobs.currentItem().text()) self.group_history.findChild(QtGui.QListWidget,"list_jobname").clearSelection() # Change palmrunline accordingly self.change_commandline("r","") self.change_commandline("a","") # Make a copy of a job def copy_job(self): self.setEnabled(False) old_job_name = self.list_jobs.currentItem().text() text, ret = QtGui.QInputDialog.getText(self, "Copy job", "Enter new job name:", mode = QtGui.QLineEdit.Normal, text = old_job_name) if ( ret ): new_job_name = str(text) else: self.setEnabled(True) return new_input_dir = job_dir + "/" + new_job_name + "/INPUT" # check if a job exists with the new job name if ( os.path.isdir(new_input_dir) ): notify = QtGui.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.") self.setEnabled(True) return else: os.makedirs(new_input_dir) # copy and rename input files (if present) job_to_copy = job_dir + "/" + old_job_name + "/INPUT" if ( os.path.isdir(job_to_copy) ): list_of_files = os.listdir(job_to_copy) for i in range(0,len(list_of_files)): tmp_file = job_to_copy + "/" + list_of_files[i] new_file = new_input_dir + "/" + list_of_files[i].replace(old_job_name, new_job_name) shutil.copy(tmp_file, new_file) new_user_dir = job_dir + "/" + new_job_name + "/USER_CODE" # check if user code exists in the new job directory if ( os.path.isdir(new_user_dir) ): notify = QtGui.QMessageBox.warning(self,'Create new user code directory',"Error. Could not create user code directory. A user code directiory with the new name already exists.") self.setEnabled(True) return else: os.makedirs(new_user_dir) # copy user code files (if present) user_to_copy = job_dir + "/" + old_job_name + "/USER_CODE" if ( os.path.isdir(user_to_copy) ): list_of_files = os.listdir(user_to_copy) for i in range(0,len(list_of_files)): tmp_file = user_to_copy + "/" + list_of_files[i] new_file = new_user_dir + "/" + list_of_files[i] shutil.copy(tmp_file, new_file) self.load_jobs() self.list_input.clear() self.list_user.clear() self.list_monitoring.clear() self.list_output.clear() self.setEnabled(True) # Create a whole set of jobs def create_set(self): global set_list # disable mainwindow self.setEnabled(False) # show Options Dialog opt = CreateSetBox() opt.exec_() old_job_name = self.list_jobs.currentItem().text() for j in range(0,len(set_list)): if ( set_list[j] != "" ): new_job_name = str(set_list[j]) new_input_dir = job_dir + "/" + str(set_list[j]) + "/INPUT" else: continue # check if a job exists with the new job name if ( os.path.isdir(new_input_dir) ): notify = QtGui.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.") self.setEnabled(True) return else: os.makedirs(new_input_dir) # copy and rename input files (if present) job_to_copy = job_dir + "/" + old_job_name + "/INPUT" if ( os.path.isdir(job_to_copy) ): list_of_files = os.listdir(job_to_copy) for i in range(0,len(list_of_files)): tmp_file = job_to_copy + "/" + list_of_files[i] new_file = new_input_dir + "/" + list_of_files[i].replace(old_job_name, new_job_name) shutil.copy(tmp_file, new_file) new_user_dir = job_dir + "/" + new_job_name + "/USER_CODE" # check if user code exists in the new job directory if ( os.path.isdir(new_user_dir) ): notify = QtGui.QMessageBox.warning(self,'Create new user code directory',"Error. Could not create user code directory. A user code directiory with the new name already exists.") self.setEnabled(True) return else: os.makedirs(new_user_dir) # copy user code files (if present) user_to_copy = job_dir + "/" + old_job_name + "/USER_CODE" if ( os.path.isdir(user_to_copy) ): list_of_files = os.listdir(user_to_copy) for i in range(0,len(list_of_files)): tmp_file = user_to_copy + "/" + list_of_files[i] new_file = new_user_dir + "/" + list_of_files[i] shutil.copy(tmp_file, new_file) self.load_jobs() self.list_input.clear() self.list_user.clear() self.list_monitoring.clear() self.list_output.clear() self.setEnabled(True) set_list = [] # Add a custom context menu def openmenuinput(self, position): menu = QtGui.QMenu() selection = self.list_input.selectedItems() if ( len(selection) != 0 ): openAction = menu.addAction('Open selected files') openAction.setStatusTip('Open file(s) in your favorite editor') openAction.triggered.connect(self.OpenFilesInput) action = menu.exec_(self.list_input.mapToGlobal(position)) # Add a custom context menu def openmenuuser(self, position): menu = QtGui.QMenu() selection = self.list_user.selectedItems() if ( len(selection) != 0 ): openAction = menu.addAction('Open selected files') openAction.setStatusTip('Open file(s) in your favorite editor') openAction.triggered.connect(self.OpenFilesUser) action = menu.exec_(self.list_user.mapToGlobal(position)) # Add a custom context menu def openmenuoutput(self, position): menu = QtGui.QMenu() selection = self.list_output.selectedItems() if ( len(selection) != 0 ): openAction = menu.addAction('Open selected files') openAction.setStatusTip('Open file(s) in your favorite editor') openAction.triggered.connect(self.OpenFilesOutput) action = menu.exec_(self.list_output.mapToGlobal(position)) # Add a custom context menu def openmenumonitoring(self, position): menu = QtGui.QMenu() selection = self.list_monitoring.selectedItems() if ( len(selection) != 0 ): openAction = menu.addAction('Open selected files') openAction.setStatusTip('Open file(s) in your favorite editor') openAction.triggered.connect(self.OpenFilesMonitoring) action = menu.exec_(self.list_monitoring.mapToGlobal(position)) def OpenFilesInput(self): sel_job = self.list_jobs.currentItem().text() sel_files = self.list_input.selectedItems() input_dir = job_dir + "/" + sel_job + "/INPUT/" open_files = "" for i in range(0,len(sel_files)): open_files = open_files + "xdg-open " + input_dir + sel_files[i].text() + "; " os.system(str(open_files)) def OpenFilesUser(self): sel_job = self.list_jobs.currentItem().text() sel_files = self.list_user.selectedItems() input_dir = job_dir + "/" + sel_job + "/USER_CODE/" open_files = "" for i in range(0,len(sel_files)): open_files = open_files + "xdg-open " + input_dir + sel_files[i].text() + "; " os.system(str(open_files)) selection = self.list_jobs.selectedItems() def OpenFilesMonitoring(self): sel_job = self.list_jobs.currentItem().text() sel_files = self.list_monitoring.selectedItems() input_dir = job_dir + "/" + sel_job + "/MONITORING/" open_files = "" for i in range(0,len(sel_files)): open_files = open_files + "xdg-open " + input_dir + sel_files[i].text() + "; " os.system(str(open_files)) selection = self.list_jobs.selectedItems() def OpenFilesOutput(self): sel_job = self.list_jobs.currentItem().text() sel_files = self.list_output.selectedItems() input_dir = job_dir + "/" + sel_job + "/OUTPUT/" open_files = "" for i in range(0,len(sel_files)): open_files = open_files + "xdg-open " + input_dir + sel_files[i].text() + "; " os.system(str(open_files)) selection = self.list_jobs.selectedItems() # Message box for showing RUN_CONTROL output class CreateSetBox(QtGui.QDialog): def __init__(self): super(CreateSetBox, self).__init__() uic.loadUi(palm_bin + '/palmrungui_files/create_set.ui', self) self.show() return # Cancel button def rejected(self): self.close() return # OK button def accept(self): global set_list text = self.list.toPlainText() set_list = text.split('\n') self.close() return if __name__ == "__main__": app = QtGui.QApplication(sys.argv) window = Mainwindow() window.show() sys.exit(app.exec_())