source: palm/trunk/SCRIPTS/palmrungui @ 4409

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

revisions in palmrungui, merged with palm_jm

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