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

Last change on this file since 2421 was 2413, checked in by maronga, 7 years ago

removed mrungui in favor of palmrungui

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