source: palm/trunk/SCRIPTS/palmrungui @ 4393

Last change on this file since 4393 was 4393, checked in by maronga, 4 years ago

removed PALM_BIN dependencies in GUI tools

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