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