[2413] | 1 | #!/usr/bin/python -B |
---|
| 2 | # -*- coding: utf-8 -*- |
---|
| 3 | #--------------------------------------------------------------------------------# |
---|
[2696] | 4 | # This file is part of the PALM model system. |
---|
[2413] | 5 | # |
---|
| 6 | # PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 7 | # of the GNU General Public License as published by the Free Software Foundation, |
---|
| 8 | # either version 3 of the License, or (at your option) any later version. |
---|
| 9 | # |
---|
| 10 | # PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | # |
---|
| 14 | # You should have received a copy of the GNU General Public License along with |
---|
| 15 | # PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | # |
---|
[2718] | 17 | # Copyright 1997-2018 Leibniz Universitaet Hannover |
---|
[2413] | 18 | #--------------------------------------------------------------------------------# |
---|
| 19 | # |
---|
| 20 | # Current revisions: |
---|
| 21 | # ----------------- |
---|
| 22 | # |
---|
| 23 | # |
---|
| 24 | # Former revisions: |
---|
| 25 | # ----------------- |
---|
| 26 | # $Id: palmrungui 2718 2018-01-02 08:49:38Z raasch $ |
---|
[2716] | 27 | # Corrected "Former revisions" section |
---|
| 28 | # |
---|
| 29 | # 2696 2017-12-14 17:12:51Z kanani |
---|
| 30 | # Change in file header (GPL part) |
---|
| 31 | # |
---|
| 32 | # 2484 2017-09-20 14:22:42Z maronga |
---|
[2484] | 33 | # Added PALM logo |
---|
| 34 | # |
---|
| 35 | # 2480 2017-09-19 06:24:14Z maronga |
---|
[2480] | 36 | # option -A (project account number) added |
---|
| 37 | # |
---|
| 38 | # 2477 2017-09-18 08:42:29Z maronga |
---|
[2477] | 39 | # Renamed restart run appendix from "f" to "r". Bugfix for displaying restart runs.> |
---|
| 40 | # Revised list of recently submitted jobs |
---|
| 41 | # |
---|
| 42 | # 2413 2017-09-06 12:48:29Z maronga |
---|
[2413] | 43 | # Renamed to palmrungui and adapted for use with palmrun instead of mrun. |
---|
| 44 | # |
---|
| 45 | # 2316 2017-07-20 07:53:42Z maronga |
---|
| 46 | # Initial revision in python |
---|
| 47 | # |
---|
| 48 | # |
---|
| 49 | # |
---|
| 50 | # Description: |
---|
| 51 | # ------------ |
---|
| 52 | # Graphical user interface for the palmrun script. |
---|
| 53 | # @author Felix Gaschler |
---|
| 54 | # @author Björn Maronga (maronga@muk.uni-hannover.de) |
---|
| 55 | # |
---|
| 56 | # Instructions: |
---|
| 57 | # ------------- |
---|
| 58 | # |
---|
| 59 | #------------------------------------------------------------------------------! |
---|
| 60 | |
---|
| 61 | import sys |
---|
| 62 | import subprocess |
---|
| 63 | from PyQt4 import QtCore, QtGui, uic |
---|
| 64 | from PyQt4.QtCore import QProcess |
---|
| 65 | from time import strftime |
---|
| 66 | import os |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | # Determine PALM directories |
---|
| 70 | try: |
---|
| 71 | devnull = open(os.devnull, 'w') |
---|
| 72 | out = subprocess.check_output("echo $PALM_BIN", shell=True, stderr=subprocess.STDOUT) |
---|
| 73 | palm_bin = out.rstrip() |
---|
| 74 | palm_dir = out.split("palm")[0] + "palm/" + out.split("palm")[1].split("/")[1] |
---|
| 75 | out = None |
---|
| 76 | except: |
---|
| 77 | print "Error. $PALM_BIN is not set." |
---|
| 78 | raise SystemExit |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | palmrunline = "" |
---|
| 82 | name_of_file = os.path.basename(__file__) |
---|
| 83 | |
---|
| 84 | palmrungui_path = os.path.realpath(__file__) |
---|
| 85 | version_path = palmrungui_path[:len(palmrungui_path)-14-len(name_of_file)-1] |
---|
| 86 | |
---|
| 87 | Ui_MainWindow = uic.loadUiType("%s/palmrungui_files/mainwindow.ui" % (palm_bin))[0] |
---|
| 88 | Ui_helpDialog = uic.loadUiType("%s/palmrungui_files/help.ui" % (palm_bin))[0] |
---|
| 89 | Ui_aboutDialog = uic.loadUiType("%s/palmrungui_files/about.ui" % (palm_bin))[0] |
---|
| 90 | |
---|
| 91 | class HelpDialog(QtGui.QDialog,Ui_helpDialog): |
---|
| 92 | def __init__(self, parent=None): |
---|
| 93 | super(HelpDialog,self).__init__() |
---|
| 94 | self.setupUi(self) |
---|
| 95 | |
---|
| 96 | class AboutDialog(QtGui.QDialog,Ui_aboutDialog): |
---|
| 97 | def __init__(self, parent=None): |
---|
| 98 | super(AboutDialog,self).__init__() |
---|
| 99 | self.setupUi(self) |
---|
| 100 | |
---|
| 101 | class Mainwindow(QtGui.QMainWindow, Ui_MainWindow): |
---|
| 102 | def __init__(self, parent=None): |
---|
| 103 | super(Mainwindow, self).__init__() |
---|
[2484] | 104 | self.setupUi(self) |
---|
[2413] | 105 | |
---|
[2484] | 106 | self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png")) |
---|
| 107 | |
---|
[2477] | 108 | self.recent_jobs(50) |
---|
[2413] | 109 | commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline") |
---|
| 110 | commandline.setText("") |
---|
| 111 | |
---|
| 112 | self.tabWidget.setCurrentIndex(0) |
---|
| 113 | |
---|
[2484] | 114 | |
---|
[2413] | 115 | filename = "%s/.palmrun.gui.default" % (version_path) |
---|
| 116 | if os.path.exists(filename): |
---|
| 117 | pass |
---|
| 118 | else: |
---|
| 119 | return |
---|
| 120 | |
---|
| 121 | file = open(filename, "r") |
---|
| 122 | if ( file is not None ): |
---|
| 123 | # File opened successfully |
---|
| 124 | palmrunline = file.readline() |
---|
| 125 | #if neue zeile zeichen |
---|
| 126 | palmrunline = palmrunline[:len(palmrunline)-1] |
---|
| 127 | file.close() |
---|
| 128 | |
---|
| 129 | # In case a palmrunline was found, load it to mainwindow |
---|
| 130 | if ( palmrunline != ""): |
---|
| 131 | palmrunline = palmrunline[17:] |
---|
| 132 | commandline.setText(palmrunline) |
---|
| 133 | self.setup_gui(palmrunline) |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | # starts xterm with palmrun commandline |
---|
| 137 | ####################################### |
---|
| 138 | def startpalmrun(self): |
---|
| 139 | palmrunline = str(self.groupBox.findChild(QtGui.QLineEdit,"commandline").text()) |
---|
| 140 | userline = str(self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text()) |
---|
| 141 | |
---|
| 142 | # Check for empty line |
---|
| 143 | palmrunline_save = palmrunline; |
---|
| 144 | if (userline != ""): |
---|
| 145 | palmrunline = "%s %s" % (palmrunline,userline) |
---|
| 146 | history_line = palmrunline |
---|
| 147 | |
---|
| 148 | # Disable the main window |
---|
| 149 | self.tabWidget.setEnabled(False) |
---|
| 150 | self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False) |
---|
| 151 | self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("wait...") |
---|
| 152 | self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText("Executing palmrun in xterm...") |
---|
| 153 | |
---|
| 154 | # Wait until all commands have been executed (ugly) ? |
---|
| 155 | #for i in range(0,21): |
---|
| 156 | # qApp->processEvents() |
---|
| 157 | |
---|
| 158 | # Start xterm as QProcess |
---|
| 159 | palmrun = QProcess() |
---|
| 160 | palmrun.setProcessChannelMode(QProcess.MergedChannels) # mergedChannels |
---|
| 161 | palmrun.setWorkingDirectory(version_path) |
---|
| 162 | |
---|
| 163 | geomet = self.frameGeometry() |
---|
| 164 | |
---|
| 165 | posx = geomet.x()+geomet.width() |
---|
| 166 | posy = geomet.y() |
---|
| 167 | |
---|
| 168 | s = " -title \"Executing palmrun...\" -fa \"Monospace\" -fs 11 -geometry \"80x38+%d+%d\" -e \"" % (posx,posy) |
---|
| 169 | palmrunline = "%s%s;echo -n '--> Press enter to continue...';read yesno\"</dev/stdin" % (s, palmrunline.replace("\"","\'")) |
---|
| 170 | |
---|
| 171 | mString = "xterm %s" % (palmrunline) |
---|
| 172 | palmrun.start(mString); |
---|
| 173 | |
---|
| 174 | if( palmrun.waitForStarted() is False ): |
---|
| 175 | return |
---|
| 176 | |
---|
| 177 | # Wait until palmrun has finished or wait for 200 minutes |
---|
| 178 | palmrun.waitForFinished(3600000); |
---|
| 179 | |
---|
| 180 | # Jobs has been submitted or aborted. Continuing... |
---|
| 181 | # Save the palmrun command to history file |
---|
| 182 | filename = "%s/.palm.history" % (version_path) |
---|
| 183 | tmstamp = strftime("%Y/%m/%d %H:%M") |
---|
| 184 | |
---|
| 185 | file = open(filename,"a") |
---|
| 186 | s = "%s %s\n" % (tmstamp,history_line) |
---|
| 187 | file.write(s) |
---|
| 188 | file.close() |
---|
| 189 | |
---|
| 190 | # Enable main window again |
---|
| 191 | self.tabWidget.setEnabled(True) |
---|
| 192 | self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True) |
---|
| 193 | self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("Start palmrun") |
---|
| 194 | self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline_save); |
---|
| 195 | |
---|
| 196 | # Reload recent jobs |
---|
[2477] | 197 | self.recent_jobs(50) |
---|
[2413] | 198 | |
---|
| 199 | |
---|
| 200 | # loads recent jobs |
---|
| 201 | ###################################### |
---|
| 202 | def recent_jobs(self, number): |
---|
| 203 | fileDir = "%s/.palm.history" % (version_path) |
---|
| 204 | if os.path.exists(fileDir): |
---|
| 205 | pass |
---|
| 206 | else: |
---|
| 207 | return |
---|
| 208 | |
---|
| 209 | file = open(fileDir,"r") |
---|
| 210 | history = file.readlines() |
---|
| 211 | tmphistory = list() |
---|
| 212 | file.close(); |
---|
| 213 | j = 0; |
---|
| 214 | |
---|
| 215 | list_jobname = self.group_job.findChild(QtGui.QListWidget,"list_jobname") |
---|
| 216 | list_jobname.clear() |
---|
| 217 | |
---|
| 218 | # Read history entries and append to recent job list |
---|
| 219 | i=len(history)-1 |
---|
| 220 | count = 0 |
---|
[2477] | 221 | while i>=0 and count<number: |
---|
[2413] | 222 | timestamp = history[i][:16] |
---|
| 223 | listitem = history[i][17:len(history[i])-1] |
---|
| 224 | matchitems = list_jobname.findItems(listitem, QtCore.Qt.MatchExactly) |
---|
| 225 | |
---|
| 226 | if ( len(matchitems) == 0 ): |
---|
[2477] | 227 | listitem = filter(None,listitem.split(" -d"))[1] |
---|
| 228 | listitem = filter(None,listitem.split(" -"))[0] |
---|
| 229 | listitem = listitem.replace(" ",""); |
---|
[2413] | 230 | list_jobname.addItem(listitem); |
---|
| 231 | s = "%s (%s)" % (listitem,timestamp) |
---|
| 232 | tmphistory.append(s); |
---|
| 233 | count = count +1 |
---|
| 234 | j = j+1 |
---|
| 235 | |
---|
| 236 | if ( j == number ): |
---|
| 237 | break |
---|
| 238 | i = i-1 |
---|
| 239 | |
---|
| 240 | # Send to list |
---|
| 241 | list_jobname.clear(); |
---|
| 242 | |
---|
| 243 | i=0 |
---|
| 244 | while i<len(tmphistory): |
---|
| 245 | list_jobname.addItem(tmphistory[i]); |
---|
| 246 | i = i+1 |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | # Enables coupled settings |
---|
| 250 | ############################### |
---|
| 251 | def enable_coupled(self): |
---|
| 252 | coupledState = self.group_job.findChild(QtGui.QComboBox, "drop_job").currentText() |
---|
| 253 | group = self.group_execution.findChild(QtGui.QGroupBox, "group_coupled") |
---|
| 254 | |
---|
| 255 | if (coupledState == "Restart run (coupled atmosphere ocean)" or coupledState == "Initial run (coupled atmosphere ocean)"): |
---|
| 256 | self.group_coupled.setEnabled(True) |
---|
| 257 | else: |
---|
| 258 | self.group_coupled.setEnabled(False) |
---|
| 259 | |
---|
| 260 | |
---|
| 261 | # select a job via "select"-button |
---|
| 262 | ################################ |
---|
| 263 | def choosejob(self): |
---|
| 264 | jobDir = "%s/JOBS" % (version_path) |
---|
| 265 | |
---|
| 266 | # Pick a job from dialog |
---|
| 267 | filename = QtGui.QFileDialog.getExistingDirectory(self, "Open a folder", jobDir, QtGui.QFileDialog.ShowDirsOnly) |
---|
| 268 | |
---|
| 269 | # If a file was selected, load it into mainwindow |
---|
| 270 | if ( filename != ""): |
---|
| 271 | jobname = os.path.basename(unicode(filename)) |
---|
| 272 | self.group_job.findChild(QtGui.QLineEdit,"line_jobname").setText(jobname) |
---|
| 273 | self.group_job.findChild(QtGui.QListWidget,"list_jobname").clearSelection() |
---|
| 274 | |
---|
| 275 | # Change palmrunline accordingly |
---|
| 276 | self.change_commandline("d","") |
---|
| 277 | self.change_commandline("a","") |
---|
| 278 | return |
---|
| 279 | else: |
---|
| 280 | return |
---|
| 281 | |
---|
| 282 | |
---|
[2477] | 283 | # select a job via click from list |
---|
[2413] | 284 | ################################# |
---|
| 285 | def choosejob_list(self): |
---|
| 286 | # Get selected item from list |
---|
| 287 | list_jobname = self.group_job.findChild(QtGui.QListWidget,"list_jobname") |
---|
| 288 | filename = str(list_jobname.currentItem().text()) |
---|
| 289 | itemint = list_jobname.currentRow() |
---|
| 290 | |
---|
| 291 | # Reload list |
---|
| 292 | self.setupUi(self) |
---|
[2477] | 293 | self.recent_jobs(50) |
---|
[2413] | 294 | |
---|
| 295 | # Set selected item to jobname |
---|
| 296 | list_jobname.item(itemint).setSelected(True); |
---|
| 297 | |
---|
| 298 | timestamp = filename[len(filename)-17:][:16] |
---|
| 299 | jobname = filename[:len(filename) - 19]; |
---|
| 300 | |
---|
| 301 | fileDir = "%s/.palm.history" % (version_path) |
---|
| 302 | file = open(fileDir,"r") |
---|
| 303 | history = file.readlines() |
---|
| 304 | tmphistory = list() |
---|
| 305 | file.close(); |
---|
| 306 | |
---|
| 307 | i = len(history) |
---|
| 308 | while i>=1: |
---|
| 309 | listitem = history[i-1][17:len(history[i-1])-1] |
---|
| 310 | listitem = filter(None,listitem.split(" -d"))[1] |
---|
| 311 | listitem = filter(None,listitem.split(" -"))[0] |
---|
| 312 | listitem = listitem.replace(" ",""); |
---|
| 313 | |
---|
| 314 | # Select command line with correct timestamp and jobname |
---|
| 315 | if (history[i-1][:16] == timestamp and listitem == jobname): |
---|
| 316 | palmrunline = history[i-1] |
---|
| 317 | palmrunline = palmrunline[17:] |
---|
| 318 | palmrunline = palmrunline[:len(palmrunline)-1] |
---|
| 319 | self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline); |
---|
| 320 | self.setup_gui(palmrunline); |
---|
[2477] | 321 | self.list_jobname.item(itemint).setSelected(True); |
---|
| 322 | |
---|
[2413] | 323 | return |
---|
| 324 | i = i-1 |
---|
| 325 | |
---|
| 326 | # Change run identifer (initial, restart, coupled...) |
---|
| 327 | ###################################################### |
---|
| 328 | def change_rc_list(self): |
---|
| 329 | drop_job = self.group_job.findChild(QtGui.QComboBox,"drop_job").currentText() |
---|
| 330 | self.change_commandline("a","") |
---|
| 331 | |
---|
| 332 | # Enable PE distribution for atmosphere/ocean |
---|
| 333 | if ( drop_job == "Restart run (coupled atmosphere ocean)" or drop_job == "Initial run (coupled atmosphere ocean)"): |
---|
| 334 | drop_atmos = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").text() |
---|
| 335 | drop_ocean = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").text() |
---|
| 336 | s = "%s %s" % (drop_atmos,drop_ocean) |
---|
| 337 | self.change_commandline("Y",s) |
---|
| 338 | |
---|
| 339 | |
---|
| 340 | if ( drop_job == "Restart run" or drop_job == "Restart run (coupled atmosphere ocean)"): |
---|
| 341 | self.change_commandline("d","") |
---|
| 342 | |
---|
| 343 | # Check of ocean runs |
---|
| 344 | else: |
---|
| 345 | self.delete_commandline("Y") |
---|
| 346 | if (drop_job == "Precursor run (ocean)"): |
---|
| 347 | self.activate_flag("y") |
---|
| 348 | else: |
---|
| 349 | self.deactivate_flag("y") |
---|
| 350 | |
---|
| 351 | # changes commandline depending on parameters |
---|
| 352 | ########################################################## |
---|
| 353 | def change_commandline(self, id_str, fwt_str): |
---|
| 354 | fwt_str = str(fwt_str) |
---|
| 355 | initialize = False |
---|
| 356 | palmrunline = str(self.groupBox.findChild(QtGui.QLineEdit,"commandline").text()) |
---|
| 357 | s = " -%s " % (id_str) |
---|
| 358 | splitline = filter(None,palmrunline.split(s)) |
---|
| 359 | |
---|
| 360 | if ( len(splitline) == 0 ): |
---|
| 361 | splitline.append("palmrun") |
---|
| 362 | splitline.append(" ") |
---|
| 363 | initialize = True |
---|
| 364 | |
---|
| 365 | elif ( len(splitline) == 1 ): |
---|
| 366 | splitline.append(" ") |
---|
| 367 | |
---|
| 368 | param = splitline[1].split("-") |
---|
| 369 | |
---|
| 370 | # Change in parameter "d" (jobname) |
---|
| 371 | if (id_str == "d"): |
---|
| 372 | filename = str(self.group_job.findChild(QtGui.QLineEdit,"line_jobname").text()) |
---|
| 373 | s = filename.split("JOBS/") |
---|
| 374 | param[0] = s[len(s)-1] |
---|
| 375 | |
---|
| 376 | if ( initialize == True ):#and self.group_runcontrol.isEnabled() == True ): |
---|
| 377 | self.group_runcontrol.setEnabled(True) |
---|
| 378 | self.group_execution.setEnabled(True) |
---|
| 379 | self.group_job.findChild(QtGui.QComboBox,"drop_job").setEnabled(True) |
---|
| 380 | self.group_advanced.setEnabled(True) |
---|
| 381 | self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True) |
---|
| 382 | self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(True) |
---|
| 383 | |
---|
| 384 | elif ( param[0] == ""): |
---|
| 385 | self.group_runcontrol.setEnabled(False) |
---|
| 386 | self.group_execution.setEnabled(False) |
---|
| 387 | self.group_job.findChild(QtGui.QComboBox,"drop_job").setEnabled(False) |
---|
| 388 | self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False) |
---|
| 389 | self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(False) |
---|
| 390 | self.group_advanced.setEnabled(False) |
---|
| 391 | self.delete_commandline("d") |
---|
| 392 | self.change_commandline("a","remove") |
---|
| 393 | self.group_job.findChild(QtGui.QLabel,"label_usercode").setText("") |
---|
| 394 | return 1 |
---|
| 395 | |
---|
| 396 | else: |
---|
| 397 | # Check if user code is available |
---|
[2477] | 398 | usercode = "%s/JOBS/%s/USER_CODE" % (version_path,param[0]) |
---|
| 399 | |
---|
[2413] | 400 | if (os.path.exists(usercode) is True): |
---|
| 401 | self.group_job.findChild(QtGui.QLabel,"label_usercode").setText("<font color='green'>User code found.</font>") |
---|
| 402 | |
---|
| 403 | else: |
---|
| 404 | self.group_job.findChild(QtGui.QLabel,"label_usercode").setText("<font color='red'>Warning: no user code found!</font>") |
---|
| 405 | |
---|
| 406 | |
---|
| 407 | # Check if _pdf file is available, otherwise notice user |
---|
| 408 | drop_job = self.group_job.findChild(QtGui.QComboBox,"drop_job").currentText() |
---|
| 409 | if ( self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").checkState() == 2 or |
---|
| 410 | drop_job == "Restart run" or drop_job == "Restart run (coupled atmosphere ocean)" ): |
---|
| 411 | |
---|
| 412 | jobname = self.group_job.findChild(QtGui.QLineEdit, "line_jobname").text() |
---|
[2477] | 413 | restartfile = "%s/JOBS/%s/INPUT/%s_p3dr" % (version_path,jobname,jobname) |
---|
[2413] | 414 | |
---|
| 415 | if (os.path.exists(restartfile) == True): |
---|
| 416 | self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("") |
---|
| 417 | |
---|
| 418 | |
---|
| 419 | if ( drop_job == "Restart run (coupled atmosphere ocean)" ): |
---|
[2477] | 420 | restartfileo = "%s/JOBS/%s/INPUT/%s_p3dor" % (version_path,jobname,jobname) |
---|
[2413] | 421 | if (os.path.exists(restartfileo) == True): |
---|
| 422 | self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("hooo") |
---|
| 423 | |
---|
| 424 | else: |
---|
[2477] | 425 | self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dor file found!</font>") |
---|
[2413] | 426 | |
---|
| 427 | else: |
---|
[2477] | 428 | self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dr file found!</font>") |
---|
[2413] | 429 | |
---|
| 430 | |
---|
| 431 | |
---|
| 432 | |
---|
| 433 | self.group_runcontrol.setEnabled(True) |
---|
| 434 | self.group_execution.setEnabled(True) |
---|
| 435 | self.drop_job.setEnabled(True) |
---|
| 436 | self.group_advanced.setEnabled(True) |
---|
| 437 | |
---|
| 438 | # Change in parameter "a" (run control list) |
---|
| 439 | elif (id_str == "a"): |
---|
| 440 | status_ts = self.group_runcontrol.findChild(QtGui.QCheckBox,"check_ts").checkState() |
---|
| 441 | status_pr = self.group_runcontrol.findChild(QtGui.QCheckBox,"check_pr").checkState() |
---|
| 442 | status_xy = self.group_runcontrol.findChild(QtGui.QCheckBox,"check_xy").checkState() |
---|
| 443 | status_xz = self.group_runcontrol.findChild(QtGui.QCheckBox,"check_xz").checkState() |
---|
| 444 | status_yz = self.group_runcontrol.findChild(QtGui.QCheckBox,"check_yz").checkState() |
---|
| 445 | status_3d = self.group_runcontrol.findChild(QtGui.QCheckBox,"check_3d").checkState() |
---|
| 446 | status_ma = self.group_runcontrol.findChild(QtGui.QCheckBox,"check_ma").checkState() |
---|
| 447 | status_sp = self.group_runcontrol.findChild(QtGui.QCheckBox,"check_sp").checkState() |
---|
| 448 | status_pts = self.group_runcontrol.findChild(QtGui.QCheckBox,"check_pts").checkState() |
---|
| 449 | status_prt = self.group_runcontrol.findChild(QtGui.QCheckBox,"check_prt").checkState() |
---|
| 450 | |
---|
| 451 | drop_job = self.group_job.findChild(QtGui.QComboBox,"drop_job").currentText() |
---|
| 452 | rc_flag = "#" |
---|
| 453 | |
---|
| 454 | if (drop_job == "Initial run"): |
---|
| 455 | rc_flag = "#" |
---|
| 456 | |
---|
| 457 | elif (drop_job == "Restart run"): |
---|
[2477] | 458 | rc_flag = "r" |
---|
[2413] | 459 | |
---|
| 460 | elif (drop_job == "Precursor run (atmosphere)"): |
---|
| 461 | rc_flag = "#" |
---|
| 462 | |
---|
| 463 | elif (drop_job == "Precursor run (ocean)"): |
---|
| 464 | rc_flag = "o#" |
---|
| 465 | |
---|
| 466 | elif (drop_job == "Initial run (coupled atmosphere ocean)"): |
---|
| 467 | rc_flag = "#" |
---|
| 468 | |
---|
| 469 | elif (drop_job == "Restart run (coupled atmosphere ocean)"): |
---|
[2477] | 470 | rc_flag = "r" |
---|
[2413] | 471 | |
---|
| 472 | param[0] = "\"d3%s" % (rc_flag) |
---|
| 473 | |
---|
| 474 | if (status_ts == 2): |
---|
| 475 | param[0] = "%s ts%s" % (param[0],rc_flag) |
---|
| 476 | |
---|
| 477 | if (status_pr == 2): |
---|
| 478 | param[0] = "%s pr%s" % (param[0],rc_flag) |
---|
| 479 | |
---|
| 480 | if (status_xy == 2): |
---|
| 481 | param[0] = "%s xy%s" % (param[0],rc_flag) |
---|
| 482 | |
---|
| 483 | if (status_xz == 2): |
---|
| 484 | param[0] = "%s xz%s" % (param[0],rc_flag) |
---|
| 485 | |
---|
| 486 | if (status_yz == 2): |
---|
| 487 | param[0] = "%s yz%s" % (param[0],rc_flag) |
---|
| 488 | |
---|
| 489 | if (status_3d == 2): |
---|
| 490 | param[0] = "%s 3d%s" % (param[0],rc_flag) |
---|
| 491 | |
---|
| 492 | if (status_ma == 2): |
---|
| 493 | param[0] = "%s ma%s" % (param[0],rc_flag) |
---|
| 494 | |
---|
| 495 | if (status_sp == 2): |
---|
| 496 | param[0] = "%s sp%s" % (param[0],rc_flag) |
---|
| 497 | |
---|
| 498 | if (status_prt == 2): |
---|
| 499 | param[0] = "%s prt%s" % (param[0],rc_flag) |
---|
| 500 | |
---|
| 501 | if (status_pts == 2): |
---|
| 502 | param[0] = "%s pts%s" % (param[0],rc_flag) |
---|
| 503 | |
---|
| 504 | |
---|
| 505 | if (drop_job == "Restart run (coupled atmosphere ocean)" or drop_job == "Initial run (coupled atmosphere ocean)"): |
---|
| 506 | if (rc_flag == "#"): |
---|
| 507 | rc_flag = "o#" |
---|
| 508 | else: |
---|
| 509 | rc_flag = "of" |
---|
| 510 | |
---|
| 511 | param[0] = "%s d3%s" % (param[0],rc_flag) |
---|
| 512 | |
---|
| 513 | if (status_ts == 2): |
---|
| 514 | param[0] = "%s ts%s" % (param[0],rc_flag) |
---|
| 515 | |
---|
| 516 | if (status_pr == 2): |
---|
| 517 | param[0] = "%s pr%s" % (param[0],rc_flag) |
---|
| 518 | |
---|
| 519 | if (status_xy == 2): |
---|
| 520 | param[0] = "%s xy%s" % (param[0],rc_flag) |
---|
| 521 | |
---|
| 522 | if (status_xz == 2): |
---|
| 523 | param[0] = "%s xz%s" % (param[0],rc_flag) |
---|
| 524 | |
---|
| 525 | if (status_yz == 2): |
---|
| 526 | param[0] = "%s yz%s" % (param[0],rc_flag) |
---|
| 527 | |
---|
| 528 | if (status_3d == 2): |
---|
| 529 | param[0] = "%s 3d%s" % (param[0],rc_flag) |
---|
| 530 | |
---|
| 531 | if (status_ma == 2): |
---|
| 532 | param[0] = "%s ma%s" % (param[0],rc_flag) |
---|
| 533 | |
---|
| 534 | if (status_sp == 2): |
---|
| 535 | param[0] = "%s sp%s" % (param[0],rc_flag) |
---|
| 536 | |
---|
| 537 | if (status_prt == 2): |
---|
| 538 | param[0] = "%s prt%s" % (param[0],rc_flag) |
---|
| 539 | |
---|
| 540 | if (status_pts == 2): |
---|
| 541 | param[0] = "%s pts%s" % (param[0],rc_flag) |
---|
| 542 | |
---|
| 543 | status_restarts = self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").checkState() |
---|
| 544 | |
---|
| 545 | if (status_restarts == 2): |
---|
| 546 | param[0]="%s restart" % (param[0]) |
---|
| 547 | |
---|
[2477] | 548 | # Check if _p3dr file is available, otherwise notice user |
---|
[2413] | 549 | if (status_restarts == 2): |
---|
| 550 | jobname = str(self.group_job.findChild(QtGui.QLineEdit, "line_jobname").text())[len(version_path)+len("/JOBS/"):] |
---|
[2477] | 551 | restartfile = "%s/JOBS/%s/INPUT/%s_p3dr" % (version_path,jobname,jobname) |
---|
[2413] | 552 | |
---|
| 553 | if (os.path.exists(restartfile) == True): |
---|
| 554 | self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("") |
---|
| 555 | |
---|
| 556 | else: |
---|
[2477] | 557 | self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dr file found!</font>") |
---|
[2413] | 558 | |
---|
| 559 | else: |
---|
| 560 | self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("") |
---|
| 561 | |
---|
| 562 | status_cycfill = self.group_execution.findChild(QtGui.QCheckBox,"check_cycfill").checkState() |
---|
| 563 | |
---|
| 564 | if (status_cycfill == 2): |
---|
| 565 | param[0]="%s cycfill" % (param[0]) |
---|
| 566 | |
---|
| 567 | param[0]="%s\"" % (param[0]) |
---|
| 568 | |
---|
| 569 | if ( fwt_str == "remove"): |
---|
| 570 | self.delete_commandline(id_str) |
---|
| 571 | return 1 |
---|
| 572 | |
---|
| 573 | else: |
---|
| 574 | self.button_start.setEnabled(True) |
---|
| 575 | self.action_save.setEnabled(True) |
---|
| 576 | |
---|
| 577 | # Change in any other parameter |
---|
| 578 | else: |
---|
| 579 | if ( fwt_str != ""): |
---|
| 580 | param[0] = "\"%s\"" % (fwt_str) |
---|
| 581 | |
---|
| 582 | else: |
---|
| 583 | self.delete_commandline(id_str) |
---|
| 584 | return 1 |
---|
| 585 | |
---|
| 586 | # Join the new palmrunline |
---|
| 587 | splitline[1]= " -".join(param) |
---|
| 588 | |
---|
| 589 | |
---|
| 590 | s = " -%s " % (id_str) |
---|
| 591 | newpalmrunline = s.join(splitline) |
---|
| 592 | |
---|
| 593 | # Pr the new palmrunline to mainwindow |
---|
| 594 | newpalmrunline = newpalmrunline.replace(" "," ") |
---|
| 595 | self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(newpalmrunline) |
---|
| 596 | |
---|
| 597 | # change lineinput depending on sender |
---|
| 598 | ################################################################################### |
---|
| 599 | def change_lineinput(self): |
---|
| 600 | if ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit, "line_host") ): |
---|
| 601 | tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_host").text() |
---|
| 602 | self.change_commandline("h",tmptext) |
---|
| 603 | |
---|
| 604 | elif ( self.sender() == self.group_job.findChild(QtGui.QLineEdit, "line_jobname") ): |
---|
| 605 | tmptext = self.group_job.findChild(QtGui.QLineEdit,"line_jobname").text() |
---|
| 606 | self.change_commandline("d",tmptext) |
---|
| 607 | |
---|
| 608 | elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_q")): |
---|
| 609 | tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_q").text() |
---|
| 610 | self.change_commandline("q",tmptext) |
---|
| 611 | |
---|
| 612 | elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_account")): |
---|
| 613 | tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_account").text() |
---|
[2480] | 614 | self.change_commandline("A",tmptext) |
---|
[2413] | 615 | |
---|
| 616 | elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_pe")): |
---|
| 617 | tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_pe").text() |
---|
| 618 | self.change_commandline("X",tmptext) |
---|
| 619 | |
---|
| 620 | elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_tpn")): |
---|
| 621 | tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_tpn").text() |
---|
| 622 | self.change_commandline("T",tmptext) |
---|
| 623 | |
---|
| 624 | elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_time")): |
---|
| 625 | tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_time").text() |
---|
| 626 | self.change_commandline("t",tmptext) |
---|
| 627 | |
---|
| 628 | elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_M")): |
---|
| 629 | tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_M").text() |
---|
| 630 | self.change_commandline("M",tmptext) |
---|
| 631 | |
---|
| 632 | elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_m")): |
---|
| 633 | tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_m").text() |
---|
| 634 | self.change_commandline("m",tmptext) |
---|
| 635 | |
---|
| 636 | elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_D")): |
---|
| 637 | tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_D").text() |
---|
| 638 | self.change_commandline("D",tmptext) |
---|
| 639 | |
---|
| 640 | elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_c")): |
---|
| 641 | tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_c").text() |
---|
| 642 | if ( tmptext == ".palmgui.config"): |
---|
| 643 | tmptext = "" |
---|
| 644 | self.change_commandline("c",tmptext) |
---|
| 645 | |
---|
| 646 | elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_s")): |
---|
| 647 | tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_s").text() |
---|
| 648 | self.change_commandline("s",tmptext) |
---|
| 649 | |
---|
| 650 | elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_w")): |
---|
| 651 | tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_w").text() |
---|
| 652 | self.change_commandline("w",tmptext) |
---|
| 653 | |
---|
| 654 | elif ( self.sender() == self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos") or |
---|
| 655 | self.sender() == self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean")): |
---|
| 656 | t1 = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").text() |
---|
| 657 | t2 = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").text() |
---|
| 658 | tmptext = "%s %s" % (t1,t2) |
---|
| 659 | |
---|
| 660 | self.change_commandline("Y",tmptext) |
---|
| 661 | |
---|
| 662 | # try catch sowas in der art |
---|
| 663 | pe1 = 0 |
---|
| 664 | pe2 = 0 |
---|
| 665 | |
---|
| 666 | try: |
---|
| 667 | pe1 = int(t1) |
---|
| 668 | except ValueError: |
---|
| 669 | pass |
---|
| 670 | |
---|
| 671 | try: |
---|
| 672 | pe2 = int(t2) |
---|
| 673 | except ValueError: |
---|
| 674 | pass |
---|
| 675 | |
---|
| 676 | PE_total = pe1+pe2 |
---|
| 677 | self.group_execution.findChild(QtGui.QLineEdit,"line_pe").setText(str(PE_total)) |
---|
| 678 | self.change_commandline("X",str(PE_total)) |
---|
| 679 | |
---|
| 680 | # deletes parameter from commandline |
---|
| 681 | ##################################################################################### |
---|
| 682 | def delete_commandline(self, id_str): |
---|
| 683 | # Read palmrunline |
---|
| 684 | commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline") |
---|
| 685 | palmrunline = str(commandline.text()) |
---|
| 686 | s = " -%s" % (id_str) |
---|
| 687 | splitline = filter(None,palmrunline.split(s)) |
---|
| 688 | |
---|
| 689 | if ( len(splitline) == 1): |
---|
| 690 | return 1 |
---|
| 691 | else: |
---|
| 692 | param = splitline[1].split("-") |
---|
| 693 | param[0] = "" |
---|
| 694 | splitline[1]= " -".join(param) |
---|
| 695 | newpalmrunline = "".join(splitline) |
---|
| 696 | newpalmrunline = newpalmrunline.replace(" "," ") |
---|
| 697 | |
---|
| 698 | # Print new palmrunline to screen |
---|
| 699 | commandline.setText(newpalmrunline) |
---|
| 700 | |
---|
| 701 | # controls flags |
---|
| 702 | ################################################################################### |
---|
| 703 | def check_flags(self): |
---|
| 704 | status = self.group_execution.findChild(QtGui.QCheckBox,"check_delete_tmp_files" ).checkState() |
---|
| 705 | if (status == 2): |
---|
| 706 | self.activate_flag("B") |
---|
| 707 | else: |
---|
| 708 | self.deactivate_flag("B") |
---|
| 709 | |
---|
| 710 | status = self.group_execution.findChild(QtGui.QCheckBox,"check_verbose" ).checkState() |
---|
| 711 | if (status == 2): |
---|
| 712 | self.activate_flag("v") |
---|
| 713 | else: |
---|
| 714 | self.deactivate_flag("v") |
---|
| 715 | |
---|
| 716 | status = self.group_advanced.findChild(QtGui.QCheckBox,"check_b" ).checkState() |
---|
| 717 | if (status == 2): |
---|
| 718 | self.activate_flag("b") |
---|
| 719 | else: |
---|
| 720 | self.deactivate_flag("b") |
---|
| 721 | |
---|
| 722 | status = self.group_advanced.findChild(QtGui.QCheckBox,"check_F" ).checkState() |
---|
| 723 | if (status == 2): |
---|
| 724 | self.activate_flag("F") |
---|
| 725 | else: |
---|
| 726 | self.deactivate_flag("F") |
---|
| 727 | |
---|
| 728 | status = self.group_advanced.findChild(QtGui.QCheckBox,"check_I" ).checkState() |
---|
| 729 | if (status == 2): |
---|
| 730 | self.activate_flag("I") |
---|
| 731 | else: |
---|
| 732 | self.deactivate_flag("I") |
---|
| 733 | |
---|
| 734 | status = self.group_advanced.findChild(QtGui.QCheckBox,"check_k" ).checkState() |
---|
| 735 | if (status == 2): |
---|
| 736 | self.activate_flag("k") |
---|
| 737 | else: |
---|
| 738 | self.deactivate_flag("k") |
---|
| 739 | |
---|
| 740 | status = self.group_advanced.findChild(QtGui.QCheckBox,"check_O" ).checkState() |
---|
| 741 | if (status == 2): |
---|
| 742 | self.activate_flag("O") |
---|
| 743 | else: |
---|
| 744 | self.deactivate_flag("O") |
---|
| 745 | |
---|
| 746 | status = self.group_advanced.findChild(QtGui.QCheckBox,"check_x" ).checkState() |
---|
| 747 | if (status == 2): |
---|
| 748 | self.activate_flag("x") |
---|
| 749 | else: |
---|
| 750 | self.deactivate_flag("x") |
---|
| 751 | |
---|
| 752 | status = self.group_advanced.findChild(QtGui.QCheckBox,"check_Z" ).checkState() |
---|
| 753 | if (status == 2): |
---|
| 754 | self.activate_flag("Z") |
---|
| 755 | else: |
---|
| 756 | self.deactivate_flag("Z") |
---|
| 757 | |
---|
| 758 | # changes flag to parameter |
---|
| 759 | ################################################################################## |
---|
| 760 | def activate_flag(self, id_str): |
---|
| 761 | commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline") |
---|
| 762 | palmrunline = str(commandline.text()) |
---|
| 763 | s = " -%s" % (id_str) |
---|
| 764 | splitline = filter(None,palmrunline.split(s)) |
---|
| 765 | |
---|
| 766 | if ( len(splitline) == 1): |
---|
| 767 | splitline.append("") |
---|
| 768 | s = " -%s" % (id_str) |
---|
| 769 | newpalmrunline = s.join(splitline) |
---|
| 770 | newpalmrunline = newpalmrunline.replace(" "," ") |
---|
| 771 | commandline.setText(newpalmrunline) |
---|
| 772 | |
---|
| 773 | # deletes flag in commandline |
---|
| 774 | #################################################################################### |
---|
| 775 | def deactivate_flag(self, id_str): |
---|
| 776 | commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline") |
---|
| 777 | palmrunline = str(commandline.text()) |
---|
| 778 | s = " -%s" % (id_str) |
---|
| 779 | splitline = filter(None,palmrunline.split(s)) |
---|
| 780 | |
---|
| 781 | newpalmrunline = "".join(splitline) |
---|
| 782 | newpalmrunline = newpalmrunline.replace(" "," ") |
---|
| 783 | commandline.setText(newpalmrunline) |
---|
| 784 | |
---|
| 785 | # Clears window |
---|
| 786 | ################################################################################# |
---|
| 787 | def reset_window(self): |
---|
| 788 | self.setupUi(self) |
---|
| 789 | self.tabWidget.setCurrentIndex(0) |
---|
[2477] | 790 | self.recent_jobs(50) |
---|
[2413] | 791 | |
---|
| 792 | # Safes current commandline and user Parameters to .sav file |
---|
| 793 | ################################################################################# |
---|
| 794 | def save_to_file(self): |
---|
| 795 | user_string = self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text() |
---|
| 796 | cmd_string = self.groupBox.findChild(QtGui.QLineEdit,"commandline").text() |
---|
| 797 | |
---|
| 798 | string_to_file = cmd_string |
---|
| 799 | if (user_string != ""): |
---|
| 800 | string_to_file = "%s%s" % (string_to_file,user_string) |
---|
| 801 | |
---|
| 802 | #filename = QtGui.QInputDialog.getText(self, "Save File naming Dialog", "Insert filename", QtGui.QLineEdit.Normal) |
---|
| 803 | filename = str(QtGui.QFileDialog.getSaveFileName(self, "Save File","filename.sav")) |
---|
| 804 | extension = ".sav" |
---|
| 805 | filename = "%s%s" % (filename, "") |
---|
| 806 | tmstamp = strftime("%Y/%m/%d %H:%M") |
---|
| 807 | |
---|
| 808 | file = open(filename,"w") |
---|
| 809 | s = "%s %s" % (tmstamp, string_to_file) |
---|
| 810 | file.write(s) |
---|
| 811 | file.close() |
---|
| 812 | |
---|
| 813 | # Safes current commandline and user parameters to default file |
---|
| 814 | ################################################################################ |
---|
| 815 | def save_default(self): |
---|
| 816 | user_string = self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text() |
---|
| 817 | cmd_string = self.groupBox.findChild(QtGui.QLineEdit,"commandline").text() |
---|
| 818 | |
---|
| 819 | string_to_file = cmd_string |
---|
| 820 | if (user_string != ""): |
---|
| 821 | string_to_file = "%s%s" % (string_to_file,user_string) |
---|
| 822 | |
---|
| 823 | filename ="%s/.palmgui.default" % (version_path) |
---|
| 824 | tmstamp = strftime("%Y/%m/%d %H:%M") |
---|
| 825 | |
---|
| 826 | file = open(filename,"w") |
---|
| 827 | s = "%s %s" % (tmstamp, string_to_file) |
---|
| 828 | file.write(s) |
---|
| 829 | file.close() |
---|
| 830 | |
---|
| 831 | # Execute command which starts jobmanager (start palm_jm) |
---|
| 832 | ####################################################### |
---|
| 833 | def start_jobmanager(self): |
---|
| 834 | subprocess.Popen(["nohup","palm_jm",">>","/dev/null", "2>&1","&"]) |
---|
| 835 | |
---|
| 836 | # Executes command which starts watchdog (start palm_wd) |
---|
| 837 | ######################################################## |
---|
| 838 | def start_watchdog(self): |
---|
| 839 | subprocess.Popen(["nohup","palm_wd",">>","/dev/null", "2>&1","&"]) |
---|
| 840 | |
---|
| 841 | # Opens "help" dialog |
---|
| 842 | ################################# |
---|
| 843 | def help(self): |
---|
| 844 | dialog = HelpDialog() |
---|
| 845 | dialog.exec_() |
---|
| 846 | |
---|
| 847 | # Opens "about" dialog |
---|
| 848 | ################################## |
---|
| 849 | def about_gui(self): |
---|
| 850 | dialog = AboutDialog() |
---|
| 851 | dialog.exec_() |
---|
| 852 | |
---|
| 853 | # commandline to buttons etc |
---|
| 854 | ############################## |
---|
| 855 | def setup_gui(self, palmrun_str): |
---|
[2484] | 856 | |
---|
| 857 | self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png")) |
---|
| 858 | |
---|
[2413] | 859 | # Some initial settings |
---|
| 860 | user = "" |
---|
| 861 | coupled_run = False |
---|
| 862 | ocean_run = False |
---|
| 863 | nojob = False |
---|
| 864 | |
---|
| 865 | #Split parameters in palmrunline |
---|
| 866 | splitline = palmrun_str.split(" -") |
---|
| 867 | |
---|
| 868 | if ( splitline[0] != "palmrun"): |
---|
| 869 | return 1 |
---|
| 870 | |
---|
| 871 | else: |
---|
| 872 | self.group_job.setEnabled(True) |
---|
| 873 | |
---|
| 874 | # Loop for all parameters in palmrunline |
---|
| 875 | i = len(splitline)-1 |
---|
| 876 | while i >= 1: |
---|
| 877 | |
---|
| 878 | # Determine parameter |
---|
| 879 | splitparameter = splitline[i].split(" ") |
---|
| 880 | |
---|
| 881 | parameter = splitparameter[0] |
---|
| 882 | splitparameter.pop(0) |
---|
| 883 | options = " ".join(splitparameter) |
---|
| 884 | options = options.replace("\"","") |
---|
| 885 | |
---|
| 886 | # Check for suitable switch |
---|
| 887 | if ( parameter == "d"): |
---|
| 888 | |
---|
| 889 | if ( options != ""): |
---|
| 890 | self.group_job.findChild(QtGui.QLineEdit,"line_jobname").setText(options) |
---|
| 891 | nojob = False |
---|
| 892 | |
---|
| 893 | else: |
---|
| 894 | nojob = True |
---|
| 895 | |
---|
| 896 | elif ( parameter == "h"): |
---|
| 897 | self.group_execution.findChild(QtGui.QLineEdit,"line_host").setText(options) |
---|
| 898 | |
---|
| 899 | elif ( parameter == "q"): |
---|
| 900 | self.group_execution.findChild(QtGui.QLineEdit,"line_q").setText(options) |
---|
| 901 | |
---|
[2480] | 902 | elif ( parameter == "A"): |
---|
[2413] | 903 | self.group_execution.findChild(QtGui.QLineEdit,"line_account").setText(options) |
---|
| 904 | |
---|
| 905 | elif ( parameter == "X"): |
---|
| 906 | self.group_execution.findChild(QtGui.QLineEdit,"line_pe").setText(options) |
---|
| 907 | |
---|
| 908 | elif ( parameter == "T"): |
---|
| 909 | self.group_execution.findChild(QtGui.QLineEdit,"line_tpn").setText(options) |
---|
| 910 | |
---|
| 911 | elif ( parameter == "t"): |
---|
| 912 | self.group_execution.findChild(QtGui.QLineEdit,"line_time").setText(options) |
---|
| 913 | |
---|
| 914 | elif ( parameter == "B"): |
---|
| 915 | self.group_execution.findChild(QtGui.QCheckBox,"check_delete_tmp_files").setChecked(True) |
---|
| 916 | |
---|
| 917 | elif ( parameter == "v"): |
---|
| 918 | self.group_execution.findChild(QtGui.QCheckBox,"check_verbose").setChecked(True) |
---|
| 919 | |
---|
| 920 | elif ( parameter == "b"): |
---|
| 921 | self.group_advanced.findChild(QtGui.QCheckBox,"check_b").setChecked(True) |
---|
| 922 | |
---|
| 923 | elif ( parameter == "F"): |
---|
| 924 | self.group_advanced.findChild(QtGui.QCheckBox,"check_F").setChecked(True) |
---|
| 925 | |
---|
| 926 | elif ( parameter == "I"): |
---|
| 927 | self.group_advanced.findChild(QtGui.QCheckBox,"check_I").setChecked(True) |
---|
| 928 | |
---|
| 929 | elif ( parameter == "k"): |
---|
| 930 | self.group_advanced.findChild(QtGui.QCheckBox,"check_k").setChecked(True) |
---|
| 931 | |
---|
| 932 | elif ( parameter == "O"): |
---|
| 933 | self.group_advanced.findChild(QtGui.QCheckBox,"check_O").setChecked(True) |
---|
| 934 | |
---|
| 935 | elif ( parameter == "x"): |
---|
| 936 | self.group_advanced.findChild(QtGui.QCheckBox,"check_x").setChecked(True) |
---|
| 937 | |
---|
| 938 | elif ( parameter == "Z"): |
---|
| 939 | self.group_advanced.findChild(QtGui.QCheckBox,"check_Z").setChecked(True) |
---|
| 940 | |
---|
| 941 | elif ( parameter == "m"): |
---|
| 942 | self.group_advanced.findChild(QtGui.QLineEdit,"line_m").setText(options) |
---|
| 943 | |
---|
| 944 | elif ( parameter == "M"): |
---|
| 945 | self.group_advanced.findChild(QtGui.QLineEdit,"line_M").setText(options) |
---|
| 946 | |
---|
| 947 | elif ( parameter == "D"): |
---|
| 948 | self.group_advanced.findChild(QtGui.QLineEdit,"line_D").setText(options) |
---|
| 949 | |
---|
| 950 | elif ( parameter == "c"): |
---|
| 951 | self.group_advanced.findChild(QtGui.QLineEdit,"line_c").setText(options) |
---|
| 952 | |
---|
| 953 | elif ( parameter == "s"): |
---|
| 954 | self.group_advanced.findChild(QtGui.QLineEdit,"line_s").setText(options) |
---|
| 955 | |
---|
| 956 | elif ( parameter == "w"): |
---|
| 957 | self.group_advanced.findChild(QtGui.QLineEdit,"line_w").setText(options) |
---|
| 958 | |
---|
| 959 | |
---|
| 960 | # Determine settings for coupled restart runs |
---|
| 961 | elif ( parameter == "Y"): |
---|
| 962 | optionssplit = options.split(" ") |
---|
| 963 | |
---|
| 964 | group_coupled = self.group_execution.findChild(QtGui.QGroupBox,"group_coupled") |
---|
| 965 | group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setEnabled(True) |
---|
| 966 | group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setEnabled(True) |
---|
| 967 | group_coupled.findChild(QtGui.QLabel,"label_coupled1").setEnabled(True) |
---|
| 968 | group_coupled.findChild(QtGui.QLabel,"label_coupled2").setEnabled(True) |
---|
| 969 | group_coupled.findChild(QtGui.QLabel,"label_coupled3").setEnabled(True) |
---|
| 970 | group_coupled.findChild(QtGui.QLabel,"label_coupling").setEnabled(True) |
---|
| 971 | |
---|
| 972 | if (optionssplit.count() == 2): |
---|
| 973 | group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setEnabled(optionssplit[0]) |
---|
| 974 | group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setEnabled(optionssplit[1]) |
---|
| 975 | |
---|
| 976 | else: |
---|
| 977 | group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setText("") |
---|
| 978 | group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setText("") |
---|
| 979 | |
---|
| 980 | |
---|
| 981 | coupled_run = True |
---|
| 982 | |
---|
| 983 | elif ( parameter == "y"): |
---|
| 984 | self.group_job.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(3) |
---|
| 985 | |
---|
| 986 | |
---|
| 987 | # Determine settings for the run control list |
---|
| 988 | elif ( parameter == "a"): |
---|
| 989 | |
---|
| 990 | optionssplit = options.split(" ") |
---|
| 991 | |
---|
| 992 | options_2 = None |
---|
| 993 | options_all = None |
---|
| 994 | |
---|
| 995 | j = 0 |
---|
| 996 | while j < len(optionssplit): |
---|
| 997 | |
---|
| 998 | options_all = optionssplit[j] |
---|
| 999 | options_2 = optionssplit[j][:2] |
---|
[2477] | 1000 | |
---|
[2413] | 1001 | if (options_2 == "ts"): |
---|
| 1002 | self.group_runcontrol.findChild(QtGui.QCheckBox,"check_ts").setChecked(True) |
---|
| 1003 | |
---|
| 1004 | if (options_2 == "pr" and options_all[:3] is not "prt"): |
---|
| 1005 | self.group_runcontrol.findChild(QtGui.QCheckBox,"check_pr").setChecked(True) |
---|
| 1006 | |
---|
| 1007 | if (options_2 == "xy"): |
---|
| 1008 | self.group_runcontrol.findChild(QtGui.QCheckBox,"check_xy").setChecked(True) |
---|
| 1009 | |
---|
| 1010 | if (options_2 == "xz"): |
---|
| 1011 | self.group_runcontrol.findChild(QtGui.QCheckBox,"check_xz").setChecked(True) |
---|
| 1012 | |
---|
| 1013 | if (options_2 == "yz"): |
---|
| 1014 | self.group_runcontrol.findChild(QtGui.QCheckBox,"check_yz").setChecked(True) |
---|
| 1015 | |
---|
| 1016 | if (options_2 == "3d"): |
---|
| 1017 | self.group_runcontrol.findChild(QtGui.QCheckBox,"check_3d").setChecked(True) |
---|
| 1018 | |
---|
| 1019 | if (options_2 == "ma"): |
---|
| 1020 | self.group_runcontrol.findChild(QtGui.QCheckBox,"check_ma").setChecked(True) |
---|
| 1021 | |
---|
| 1022 | if (options_2 == "sp"): |
---|
| 1023 | self.group_runcontrol.findChild(QtGui.QCheckBox,"check_sp").setChecked(True) |
---|
| 1024 | |
---|
| 1025 | if (options_all[:3] == "prt"): |
---|
| 1026 | self.group_runcontrol.findChild(QtGui.QCheckBox,"check_prt").setChecked(True) |
---|
| 1027 | |
---|
| 1028 | if (options_all[:3] == "pts"): |
---|
| 1029 | self.group_runcontrol.findChild(QtGui.QCheckBox,"check_pts").setChecked(True) |
---|
| 1030 | |
---|
[2477] | 1031 | if (options_2 == "d3"): |
---|
| 1032 | if (options_all[:3][-1] == "#"): |
---|
[2413] | 1033 | self.group_job.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(0) |
---|
[2477] | 1034 | elif (options_all[:3][-1] == "r"): |
---|
[2413] | 1035 | self.group_job.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(1) |
---|
| 1036 | |
---|
[2477] | 1037 | elif (options_all[:3][-1] == "o"): |
---|
[2413] | 1038 | ocean_run = True |
---|
| 1039 | |
---|
| 1040 | if (options_all == "restart"): |
---|
| 1041 | self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").setChecked(True) |
---|
| 1042 | # Check if _pdf file is available, otherwise notice user |
---|
| 1043 | jobname = str(self.group_job.findChild(QtGui.QLineEdit,"line_jobname").text())[len(version_path)+len("/JOBS/"):] |
---|
| 1044 | |
---|
[2477] | 1045 | restartfile = "%sJOBS/%s/INPUT/%s_p3dr" % (version_path,jobname,jobname) |
---|
[2413] | 1046 | if (os.path.exists(restartfile) == True): |
---|
| 1047 | self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("") |
---|
| 1048 | |
---|
| 1049 | else: |
---|
[2477] | 1050 | self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dr file \found!</font>") |
---|
[2413] | 1051 | j = j+1 |
---|
| 1052 | |
---|
| 1053 | # All unknown parameters are set as extra user parameters |
---|
| 1054 | else: |
---|
| 1055 | print parameter |
---|
| 1056 | user = "%s-%s \"%s\" " % (user,parameter,options) |
---|
| 1057 | splitline.removeAt(i) |
---|
| 1058 | |
---|
| 1059 | i = i-1 |
---|
| 1060 | # Change drop box state in case of ocean precursor or coupled restart runs |
---|
| 1061 | if ( ocean_run == True ): |
---|
| 1062 | if ( coupled_run == True ): |
---|
| 1063 | self.group_job.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(4) |
---|
| 1064 | |
---|
| 1065 | else: |
---|
| 1066 | self.group_job.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(3) |
---|
| 1067 | |
---|
| 1068 | if ( user != ""): |
---|
| 1069 | self.group_advanced.findChild(QtGui.QLineEdit,"line_user").setText(user) |
---|
| 1070 | |
---|
| 1071 | # Join palmrunline and post it to mainwindow |
---|
| 1072 | palmrunline = " -".join(splitline) |
---|
| 1073 | self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) |
---|
| 1074 | |
---|
| 1075 | # Disable mainwindow if no job was found, otherwise enable |
---|
| 1076 | if ( nojob == True ): |
---|
| 1077 | self.group_execution.setEnabled(False) |
---|
| 1078 | self.group_runcontrol.setEnabled(False) |
---|
| 1079 | self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False) |
---|
| 1080 | self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(False) |
---|
| 1081 | self.group_job.findChild(QtGui.QComboBox, "drop_job").setEnabled(False) |
---|
| 1082 | self.group_advanced.setEnabled(False) |
---|
| 1083 | self.check_advanced.setEnabled(False) |
---|
| 1084 | |
---|
| 1085 | else: |
---|
| 1086 | self.group_execution.setEnabled(True) |
---|
| 1087 | self.group_runcontrol.setEnabled(True) |
---|
| 1088 | self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True) |
---|
| 1089 | self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(True) |
---|
| 1090 | self.group_job.findChild(QtGui.QComboBox, "drop_job").setEnabled(True) |
---|
| 1091 | self.group_advanced.setEnabled(True) |
---|
| 1092 | |
---|
| 1093 | self.tabWidget.setCurrentIndex(0) |
---|
| 1094 | |
---|
| 1095 | # open saved commandline |
---|
| 1096 | ################################## |
---|
| 1097 | def open_from_file(self): |
---|
| 1098 | |
---|
| 1099 | # Select filename and open it |
---|
| 1100 | filename = QtGui.QFileDialog.getOpenFileName(self, "Open File","Save files (*.sav)") |
---|
| 1101 | |
---|
| 1102 | if ( filename != ""): |
---|
| 1103 | file = open(filename, "r") |
---|
| 1104 | |
---|
| 1105 | if ( file is not None ): |
---|
| 1106 | # File opened successfully |
---|
| 1107 | palmrunline = file.read() |
---|
| 1108 | file.close() |
---|
| 1109 | |
---|
| 1110 | # In case a palmrunline was found, load it to mainwindow |
---|
| 1111 | if ( palmrunline != ""): |
---|
| 1112 | palmrunline = palmrunline[17:] |
---|
| 1113 | self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) |
---|
| 1114 | self.setup_gui(palmrunline) |
---|
| 1115 | |
---|
| 1116 | # open saved commandline |
---|
| 1117 | ################################## |
---|
| 1118 | def open_last(self): |
---|
| 1119 | # Select filename and open it |
---|
| 1120 | filename = "%s/.palm.history" % (version_path) |
---|
| 1121 | |
---|
| 1122 | if os.path.exists(filename): |
---|
| 1123 | pass |
---|
| 1124 | else: |
---|
| 1125 | return |
---|
| 1126 | |
---|
| 1127 | file = open(filename, "r") |
---|
| 1128 | if ( file is not None ): |
---|
| 1129 | # File opened successfully |
---|
| 1130 | lines = file.readlines() |
---|
| 1131 | palmrunline = lines[len(lines)-1] |
---|
| 1132 | palmrunline = palmrunline[:len(palmrunline)-1] |
---|
| 1133 | file.close() |
---|
| 1134 | |
---|
| 1135 | # In case a palmrunline was found, load it to mainwindow |
---|
| 1136 | if ( palmrunline != ""): |
---|
| 1137 | palmrunline = palmrunline[17:len(palmrunline)] |
---|
| 1138 | self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) |
---|
| 1139 | self.setup_gui(palmrunline) |
---|
| 1140 | |
---|
| 1141 | |
---|
| 1142 | if __name__ == "__main__": |
---|
| 1143 | app = QtGui.QApplication(sys.argv) |
---|
| 1144 | window = Mainwindow() |
---|
| 1145 | window.show() |
---|
| 1146 | sys.exit(app.exec_()) |
---|