source: palm/trunk/SCRIPTS/palmrungui.py @ 2479

Last change on this file since 2479 was 2477, checked in by maronga, 7 years ago

bugfix in palmrungui

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