source: palm/trunk/SCRIPTS/palmrungui @ 4429

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

bugfix for last commit. fix in .palm.iofiles

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 59.3 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 4428 2020-02-27 11:43:53Z raasch $
27# Bugfix for update button
28#
29# 4427 2020-02-27 11:29:51Z maronga
30# Small fixes and adjustments
31#
32# 4420 2020-02-24 14:13:56Z maronga
33# Bugfix: minor fixes related to start buttons
34#
35# 4411 2020-02-18 14:28:02Z maronga
36# Added new features: individual tag for submitted runs, automatic finding of
37# configuration, start of palmbuild from GUI
38#
39# 4405 2020-02-12 19:11:11Z maronga
40# Major revisions: New layout. Merged with palm job manager (palm_jm).
41# Minor revisions: Misc. bugs fixed.
42#
43# 4394 2020-02-04 21:40:38Z maronga
44# Bugfix: harmonized naming convention of configuration files
45#
46# 4393 2020-02-04 21:24:48Z maronga
47# Removed PALM_BIN dependency and os calls
48#
49# 3487 2018-11-05 07:18:02Z maronga
50# Renamed options -d and -h to -r and -c.
51#
52# 2825 2018-02-20 21:48:27Z maronga
53# Adjusted to work with newest version of palmrun
54#
55# 2718 2018-01-02 08:49:38Z maronga
56# Corrected "Former revisions" section
57#
58# 2696 2017-12-14 17:12:51Z kanani
59# Change in file header (GPL part)
60#
61# 2484 2017-09-20 14:22:42Z maronga
62# Added PALM logo
63#
64# 2480 2017-09-19 06:24:14Z maronga
65# option -A (project account number) added
66#
67# 2477 2017-09-18 08:42:29Z maronga
68# Renamed restart run appendix from "f" to "r". Bugfix for displaying restart runs.>
69# Revised list of recently submitted jobs
70#
71# 2413 2017-09-06 12:48:29Z maronga
72# Renamed to palmrungui and adapted for use with palmrun instead of mrun.
73#
74# 2316 2017-07-20 07:53:42Z maronga
75# Initial revision in python
76#
77#
78#
79# Description:
80# ------------
81# Graphical user interface for the palmrun script.
82# @author Felix Gaschler
83# @author Björn Maronga (maronga@muk.uni-hannover.de)
84#
85# Instructions:
86# -------------
87#
88#------------------------------------------------------------------------------!
89
90import sys
91import subprocess
92from PyQt4 import QtCore, QtGui, uic
93from PyQt4.QtCore import QProcess,pyqtSlot,SIGNAL,SLOT
94from time import strftime
95import os
96import shutil
97
98
99
100# Determine PALM directories
101try: 
102   devnull = open(os.devnull, 'w')     
103   palm_dir = os.getcwd()
104   palm_bin = palm_dir + '/trunk/SCRIPTS'
105   job_dir = palm_dir + '/JOBS'
106   user_dir = palm_dir + '/USER_CODE'
107   with open(palm_bin + '/palmrungui', 'r') as fh:
108      # file found
109      out = None
110except:   
111   print "Error. palmrungui probably called in wrong directory."
112   raise SystemExit
113
114
115palmrunline = ""
116set_list = []
117
118Ui_MainWindow = uic.loadUiType("%s/palmrungui_files/mainwindow.ui" % (palm_bin))[0]
119Ui_helpDialog = uic.loadUiType("%s/palmrungui_files/help.ui" % (palm_bin))[0]
120Ui_aboutDialog = uic.loadUiType("%s/palmrungui_files/about.ui" % (palm_bin))[0]
121
122class HelpDialog(QtGui.QDialog,Ui_helpDialog):
123    def __init__(self, parent=None):
124        super(HelpDialog,self).__init__()
125        self.setupUi(self)
126       
127class AboutDialog(QtGui.QDialog,Ui_aboutDialog):
128    def __init__(self, parent=None):
129        super(AboutDialog,self).__init__()
130        self.setupUi(self)       
131
132class Mainwindow(QtGui.QMainWindow, Ui_MainWindow):
133    def __init__(self, parent=None):
134        super(Mainwindow, self).__init__()
135        self.setupUi(self)
136   
137        self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png"))       
138       
139        self.recent_jobs(50)
140        self.load_jobs()
141
142        # look up configuration files and add to combo box
143       
144        self.group_execution.findChild(QtGui.QComboBox,"combo_configuration").addItem("")
145       
146        for files in os.listdir(palm_dir):
147           if files.startswith(".palm.config"):
148              tmpstring = filter(None,files.split(".palm.config."))[0]
149              self.group_execution.findChild(QtGui.QComboBox,"combo_configuration").addItem(tmpstring)
150
151        commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline")
152        commandline.setText("")
153       
154        self.tabWidget.setCurrentIndex(0) 
155       
156       
157        filename = "%s/.palmrungui.default" % (palm_dir) 
158        if os.path.exists(filename):
159            pass
160        else:
161            return
162       
163        file = open(filename, "r")
164        if ( file is not None ):
165            # File opened successfully
166            palmrunline = file.readline()
167            #if neue zeile zeichen
168            palmrunline = palmrunline[:len(palmrunline)-1]
169            file.close() 
170
171        # In case a palmrunline was found, load it to mainwindow
172        if ( palmrunline != ""):
173            palmrunline = palmrunline[17:] 
174            commandline.setText(palmrunline)
175            self.setup_gui(palmrunline)
176
177
178
179   
180        QtGui.QApplication.processEvents()
181
182
183       
184    # starts xterm with palmrun commandline
185    #######################################
186    def startpalmrun(self):
187        palmrunline = str(self.groupBox.findChild(QtGui.QLineEdit,"commandline").text())
188        userline    = str(self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text())
189       
190        # Check for empty line
191        palmrunline_save = palmrunline
192        if (userline != ""):
193            palmrunline = "%s %s" % (palmrunline,userline)
194        history_line = palmrunline       
195       
196        # Disable the main window
197        self.tabWidget.setEnabled(False)
198        self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False)
199        self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(False)
200        self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("wait...")     
201        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText("Executing palmrun in xterm...")       
202       
203        # Wait until all commands have been executed (ugly) ?
204        #for i in range(0,21):
205        #    qApp->processEvents()       
206       
207        # Start xterm as QProcess
208        palmrun = QProcess()
209        palmrun.setProcessChannelMode(QProcess.MergedChannels) # mergedChannels
210        palmrun.setWorkingDirectory(palm_dir)
211   
212        geomet = self.frameGeometry()
213       
214        posx = geomet.x()+geomet.width()
215        posy = geomet.y()
216     
217        s = " -title \"Executing palmrun...\" -fa \"Monospace\" -fs 11 -geometry \"80x38+%d+%d\" -e \"" % (posx,posy)
218        palmrunline = "%s%s;echo -n '--> Press enter to continue...';read yesno\"</dev/stdin" % (s, palmrunline.replace("\"","\'"))
219       
220        mString = "xterm %s" % (palmrunline)
221        palmrun.start(mString)
222   
223        if( palmrun.waitForStarted() is False ):
224            return
225       
226        # Wait until palmrun has finished or wait for 200 minutes
227        palmrun.waitForFinished(3600000)       
228       
229        # Jobs has been submitted or aborted. Continuing...
230        # Save the palmrun command to history file
231        filename = "%s/.palmrungui.history" % (palm_dir)
232        tmstamp = strftime("%Y/%m/%d %H:%M")
233        tag = str(self.groupBox.findChild(QtGui.QLineEdit,"line_tag").text())
234   
235        file = open(filename,"a")
236        s = "%s %s (%s)\n" % (tmstamp,history_line,tag)
237        file.write(s)
238        file.close()             
239       
240        # Enable main window again
241        self.tabWidget.setEnabled(True)
242        self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True)
243        self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("palmrun") 
244        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline_save)
245        self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
246       
247        # Reload recent jobs
248        self.recent_jobs(50)
249       
250       
251       
252    # starts xterm with palmbuild commandline
253    #######################################
254    def startpalmbuild(self):
255        palmbuildline = 'palmbuild -c ' + str(self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").currentText())
256       
257        palmrunline_save = str(self.groupBox.findChild(QtGui.QLineEdit,"commandline").text())
258       
259        # Disable the main window
260        palmbuildline_save = palmbuildline
261        self.tabWidget.setEnabled(False)
262        self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False)
263        self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(False) 
264        self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("wait...") 
265        self.group_execution.findChild(QtGui.QPushButton,"button_palmbuild").setText("wait...") 
266        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText("Executing palmbuild in xterm...")       
267       
268        # Wait until all commands have been executed (ugly) ?
269        #for i in range(0,21):
270        #    qApp->processEvents()       
271       
272        # Start xterm as QProcess
273        palmbuild = QProcess()
274        palmbuild.setProcessChannelMode(QProcess.MergedChannels) # mergedChannels
275        palmbuild.setWorkingDirectory(palm_dir)
276   
277        geomet = self.frameGeometry()
278       
279        posx = geomet.x()+geomet.width()
280        posy = geomet.y()
281     
282        s = " -title \"Executing palmbuild...\" -fa \"Monospace\" -fs 11 -geometry \"80x38+%d+%d\" -e \"" % (posx,posy)
283        palmbuildline = "%s%s;echo -n '--> Press enter to continue...';read yesno\"</dev/stdin" % (s, palmbuildline.replace("\"","\'"))
284       
285        mString = "xterm %s" % (palmbuildline)
286        palmbuild.start(mString)
287   
288        if( palmbuild.waitForStarted() is False ):
289            return
290       
291        # Wait until palmbuild has finished or wait for 200 minutes
292        palmbuild.waitForFinished(3600000)       
293       
294         
295       
296        # Enable main window again
297        self.tabWidget.setEnabled(True)
298        self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True)
299        self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
300        self.groupBox.findChild(QtGui.QPushButton,"button_start").setText("palmrun") 
301        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline_save)
302        self.group_execution.findChild(QtGui.QPushButton,"button_palmbuild").setText("(re-)build")     
303        # Reload recent jobs
304        self.recent_jobs(50)
305
306    # loads recent jobs
307    ######################################
308    def recent_jobs(self, number):
309        fileDir = "%s/.palmrungui.history" % (palm_dir)
310        if os.path.exists(fileDir):
311            pass
312        else:
313            return
314       
315        file = open(fileDir,"r")
316        history = file.readlines()
317        tmphistory = list()
318        tmptag = list()
319        file.close()
320        j = 0
321
322        list_jobname = self.group_history.findChild(QtGui.QListWidget,"list_jobname")
323        list_jobname.clear()
324
325        # Read history entries and append to recent job list
326        i=len(history)-1
327        count = 0
328        while i>=0 and count<number:
329            timestamp = history[i][:16]
330            listitem = history[i][17:len(history[i])-1]
331            tagitem = listitem
332            matchitems = list_jobname.findItems(listitem, QtCore.Qt.MatchExactly)
333
334            if ( len(matchitems) == 0 ):
335                listitem = filter(None,listitem.split(" -r"))[1]
336                listitem = filter(None,listitem.split(" -"))[0]
337                listitem = listitem.replace(" ","") 
338                list_jobname.addItem(listitem)
339                s = "%s: %s" % (timestamp,listitem)
340                tmphistory.append(s)
341               
342               
343                tagitem = filter(None,tagitem.split(" ("))[1]
344                tagitem = tagitem.replace(")","") 
345                if ( len(tagitem) == 0 ): 
346                   s = "Tag: empty"
347                else:
348                   s = "Tag: %s" % (tagitem)               
349                tmptag.append(s)
350                count = count +1
351
352                j = j+1
353               
354            if ( j == number ):
355                break
356            i = i-1
357           
358        # Send to list
359        list_jobname.clear()
360       
361        i=0
362        while i<len(tmphistory):
363            list_jobname.addItem(tmphistory[i])
364            list_jobname.item(i).setToolTip(tmptag[i])
365            i = i+1
366           
367
368    # Enables coupled settings
369    ###############################
370    def enable_coupled(self):
371        coupledState = self.group_execution.findChild(QtGui.QComboBox, "drop_job").currentText()
372        group = self.group_execution.findChild(QtGui.QGroupBox, "group_coupled")
373       
374        if (coupledState == "Restart run (coupled atmosphere ocean)" or coupledState == "Initial run (coupled atmosphere ocean)"):
375            self.group_coupled.setEnabled(True)
376        else: 
377            self.group_coupled.setEnabled(False)
378           
379
380    # select a job via click from list
381    #################################
382    def choosejob_list(self):
383        #  Get selected item from list
384        list_jobname = self.group_history.findChild(QtGui.QListWidget,"list_jobname")
385        filename = str(list_jobname.currentItem().text())
386           
387        timestamp = filename[:16]
388        jobname = filename[18:]
389               
390        itemint = list_jobname.currentRow()
391
392        # Reload list
393        self.recent_jobs(50)
394        self.load_jobs()
395   
396        # Set selected item to jobname
397        list_jobname.item(itemint).setSelected(True)
398   
399        # Set selected item to jobname in "available jobs" list
400        item2int = self.list_jobs.findItems(jobname,QtCore.Qt.MatchCaseSensitive)
401       
402        if ( item2int != [] ):
403           self.list_jobs.setCurrentItem(item2int[0])
404        self.update_input()
405           
406   
407        fileDir = "%s/.palmrungui.history" % (palm_dir)
408        file = open(fileDir,"r")
409        history = file.readlines()
410        tmphistory = list()
411        file.close()       
412   
413        i = len(history)
414        while i>=1:
415            listitem = history[i-1][17:len(history[i-1])-1]
416            listitem = filter(None,listitem.split(" -r"))[1]
417            listitem = filter(None,listitem.split(" -"))[0]
418            listitem = listitem.replace(" ","") 
419
420            # Select command line with correct timestamp and jobname
421            if (history[i-1][:16] == timestamp and listitem == jobname):
422                palmrunline = history[i-1]
423                palmrunline = palmrunline[17:]
424                palmrunline = palmrunline[:len(palmrunline)-1]
425                palmrunline = filter(None,palmrunline.split("("))[0]
426                self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline)
427               
428             
429                tag = history[i-1].split('\n')[0]
430                tag = filter(None,tag.split("("))[1]
431                tag = tag.replace(")","")
432
433                self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setText(tag)
434                self.setup_gui(palmrunline)
435                self.list_jobname.item(itemint).setSelected(True)   
436               
437                return
438            i = i-1
439               
440    # Change run identifer (initial, restart, coupled...)
441    ######################################################
442    def change_rc_list(self):
443        drop_job = self.group_execution.findChild(QtGui.QComboBox,"drop_job").currentText()   
444        self.change_commandline("a","")
445   
446        # Enable PE distribution for atmosphere/ocean
447        if ( drop_job == "Restart run (coupled atmosphere ocean)" or drop_job == "Initial run (coupled atmosphere ocean)"):
448            drop_atmos = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").text() 
449            drop_ocean = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").text() 
450            s = "%s %s" % (drop_atmos,drop_ocean)
451            self.change_commandline("Y",s)
452   
453   
454        if ( drop_job == "Restart run" or drop_job == "Restart run (coupled atmosphere ocean)"):
455           self.change_commandline("r","")
456
457        # Check of ocean runs
458        else:
459            self.delete_commandline("Y")
460            if (drop_job == "Precursor run (ocean)"):
461                self.activate_flag("y")
462            else:
463                self.deactivate_flag("y")
464           
465    # changes commandline depending on parameters
466    ##########################################################     
467    def change_commandline(self, id_str, fwt_str):
468        fwt_str = str(fwt_str) 
469        initialize = False
470        palmrunline = str(self.groupBox.findChild(QtGui.QLineEdit,"commandline").text())   
471        s = " -%s " % (id_str)
472        splitline = filter(None,palmrunline.split(s))
473
474        if ( len(splitline) == 0 ):
475                splitline.append("palmrun")
476                splitline.append(" ")
477                initialize = True
478
479        elif ( len(splitline) == 1 ):
480            splitline.append(" ")
481       
482        param = splitline[1].split("-")
483   
484        # Change in parameter "r" (jobname)
485        if (id_str == "r"):
486            filename = str(self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").text())
487            s = filename.split("JOBS/") 
488            param[0] = s[len(s)-1]
489     
490            if ( initialize == True ):#and self.group_runcontrol.isEnabled() == True ):
491                self.group_execution.setEnabled(True)
492                self.group_execution.findChild(QtGui.QComboBox,"drop_job").setEnabled(True)
493                self.group_advanced.setEnabled(True)
494                self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True) 
495                self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(True)
496                self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
497           
498            elif ( param[0] == ""):           
499                self.group_execution.setEnabled(False)
500                self.group_execution.findChild(QtGui.QComboBox,"drop_job").setEnabled(False)
501                self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False) 
502                self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(False)
503                self.group_advanced.setEnabled(False)
504                self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
505                self.delete_commandline("r")
506                self.change_commandline("a","remove")
507                return 1 
508           
509            else:
510
511                # Check if _p3dr file is available, otherwise notice user
512                drop_job = self.group_execution.findChild(QtGui.QComboBox,"drop_job").currentText()
513                if ( self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").checkState() == 2 or 
514                     drop_job == "Restart run" or drop_job == "Restart run (coupled atmosphere ocean)"     ):
515
516                    jobname = self.group_execution.findChild(QtGui.QLineEdit, "line_jobname").text()
517                    restartfile = "%s/JOBS/%s/INPUT/%s_p3dr" % (palm_dir,jobname,jobname)
518
519                    if (os.path.exists(restartfile) == True):                 
520                        self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("")
521               
522
523                        if ( drop_job == "Restart run (coupled atmosphere ocean)" ):
524                            restartfileo = "%s/JOBS/%s/INPUT/%s_p3dor" % (palm_dir,jobname,jobname)
525                            if (os.path.exists(restartfileo) == True):                 
526                                self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("hooo")
527                 
528                            else:       
529                                self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dor file found!</font>")   
530               
531                    else:       
532                        self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dr file found!</font>")
533         
534               
535                       
536                self.group_execution.setEnabled(True)
537                self.drop_job.setEnabled(True)
538                self.group_advanced.setEnabled(True)
539                   
540        # Change in parameter "a" (run control list)
541        elif (id_str == "a"): 
542   
543            drop_job = self.group_execution.findChild(QtGui.QComboBox,"drop_job").currentText()
544            rc_flag = "#"
545   
546            if (drop_job == "Initial run"):
547                rc_flag = "#"
548           
549            elif (drop_job == "Restart run"):           
550                rc_flag = "r"
551           
552            elif (drop_job == "Precursor run (atmosphere)"):           
553                rc_flag = "#"
554           
555            elif (drop_job == "Precursor run (ocean)"):           
556                rc_flag = "o#"
557
558            elif (drop_job == "Initial run (coupled atmosphere ocean)"):           
559                rc_flag = "#"
560           
561            elif (drop_job == "Restart run (coupled atmosphere ocean)"):           
562                rc_flag = "r"
563           
564            param[0] = "\"d3%s" % (rc_flag)
565   
566   
567            if (drop_job == "Restart run (coupled atmosphere ocean)" or drop_job == "Initial run (coupled atmosphere ocean)"):
568                if (rc_flag == "#"):
569                   rc_flag = "o#"
570                else:
571                   rc_flag = "or"
572
573                param[0] = "%s d3%s" % (param[0],rc_flag)
574   
575            status_restarts = self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").checkState()
576
577            if (status_restarts == 2):
578                param[0]="%s restart" % (param[0])
579   
580                # Check if _p3dr file is available, otherwise notice user
581                if (status_restarts == 2):
582                    jobname = str(self.group_execution.findChild(QtGui.QLineEdit, "line_jobname").text())
583                    restartfile = "%s/JOBS/%s/INPUT/%s_p3dr" % (palm_dir,jobname,jobname)
584                    if (os.path.exists(restartfile) == True):                   
585                        self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("")
586                   
587                    else:                   
588                        self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dr file found!</font>")
589
590            else: 
591                self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("")
592
593            status_cycfill = self.group_execution.findChild(QtGui.QCheckBox,"check_cycfill").checkState()
594   
595            if (status_cycfill == 2):           
596                param[0]="%s fill" % (param[0])
597           
598            status_svf = self.group_execution.findChild(QtGui.QCheckBox,"check_svf").checkState()
599   
600            if (status_svf == 2):           
601                param[0]="%s svf" % (param[0])
602
603            param[0]="%s\"" % (param[0])
604 
605 
606            if ( fwt_str == "remove"):           
607                self.delete_commandline(id_str)
608                return 1
609           
610            else:           
611                self.button_start.setEnabled(True)
612                self.action_save.setEnabled(True)
613                self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
614
615        # Change in any other parameter
616        else:
617            if ( fwt_str != ""):           
618                param[0] = "\"%s\"" % (fwt_str)
619           
620            else:           
621                self.delete_commandline(id_str)
622                return 1
623                       
624        # Join the new palmrunline
625        splitline[1]= " -".join(param)
626               
627               
628        s = " -%s " % (id_str)
629        newpalmrunline = s.join(splitline)
630   
631        # Pr the new palmrunline to mainwindow
632        newpalmrunline = newpalmrunline.replace("  "," ")
633        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(newpalmrunline)
634
635    # change lineinput depending on sender
636    ###################################################################################
637    def change_lineinput(self):
638        if ( self.sender() == self.group_execution.findChild(QtGui.QComboBox, "combo_configuration") ):
639            tmptext = self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").currentText()
640            if tmptext.isEmpty():
641               self.change_commandline("c"," ")
642               self.group_execution.findChild(QtGui.QPushButton,'button_palmbuild').setEnabled(False)
643            else:
644               self.change_commandline("c",tmptext)
645               self.group_execution.findChild(QtGui.QPushButton,'button_palmbuild').setEnabled(True)         
646
647        elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_q")):
648            tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_q").text()
649            self.change_commandline("q",tmptext)
650       
651        elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_account")):
652            tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_account").text()
653            self.change_commandline("A",tmptext)
654       
655        elif ( self.sender() ==  self.group_execution.findChild(QtGui.QLineEdit,"line_pe")):
656            tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_pe").text()
657            self.change_commandline("X",tmptext)
658       
659        elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_tpn")):
660            tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_tpn").text()
661            self.change_commandline("T",tmptext)
662               
663        elif ( self.sender() == self.group_execution.findChild(QtGui.QLineEdit,"line_time")):
664            tmptext = self.group_execution.findChild(QtGui.QLineEdit,"line_time").text()
665            self.change_commandline("t",tmptext)
666       
667        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_M")):
668            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_M").text()
669            self.change_commandline("M",tmptext)
670       
671        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_m")):
672            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_m").text()
673            self.change_commandline("m",tmptext)
674       
675        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_D")):
676            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_D").text()
677            self.change_commandline("D",tmptext)
678       
679        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_c")):
680            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_c").text()
681            if ( tmptext == ".palmrungui.config"):
682                tmptext = ""
683            self.change_commandline("c",tmptext)
684       
685        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_s")):
686            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_s").text()
687            self.change_commandline("s",tmptext)
688               
689        elif ( self.sender() == self.group_advanced.findChild(QtGui.QLineEdit,"line_w")):
690            tmptext = self.group_advanced.findChild(QtGui.QLineEdit,"line_w").text()
691            self.change_commandline("w",tmptext)
692       
693        elif ( self.sender() == self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos") or 
694               self.sender() == self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean")):
695            t1 = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").text()
696            t2 = self.group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").text()           
697            tmptext = "%s %s" % (t1,t2)
698           
699            self.change_commandline("Y",tmptext)
700
701            # try catch sowas in der art
702            pe1 = 0
703            pe2 = 0
704           
705            try:
706                pe1 = int(t1)
707            except ValueError:           
708                pass
709               
710            try:
711                pe2 = int(t2)
712            except ValueError:
713                pass
714               
715            PE_total = pe1+pe2   
716            self.group_execution.findChild(QtGui.QLineEdit,"line_pe").setText(str(PE_total))
717            self.change_commandline("X",str(PE_total))
718         
719    # deletes parameter from commandline
720    #####################################################################################
721    def delete_commandline(self, id_str):   
722        # Read palmrunline
723        commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline")
724        palmrunline = str(commandline.text())
725        s = " -%s" % (id_str)
726        splitline = filter(None,palmrunline.split(s))
727       
728        if ( len(splitline) == 1):
729            return 1
730        else:
731            param = splitline[1].split("-")
732            param[0] = ""
733            splitline[1]= " -".join(param)
734            newpalmrunline = "".join(splitline)
735            newpalmrunline = newpalmrunline.replace("  "," ")
736   
737            # Print new palmrunline to screen
738            commandline.setText(newpalmrunline)
739       
740    # controls flags
741    ###################################################################################
742    def check_flags(self):
743        status = self.group_execution.findChild(QtGui.QCheckBox,"check_delete_tmp_files" ).checkState()
744        if (status == 2):     
745            self.activate_flag("B")
746        else:
747            self.deactivate_flag("B")
748   
749        status = self.group_execution.findChild(QtGui.QCheckBox,"check_verbose" ).checkState()
750        if (status == 2):
751            self.activate_flag("v") 
752        else:
753            self.deactivate_flag("v")
754       
755        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_b" ).checkState() 
756        if (status == 2):
757            self.activate_flag("b")
758        else:
759            self.deactivate_flag("b")
760   
761        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_F" ).checkState()   
762        if (status == 2):
763            self.activate_flag("F")
764        else:
765            self.deactivate_flag("F")
766           
767        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_I" ).checkState() 
768        if (status == 2):
769            self.activate_flag("I")
770        else:
771            self.deactivate_flag("I")
772
773        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_k" ).checkState() 
774        if (status == 2):
775            self.activate_flag("k")
776        else:
777            self.deactivate_flag("k")
778
779        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_O" ).checkState() 
780        if (status == 2):
781            self.activate_flag("O")
782        else:
783            self.deactivate_flag("O")
784
785        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_x" ).checkState() 
786        if (status == 2):
787            self.activate_flag("x")
788        else:
789            self.deactivate_flag("x")
790       
791        status = self.group_advanced.findChild(QtGui.QCheckBox,"check_Z" ).checkState() 
792        if (status == 2):
793            self.activate_flag("Z")
794        else:
795            self.deactivate_flag("Z")
796       
797    # changes flag to parameter
798    ##################################################################################   
799    def activate_flag(self, id_str):
800        commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline")
801        palmrunline = str(commandline.text())
802        s = " -%s" % (id_str)
803        splitline = filter(None,palmrunline.split(s))
804       
805        if ( len(splitline) == 1):
806            splitline.append("")
807            s = " -%s" % (id_str)
808            newpalmrunline = s.join(splitline)
809            newpalmrunline = newpalmrunline.replace("  "," ")
810            commandline.setText(newpalmrunline)               
811       
812    # deletes flag in commandline
813    ####################################################################################   
814    def deactivate_flag(self, id_str):
815        commandline = self.groupBox.findChild(QtGui.QLineEdit,"commandline")
816        palmrunline = str(commandline.text())
817        s = " -%s" % (id_str)
818        splitline = filter(None,palmrunline.split(s))
819 
820        newpalmrunline = "".join(splitline)
821        newpalmrunline = newpalmrunline.replace("  "," ")
822        commandline.setText(newpalmrunline)     
823
824    # Clears window
825    #################################################################################
826    def reset_window(self):
827        self.setupUi(self)
828        self.tabWidget.setCurrentIndex(0)
829        self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png"))   
830        self.recent_jobs(50)
831        self.load_jobs()
832       
833    # Safes current commandline and user Parameters to .sav file
834    #################################################################################
835    def save_to_file(self):
836        user_string = self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text()
837        cmd_string = self.groupBox.findChild(QtGui.QLineEdit,"commandline").text()
838       
839        string_to_file = cmd_string
840        if (user_string != ""): 
841            string_to_file = "%s%s" % (string_to_file,user_string)
842           
843        #filename = QtGui.QInputDialog.getText(self, "Save File naming Dialog", "Insert filename", QtGui.QLineEdit.Normal)
844        filename = str(QtGui.QFileDialog.getSaveFileName(self, "Save File","filename.sav"))
845        extension = ".sav"
846        filename = "%s%s" % (filename, "")
847        tmstamp = strftime("%Y/%m/%d %H:%M")
848       
849        file = open(filename,"w")
850        s = "%s %s" % (tmstamp, string_to_file)
851        file.write(s)
852        file.close()
853       
854    # Safes current commandline and user parameters to default file
855    ################################################################################
856    def save_default(self):
857        user_string = self.group_advanced.findChild(QtGui.QLineEdit,"line_user").text()
858        cmd_string = self.groupBox.findChild(QtGui.QLineEdit,"commandline").text()
859       
860        string_to_file = cmd_string
861        if (user_string != ""): 
862            string_to_file = "%s%s" % (string_to_file,user_string)
863       
864        filename ="%s/.palmrungui.default" % (palm_dir)
865        tmstamp = strftime("%Y/%m/%d %H:%M")
866       
867        file = open(filename,"w")
868        s = "%s %s" % (tmstamp, string_to_file)
869        file.write(s)
870        file.close()       
871
872       
873    # Executes command which starts watchdog (start palm_wd)
874    ########################################################
875    def start_watchdog(self):
876        subprocess.Popen(["nohup","palm_wd",">>","/dev/null", "2>&1","&"])
877
878    # Opens "help" dialog
879    #################################
880    def help(self):       
881        dialog = HelpDialog()
882        dialog.exec_()
883
884    # Opens "about" dialog
885    ##################################
886    def about_gui(self):
887        dialog = AboutDialog()
888        dialog.exec_()
889
890    # commandline to buttons etc
891    ##############################
892    def setup_gui(self, palmrun_str): 
893     
894        #self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png"))   
895     
896        #  Some initial settings
897        user = "" 
898        coupled_run = False 
899        ocean_run   = False 
900        nojob       = False 
901
902        #Split parameters in palmrunline
903        splitline = palmrun_str.split(" -")
904       
905        if ( splitline[0] != "palmrun"):
906            return 1
907
908        else:
909            self.group_execution.setEnabled(True) 
910
911        # Loop for all parameters in palmrunline
912        i = len(splitline)-1
913        while i >= 1:
914
915            # Determine parameter
916            splitparameter = splitline[i].split(" ")
917
918            parameter = splitparameter[0] 
919            splitparameter.pop(0)
920            options = " ".join(splitparameter) 
921            options = options.replace("\"","") 
922
923            # Check for suitable switch
924            if ( parameter == "r"):
925             
926                if ( options != ""):
927                    self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").setText(options) 
928                    nojob = False 
929               
930                else:                 
931                    nojob = True 
932               
933            elif ( parameter == "c"):
934                tmpindex = self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").findText(options,QtCore.Qt.MatchExactly)
935                if tmpindex != -1: 
936                   self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").setCurrentIndex(tmpindex)
937                else:
938                   self.group_execution.findChild(QtGui.QComboBox, "combo_configuration").setCurrentIndex(0)
939            elif ( parameter == "q"):
940                self.group_execution.findChild(QtGui.QLineEdit,"line_q").setText(options) 
941             
942            elif ( parameter == "A"):
943                self.group_execution.findChild(QtGui.QLineEdit,"line_account").setText(options) 
944             
945            elif ( parameter == "X"):
946                self.group_execution.findChild(QtGui.QLineEdit,"line_pe").setText(options) 
947             
948            elif ( parameter == "T"):
949                self.group_execution.findChild(QtGui.QLineEdit,"line_tpn").setText(options) 
950             
951            elif ( parameter == "t"):
952                self.group_execution.findChild(QtGui.QLineEdit,"line_time").setText(options) 
953             
954            elif ( parameter == "B"):
955                self.group_execution.findChild(QtGui.QCheckBox,"check_delete_tmp_files").setChecked(True) 
956             
957            elif ( parameter == "v"):
958                self.group_execution.findChild(QtGui.QCheckBox,"check_verbose").setChecked(True) 
959                         
960            elif ( parameter == "b"): 
961                self.group_advanced.findChild(QtGui.QCheckBox,"check_b").setChecked(True) 
962             
963            elif ( parameter == "F"):
964                self.group_advanced.findChild(QtGui.QCheckBox,"check_F").setChecked(True) 
965             
966            elif ( parameter == "I"):
967                self.group_advanced.findChild(QtGui.QCheckBox,"check_I").setChecked(True) 
968             
969            elif ( parameter == "k"):
970                self.group_advanced.findChild(QtGui.QCheckBox,"check_k").setChecked(True) 
971             
972            elif ( parameter == "O"): 
973                self.group_advanced.findChild(QtGui.QCheckBox,"check_O").setChecked(True) 
974             
975            elif ( parameter == "x"):             
976                self.group_advanced.findChild(QtGui.QCheckBox,"check_x").setChecked(True) 
977             
978            elif ( parameter == "Z"):
979                self.group_advanced.findChild(QtGui.QCheckBox,"check_Z").setChecked(True) 
980               
981            elif ( parameter == "m"):
982                self.group_advanced.findChild(QtGui.QLineEdit,"line_m").setText(options) 
983             
984            elif ( parameter == "M"):
985                self.group_advanced.findChild(QtGui.QLineEdit,"line_M").setText(options) 
986                         
987            elif ( parameter == "D"):
988                self.group_advanced.findChild(QtGui.QLineEdit,"line_D").setText(options) 
989             
990            elif ( parameter == "c"):
991                self.group_advanced.findChild(QtGui.QLineEdit,"line_c").setText(options) 
992                         
993            elif ( parameter == "s"):
994                self.group_advanced.findChild(QtGui.QLineEdit,"line_s").setText(options) 
995             
996            elif ( parameter == "w"):
997                self.group_advanced.findChild(QtGui.QLineEdit,"line_w").setText(options) 
998             
999
1000            # Determine settings for coupled restart runs
1001            elif ( parameter == "Y"):
1002                optionssplit = options.split(" ") 
1003               
1004                group_coupled = self.group_execution.findChild(QtGui.QGroupBox,"group_coupled")
1005                group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setEnabled(True) 
1006                group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setEnabled(True) 
1007                group_coupled.findChild(QtGui.QLabel,"label_coupled1").setEnabled(True) 
1008                group_coupled.findChild(QtGui.QLabel,"label_coupled2").setEnabled(True) 
1009                group_coupled.findChild(QtGui.QLabel,"label_coupled3").setEnabled(True) 
1010                group_coupled.findChild(QtGui.QLabel,"label_coupling").setEnabled(True) 
1011
1012                if (optionssplit.count() == 2):
1013                    group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setEnabled(optionssplit[0]) 
1014                    group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setEnabled(optionssplit[1])
1015                 
1016                else:                 
1017                    group_coupled.findChild(QtGui.QLineEdit,"line_PE_atmos").setText("") 
1018                    group_coupled.findChild(QtGui.QLineEdit,"line_PE_ocean").setText("") 
1019 
1020                 
1021                coupled_run = True 
1022           
1023            elif ( parameter == "y"):             
1024                self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(3) 
1025             
1026
1027            # Determine settings for the run control list
1028            elif ( parameter == "a"):
1029             
1030                optionssplit = options.split(" ") 
1031
1032                options_2 = None
1033                options_all = None
1034               
1035                j = 0
1036                while j < len(optionssplit):
1037                 
1038                    options_all = optionssplit[j] 
1039                    options_2 = optionssplit[j][:2] 
1040                                             
1041                    if (options_2 == "d3"):     
1042                        if (options_all[:3][-1] == "#"):
1043                            self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(0) 
1044                        elif (options_all[:3][-1] == "r"):
1045                            self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(1) 
1046                       
1047                        elif (options_all[:3][-1] == "o"):
1048                            ocean_run = True 
1049                       
1050                    if (options_all == "restart"):
1051                        self.group_execution.findChild(QtGui.QCheckBox,"check_restarts").setChecked(True) 
1052                        # Check if _pdf file is available, otherwise notice user
1053                        jobname = str(self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").text()) 
1054                       
1055                        restartfile = "%sJOBS/%s/INPUT/%s_p3dr" % (palm_dir,jobname,jobname)
1056                        if (os.path.exists(restartfile) == True):   
1057                            self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("") 
1058                       
1059                        else:
1060                            self.group_execution.findChild(QtGui.QLabel,"label_restart").setText("<font color='red'>Warning: No p3dr file \found!</font>") 
1061                    j = j+1
1062
1063            # All unknown parameters are set as extra user parameters
1064            else: 
1065                print parameter
1066                user = "%s-%s \"%s\" " % (user,parameter,options)
1067                splitline.removeAt(i) 
1068
1069            i = i-1
1070        # Change drop box state in case of ocean precursor or coupled restart runs
1071        if ( ocean_run == True ):
1072            if ( coupled_run == True ):
1073                self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(4) 
1074           
1075            else:
1076                self.group_execution.findChild(QtGui.QComboBox, "drop_job").setCurrentIndex(3) 
1077
1078        if ( user != ""):
1079            self.group_advanced.findChild(QtGui.QLineEdit,"line_user").setText(user)
1080
1081        # Join palmrunline and post it to mainwindow
1082        palmrunline = " -".join(splitline) 
1083        self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline)         
1084
1085        # Disable mainwindow if no job was found, otherwise enable
1086        if ( nojob == True ):
1087            self.group_execution.setEnabled(False) 
1088            self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(False) 
1089            self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(False) 
1090            self.group_execution.findChild(QtGui.QComboBox, "drop_job").setEnabled(False) 
1091            self.group_advanced.setEnabled(False) 
1092            self.check_advanced.setEnabled(False) 
1093            self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(False)
1094         
1095        else:
1096            self.group_execution.setEnabled(True) 
1097            self.groupBox.findChild(QtGui.QPushButton,"button_start").setEnabled(True) 
1098            self.menuBar.findChild(QtGui.QMenu,"menuStart").actions()[3].setEnabled(True)
1099            self.group_execution.findChild(QtGui.QComboBox, "drop_job").setEnabled(True) 
1100            self.group_advanced.setEnabled(True) 
1101            self.groupBox.findChild(QtGui.QLineEdit,"line_tag").setEnabled(True)
1102         
1103        self.tabWidget.setCurrentIndex(0)
1104         
1105    # open saved commandline
1106    ##################################
1107    def open_from_file(self):
1108       
1109        # Select filename and open it
1110        filename = QtGui.QFileDialog.getOpenFileName(self, "Open File","Save files (*.sav)") 
1111       
1112        if ( filename != ""):
1113            file = open(filename, "r")
1114         
1115            if ( file is not None ):
1116                # File opened successfully
1117                palmrunline = file.read()
1118                file.close() 
1119   
1120            # In case a palmrunline was found, load it to mainwindow
1121            if ( palmrunline != ""):
1122                palmrunline = palmrunline[17:] 
1123                self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) 
1124                self.setup_gui(palmrunline)
1125         
1126    # open saved commandline   
1127    ##################################
1128    def open_last(self): 
1129        # Select filename and open it
1130        filename = "%s/.palmrungui.history" % (palm_dir)
1131       
1132        if os.path.exists(filename):
1133            pass
1134        else:
1135            return
1136       
1137        file = open(filename, "r") 
1138        if ( file is not None ):
1139            # File opened successfully
1140            lines = file.readlines()
1141            palmrunline = lines[len(lines)-1]
1142            palmrunline = palmrunline[:len(palmrunline)-1]
1143            file.close() 
1144
1145        # In case a palmrunline was found, load it to mainwindow
1146        if ( palmrunline != ""):
1147            palmrunline = palmrunline[17:len(palmrunline)] 
1148            self.groupBox.findChild(QtGui.QLineEdit,"commandline").setText(palmrunline) 
1149            self.setup_gui(palmrunline)       
1150
1151 
1152   
1153    def update_all(self):
1154 
1155       self.setEnabled(False)
1156       self.list_input.clear() 
1157       self.list_user.clear()
1158       self.list_monitoring.clear()
1159       self.list_output.clear()
1160       self.load_jobs()
1161       self.setEnabled(True)
1162       self.update_input()
1163
1164    # Load jobs into list
1165    def load_jobs(self):
1166       
1167       selected_job = self.list_jobs.currentItem()
1168       
1169       if ( selected_job is not None ):
1170          jobname = selected_job.text()
1171       else:
1172          jobname = ""
1173
1174       self.list_jobs.clear() 
1175       self.push_copy.setEnabled(False)
1176       self.push_create_set.setEnabled(False)     
1177     
1178       self.line_path.setText(job_dir + "/")
1179       
1180       list_of_files = os.listdir(job_dir)
1181     
1182
1183       for i in range(0,len(list_of_files)):
1184          tmp_file = job_dir + "/" + list_of_files[i]
1185
1186          if ( os.path.isdir(tmp_file) ):
1187             self.list_jobs.addItem(str(list_of_files[i]))
1188       
1189
1190
1191       item2int = self.list_jobs.findItems(jobname,QtCore.Qt.MatchCaseSensitive)
1192       
1193       if ( item2int != [] ):
1194          self.list_jobs.setCurrentItem(item2int[0])
1195
1196
1197    # Update input and user code lists
1198    def update_input(self):
1199     
1200       self.list_input.clear() 
1201       self.list_user.clear()
1202       self.list_monitoring.clear()
1203       self.list_output.clear()
1204       self.push_copy.setEnabled(True)
1205       self.push_create_set.setEnabled(True)
1206       
1207       jobitem = self.list_jobs.currentItem()
1208       
1209       if ( jobitem != None ):
1210       
1211          job_to_show = job_dir + "/" + jobitem.text() + "/INPUT"
1212
1213          if ( os.path.isdir(job_to_show) ):
1214
1215             list_of_files = os.listdir(job_to_show)
1216         
1217             for i in range(0,len(list_of_files)):
1218                tmp_file = job_to_show + "/" + list_of_files[i]
1219             
1220                if ( os.path.isfile(tmp_file) ):
1221                   self.list_input.addItem(str(list_of_files[i]))
1222 
1223          job_to_show = job_dir + "/" + jobitem.text() + "/USER_CODE"
1224       
1225          if ( os.path.isdir(job_to_show) ):
1226         
1227             list_of_files = os.listdir(job_to_show)
1228         
1229             for i in range(0,len(list_of_files)):
1230                tmp_file = job_to_show + "/" + list_of_files[i]
1231
1232                if ( os.path.isfile(tmp_file) ):
1233                   self.list_user.addItem(str(list_of_files[i]))
1234
1235          job_to_show = job_dir + "/" + jobitem.text() + "/MONITORING"
1236       
1237          if ( os.path.isdir(job_to_show) ):
1238         
1239             list_of_files = os.listdir(job_to_show)
1240         
1241             for i in range(0,len(list_of_files)):
1242                tmp_file = job_to_show + "/" + list_of_files[i]
1243
1244                if ( os.path.isfile(tmp_file) ):
1245                   self.list_monitoring.addItem(str(list_of_files[i]))
1246
1247          job_to_show = job_dir + "/" + jobitem.text() + "/OUTPUT"
1248
1249          if ( os.path.isdir(job_to_show) ):
1250         
1251             list_of_files = os.listdir(job_to_show)
1252         
1253             for i in range(0,len(list_of_files)):
1254                tmp_file = job_to_show + "/" + list_of_files[i]
1255
1256                if ( os.path.isfile(tmp_file) ):
1257                   self.list_output.addItem(str(list_of_files[i]))
1258 
1259          self.group_execution.findChild(QtGui.QLineEdit,"line_jobname").setText(jobitem.text())
1260       self.group_history.findChild(QtGui.QListWidget,"list_jobname").clearSelection()
1261
1262       # Change palmrunline accordingly
1263       self.change_commandline("r","")
1264       self.change_commandline("a","")
1265 
1266 
1267    # Make a copy of a job
1268    def copy_job(self):
1269 
1270       self.setEnabled(False)
1271       old_job_name = self.list_jobs.currentItem().text()
1272       
1273       text, ret = QtGui.QInputDialog.getText(self, "Copy job", "Enter new job name:", mode = QtGui.QLineEdit.Normal, text = old_job_name)
1274       
1275       if ( ret ):
1276          new_job_name = str(text)
1277       else:
1278           self.setEnabled(True)
1279           return
1280         
1281       new_input_dir  = job_dir + "/" + new_job_name + "/INPUT"
1282
1283#      check if a job exists with the new job name 
1284       if ( os.path.isdir(new_input_dir) ):
1285           notify = QtGui.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.")
1286           self.setEnabled(True)
1287           return
1288       else:
1289           os.makedirs(new_input_dir)
1290
1291#      copy and rename input files (if present)       
1292       job_to_copy = job_dir + "/" + old_job_name + "/INPUT"
1293
1294       if ( os.path.isdir(job_to_copy) ):
1295
1296          list_of_files = os.listdir(job_to_copy)
1297         
1298          for i in range(0,len(list_of_files)):
1299
1300             tmp_file = job_to_copy + "/" + list_of_files[i]         
1301             new_file = new_input_dir + "/" + list_of_files[i].replace(old_job_name, new_job_name)
1302             shutil.copy(tmp_file, new_file)
1303
1304
1305
1306
1307       new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
1308       
1309#      check if user code exists in the new job directory
1310       if ( os.path.isdir(new_user_dir) ):
1311           notify = QtGui.QMessageBox.warning(self,'Create new user code directory',"Error. Could not create user code directory. A user code directiory with the new name already exists.")
1312           self.setEnabled(True)
1313           return
1314       else:
1315           os.makedirs(new_user_dir)
1316
1317
1318#      copy user code files (if present)       
1319       user_to_copy = job_dir + "/" + old_job_name + "/USER_CODE"
1320
1321       if ( os.path.isdir(user_to_copy) ):
1322
1323          list_of_files = os.listdir(user_to_copy)
1324         
1325          for i in range(0,len(list_of_files)):
1326
1327             tmp_file = user_to_copy + "/" + list_of_files[i]         
1328             new_file = new_user_dir + "/" + list_of_files[i]
1329             shutil.copy(tmp_file, new_file)
1330
1331       self.load_jobs()
1332       self.list_input.clear() 
1333       self.list_user.clear()
1334       self.list_monitoring.clear()
1335       self.list_output.clear()
1336       self.setEnabled(True)
1337
1338
1339    # Create a whole set of jobs
1340    def create_set(self):
1341 
1342       global set_list
1343#      disable mainwindow 
1344       self.setEnabled(False)
1345     
1346#      show Options Dialog     
1347       opt = CreateSetBox()
1348       opt.exec_()
1349
1350       old_job_name = self.list_jobs.currentItem().text()
1351
1352       for j in range(0,len(set_list)):
1353
1354          if ( set_list[j] != "" ):
1355             new_job_name   = str(set_list[j])
1356             new_input_dir  = job_dir + "/" + str(set_list[j]) + "/INPUT"
1357          else:
1358             continue
1359
1360#         check if a job exists with the new job name 
1361          if ( os.path.isdir(new_input_dir) ):
1362             notify = QtGui.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.")
1363             self.setEnabled(True)
1364             return
1365          else:
1366             os.makedirs(new_input_dir)
1367
1368#         copy and rename input files (if present)       
1369          job_to_copy = job_dir + "/" + old_job_name + "/INPUT"
1370
1371          if ( os.path.isdir(job_to_copy) ):
1372
1373             list_of_files = os.listdir(job_to_copy)
1374         
1375             for i in range(0,len(list_of_files)):
1376
1377                tmp_file = job_to_copy + "/" + list_of_files[i]         
1378                new_file = new_input_dir + "/" + list_of_files[i].replace(old_job_name, new_job_name)
1379                shutil.copy(tmp_file, new_file)
1380
1381
1382          new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
1383       
1384#         check if user code exists in the new job directory
1385          if ( os.path.isdir(new_user_dir) ):
1386              notify = QtGui.QMessageBox.warning(self,'Create new user code directory',"Error. Could not create user code directory. A user code directiory with the new name already exists.")
1387              self.setEnabled(True)
1388              return
1389          else:
1390              os.makedirs(new_user_dir)
1391
1392
1393#         copy user code files (if present)       
1394          user_to_copy = job_dir + "/" + old_job_name + "/USER_CODE"
1395
1396          if ( os.path.isdir(user_to_copy) ):
1397
1398             list_of_files = os.listdir(user_to_copy)
1399         
1400             for i in range(0,len(list_of_files)):
1401
1402                tmp_file = user_to_copy + "/" + list_of_files[i]         
1403                new_file = new_user_dir + "/" + list_of_files[i]
1404                shutil.copy(tmp_file, new_file)
1405
1406          self.load_jobs()
1407          self.list_input.clear() 
1408          self.list_user.clear()
1409          self.list_monitoring.clear()
1410          self.list_output.clear()
1411
1412       self.setEnabled(True) 
1413       set_list = []
1414   
1415 # Add a custom context menu
1416    def openmenuinput(self, position):
1417
1418        menu = QtGui.QMenu()
1419
1420        selection = self.list_input.selectedItems()
1421       
1422        if ( len(selection) != 0 ):
1423
1424           openAction = menu.addAction('Open selected files')     
1425           openAction.setStatusTip('Open file(s) in your favorite editor')
1426           openAction.triggered.connect(self.OpenFilesInput)
1427           action = menu.exec_(self.list_input.mapToGlobal(position))
1428
1429 # Add a custom context menu
1430    def openmenuuser(self, position):
1431
1432        menu = QtGui.QMenu()
1433
1434        selection = self.list_user.selectedItems()
1435       
1436        if ( len(selection) != 0 ):
1437
1438           openAction = menu.addAction('Open selected files')     
1439           openAction.setStatusTip('Open file(s) in your favorite editor')
1440           openAction.triggered.connect(self.OpenFilesUser)
1441           action = menu.exec_(self.list_user.mapToGlobal(position))
1442
1443 # Add a custom context menu
1444    def openmenuoutput(self, position):
1445
1446        menu = QtGui.QMenu()
1447
1448        selection = self.list_output.selectedItems()
1449       
1450        if ( len(selection) != 0 ):
1451
1452           openAction = menu.addAction('Open selected files')     
1453           openAction.setStatusTip('Open file(s) in your favorite editor')
1454           openAction.triggered.connect(self.OpenFilesOutput)
1455           action = menu.exec_(self.list_output.mapToGlobal(position))
1456
1457 # Add a custom context menu
1458    def openmenumonitoring(self, position):
1459
1460        menu = QtGui.QMenu()
1461
1462        selection = self.list_monitoring.selectedItems()
1463       
1464        if ( len(selection) != 0 ):
1465
1466           openAction = menu.addAction('Open selected files')     
1467           openAction.setStatusTip('Open file(s) in your favorite editor')
1468           openAction.triggered.connect(self.OpenFilesMonitoring)
1469           action = menu.exec_(self.list_monitoring.mapToGlobal(position))
1470
1471    def OpenFilesInput(self):
1472   
1473       sel_job = self.list_jobs.currentItem().text()
1474       sel_files = self.list_input.selectedItems()
1475       
1476       input_dir = job_dir + "/" + sel_job + "/INPUT/"
1477       
1478       open_files = ""
1479       for i in range(0,len(sel_files)):
1480          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text() + "; "
1481
1482       os.system(str(open_files))
1483
1484    def OpenFilesUser(self):
1485   
1486       sel_job = self.list_jobs.currentItem().text()
1487       sel_files = self.list_user.selectedItems()
1488       
1489       input_dir = job_dir + "/" + sel_job + "/USER_CODE/"
1490       
1491       open_files = ""
1492       for i in range(0,len(sel_files)):
1493          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text() + "; "
1494
1495       os.system(str(open_files)) 
1496       selection = self.list_jobs.selectedItems()
1497 
1498    def OpenFilesMonitoring(self):
1499   
1500       sel_job = self.list_jobs.currentItem().text()
1501       sel_files = self.list_monitoring.selectedItems()
1502       
1503       input_dir = job_dir + "/" + sel_job + "/MONITORING/"
1504       
1505       open_files = ""
1506       for i in range(0,len(sel_files)):
1507          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text() + "; "
1508
1509       os.system(str(open_files)) 
1510       selection = self.list_jobs.selectedItems()
1511 
1512    def OpenFilesOutput(self):
1513   
1514       sel_job = self.list_jobs.currentItem().text()
1515       sel_files = self.list_output.selectedItems()
1516       
1517       input_dir = job_dir + "/" + sel_job + "/OUTPUT/"
1518       
1519       open_files = ""
1520       for i in range(0,len(sel_files)):
1521          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text() + "; "
1522
1523       os.system(str(open_files)) 
1524       selection = self.list_jobs.selectedItems()
1525 
1526# Message box for showing RUN_CONTROL output
1527class CreateSetBox(QtGui.QDialog):
1528    def __init__(self):
1529     
1530        super(CreateSetBox, self).__init__()
1531       
1532        uic.loadUi(palm_bin + '/palmrungui_files/create_set.ui', self)
1533       
1534        self.show()
1535       
1536        return
1537
1538#   Cancel button
1539    def rejected(self):
1540     
1541       self.close()
1542     
1543       return
1544 
1545
1546#   OK button
1547    def accept(self):
1548     
1549       global set_list
1550       
1551       text = self.list.toPlainText() 
1552       set_list = text.split('\n')
1553       self.close()
1554     
1555       return
1556
1557
1558       
1559
1560if __name__ == "__main__":
1561    app = QtGui.QApplication(sys.argv)
1562    window = Mainwindow()
1563    window.show()
1564    sys.exit(app.exec_())
Note: See TracBrowser for help on using the repository browser.