source: palm/trunk/SCRIPTS/mrungui.py @ 2365

Last change on this file since 2365 was 2316, checked in by maronga, 7 years ago

new mrungui version based on python

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