source: palm/trunk/SCRIPTS/palmrungui @ 4670

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

ported palmrungui to pyqt5; several minor bugfixes in palmrungui

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 70.0 KB
Line 
1#!/usr/bin/env python3
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-2020  Leibniz Universitaet Hannover
18#--------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22#
23#
24# Former revisions:
25# -----------------
26# $Id: palmrungui 4670 2020-09-09 17:27:45Z maronga $
27# Ported to PyQt5, removed support for user parameters. Added support for Option
28# "-V" (do not re-build pre-built source code). Changed activation strings
29# according to default .palm.iofiles (svfin/svfout/rec)
30#
31# 4482 2020-04-01 13:17:50Z maronga
32# Added possibility to delete all files in a directory and option to create
33# blank new jobs
34#
35# 4481 2020-03-31 18:55:54Z maronga
36# Bugfixes: - reading history lines discard button caused error message
37#           - deleting of USER_CODE files did not work
38#
39# 4470 2020-03-24 06:52:19Z maronga
40# Added file size output, more I/O functionalities, new/removed buttons
41#
42# 4428 2020-02-27 11:43:53Z maronga
43# Bugfix for update button
44#
45# 4427 2020-02-27 11:29:51Z maronga
46# Small fixes and adjustments
47#
48# 4420 2020-02-24 14:13:56Z maronga
49# Bugfix: minor fixes related to start buttons
50#
51# 4411 2020-02-18 14:28:02Z maronga
52# Added new features: individual tag for submitted runs, automatic finding of
53# configuration, start of palmbuild from GUI
54#
55# 4405 2020-02-12 19:11:11Z maronga
56# Major revisions: New layout. Merged with palm job manager (palm_jm).
57# Minor revisions: Misc. bugs fixed.
58#
59# 4394 2020-02-04 21:40:38Z maronga
60# Bugfix: harmonized naming convention of configuration files
61#
62# 4393 2020-02-04 21:24:48Z maronga
63# Removed PALM_BIN dependency and os calls
64#
65# 3487 2018-11-05 07:18:02Z maronga
66# Renamed options -d and -h to -r and -c.
67#
68# 2825 2018-02-20 21:48:27Z maronga
69# Adjusted to work with newest version of palmrun
70#
71# 2718 2018-01-02 08:49:38Z maronga
72# Corrected "Former revisions" section
73#
74# 2696 2017-12-14 17:12:51Z kanani
75# Change in file header (GPL part)
76#
77# 2484 2017-09-20 14:22:42Z maronga
78# Added PALM logo
79#
80# 2480 2017-09-19 06:24:14Z maronga
81# option -A (project account number) added
82#
83# 2477 2017-09-18 08:42:29Z maronga
84# Renamed restart run appendix from "f" to "r". Bugfix for displaying restart runs.>
85# Revised list of recently submitted jobs
86#
87# 2413 2017-09-06 12:48:29Z maronga
88# Renamed to palmrungui and adapted for use with palmrun instead of mrun.
89#
90# 2316 2017-07-20 07:53:42Z maronga
91# Initial revision in python
92#
93#
94#
95# Description:
96# ------------
97# Graphical user interface for the palmrun script.
98# @author Felix Gaschler
99# @author Björn Maronga (maronga@muk.uni-hannover.de)
100#
101# Instructions:
102# -------------
103#
104#------------------------------------------------------------------------------!
105import sys
106import subprocess
107from PyQt5 import QtCore, QtGui, uic, QtWidgets
108from PyQt5.QtWidgets import QMainWindow, QApplication
109from PyQt5.QtCore import QProcess, pyqtSlot, QTimer
110from time import strftime
111import os
112import shutil
113
114global update_frequency
115update_frequency = 5*60000
116
117# Determine PALM directories
118try: 
119   devnull = open(os.devnull, 'w')     
120   palm_dir = os.getcwd()
121   palm_bin = palm_dir + '/trunk/SCRIPTS'
122   palm_source = palm_dir + '/trunk/SOURCE'
123   job_dir = palm_dir + '/JOBS'
124   user_dir = palm_dir + '/USER_CODE'
125   with open(palm_bin + '/palmrungui', 'r', encoding='utf8') as fh:
126      # file found
127      out = None
128except:   
129   print ("Error. palmrungui probably called in wrong directory.")
130   raise SystemExit
131
132
133# returns the human readable file size of filename
134def file_size(filename, suffix='B'):
135   size_raw = os.stat(filename).st_size
136   for unit in [' ',' K',' M',' G',' T']:
137      if abs(size_raw) < 1024.0:
138         return "%i%s%s" % (size_raw, unit, suffix)
139      size_raw /= 1024.0
140   return "%.1f%s%s" % (num, 'Y', suffix)
141
142def ilen(iterable):
143    return reduce(lambda sum, element: sum + 1, iterable, 0)
144
145palmrunline = ""
146set_list = []
147
148Ui_MainWindow = uic.loadUiType("%s/palmrungui_files/mainwindow.ui" % (palm_bin))[0]
149Ui_helpDialog = uic.loadUiType("%s/palmrungui_files/help.ui" % (palm_bin))[0]
150Ui_aboutDialog = uic.loadUiType("%s/palmrungui_files/about.ui" % (palm_bin))[0]
151
152class HelpDialog(QtWidgets.QDialog,Ui_helpDialog):
153    def __init__(self, parent=None):
154        super(HelpDialog,self).__init__()
155        self.setupUi(self)
156       
157class AboutDialog(QtWidgets.QDialog,Ui_aboutDialog):
158    def __init__(self, parent=None):
159        super(AboutDialog,self).__init__()
160        self.setupUi(self)       
161
162class Mainwindow(QtWidgets.QMainWindow, Ui_MainWindow):
163    def __init__(self, parent=None):
164        super(Mainwindow, self).__init__()
165        self.setupUi(self)
166
167        self.palm_logo.setPixmap(QtGui.QPixmap(palm_bin + "/palmrungui_files/logo.png"))
168        with open(palm_bin + "/palmrungui", encoding='utf8') as search:
169           for line in search:
170              line = line.rstrip()
171              if "$Id" in line:
172                 version = "Version: r" + line.split(" ")[3] + " (" + line.split(" ")[4] + ")"
173                 self.groupBox.findChild(QtWidgets.QLabel,"label_version").setText(version)
174                 break
175        self.recent_jobs(50)
176        self.load_jobs()
177
178
179
180        # look up configuration files and add to combo box
181       
182        self.group_execution.findChild(QtWidgets.QComboBox,"combo_configuration").addItem("")
183       
184        for files in os.listdir(palm_dir):
185           if files.startswith(".palm.config"):
186              tmpstring = list(filter(None,files.split(".palm.config.")))[0]
187              self.group_execution.findChild(QtWidgets.QComboBox,"combo_configuration").addItem(tmpstring)
188
189        commandline = self.groupBox.findChild(QtWidgets.QLineEdit,"commandline")
190        commandline.setText("")
191       
192        self.tabWidget.setCurrentIndex(0) 
193       
194
195        filename = "%s/.palmrungui.default" % (palm_dir) 
196        if os.path.exists(filename):
197           file = open(filename, "r")
198           if ( file is not None ):
199              # File opened successfully
200              palmrunline = file.readline()
201              #if neue zeile zeichen
202              palmrunline = palmrunline[:len(palmrunline)-1]
203              file.close()
204
205           # In case a palmrunline was found, load it to mainwindow
206           if ( palmrunline != ""):
207              palmrunline = palmrunline[17:]
208              commandline.setText(palmrunline)
209              self.setup_gui(palmrunline)
210
211        QtWidgets.QApplication.processEvents()
212
213        # Start refresh timer. On timeout perform update
214
215        self.timer = QtCore.QTimer(self)
216        self.timer.timeout.connect(self.update_all)
217        self.timer.setSingleShot(False)
218        self.timer.start(update_frequency)
219
220        # The timetimer counts the time since last update
221        self.timetimer= QtCore.QElapsedTimer()
222        self.timetimer.start()
223
224        # The labeltimer induces the update of the remaining time in the UI
225
226        self.labeltimer = QtCore.QTimer(self)
227        self.labeltimer.timeout.connect(self.UpdatePush)
228        self.labeltimer.setSingleShot(False)
229
230        # Update in the UI will be performed at each 1/10 of the update interval
231        self.labeltimer.start(update_frequency/10)
232        self.push_update.setText("Update (" + str(int(update_frequency/1000/60)) + " min)")
233
234    # starts xterm with palmrun commandline
235    #######################################
236    def startpalmrun(self):
237        palmrunline = str(self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").text())
238        palmrunline_save = palmrunline
239
240        # Disable the main window
241        self.tabWidget.setEnabled(False)
242        self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setEnabled(False)
243        self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setEnabled(False)
244        self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setText("wait...")
245        self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").setText("Executing palmrun in xterm...")
246
247        # Wait until all commands have been executed (ugly) ?
248        #for i in range(0,21):
249        #    qApp->processEvents()       
250
251        # Start xterm as QProcess
252        palmrun = QProcess()
253        palmrun.setProcessChannelMode(QProcess.MergedChannels) # mergedChannels
254        palmrun.setWorkingDirectory(palm_dir)
255
256        geomet = self.frameGeometry()
257
258        posx = geomet.x()+geomet.width()
259        posy = geomet.y()
260
261        if ( os.path.isfile("palmrungui.log") ):
262           os.remove("palmrungui.log")
263
264        s = " -title \"Executing palmrun...\" -fa \"Monospace\" -l -lf \"palmrungui.log\" -fs 11 -geometry \"80x38+%d+%d\" -e \"" % (posx,posy)
265        palmrunline = "%s%s ;echo -n '--> Press enter to continue...';read yesno\"</dev/stdin" % (s, palmrunline.replace("\"","\'"))
266
267        mString = "xterm %s" % (palmrunline)
268        palmrun.start(mString)
269
270        if( palmrun.waitForStarted() is False ):
271            return
272
273        # Wait until palmrun has finished or wait for 200 minutes
274        palmrun.waitForFinished(3600000)       
275
276        # Jobs has been submitted or aborted. Continuing...
277        # Save the palmrun command to history file
278        filename = "%s/.palmrungui.history" % (palm_dir)
279        tmstamp = strftime("%Y/%m/%d %H:%M")
280        tag = str(self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").text())
281   
282        file = open(filename,"a")
283        s = "%s %s (%s)\n" % (tmstamp,palmrunline_save,tag)
284        file.write(s)
285        file.close()             
286       
287        # Enable main window again
288        self.tabWidget.setEnabled(True)
289        self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setEnabled(True)
290        self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setText("palmrun")
291        self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").setText(palmrunline_save)
292        self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setEnabled(True)
293       
294        # Reload recent jobs
295        self.recent_jobs(50)
296       
297       
298       
299    # Update the label
300    def UpdatePush(self):
301        remaining_time = int((update_frequency - self.timetimer.elapsed()) / 1000 / 60)
302        self.push_update.setText("Update (" + str(remaining_time) + " min)")
303
304
305    # starts xterm with palmbuild commandline
306    #######################################
307    def startpalmbuild(self):
308        palmbuildline = 'palmbuild -c ' + str(self.group_execution.findChild(QtWidgets.QComboBox, "combo_configuration").currentText())
309
310        full_build = self.group_execution.findChild(QtWidgets.QCheckBox,"check_rebuild").checkState()
311
312        if ( full_build == 2 ):
313           for filename in os.listdir(palm_source):
314              os.utime(palm_source + "/" + filename, None)
315
316        palmrunline_save = str(self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").text())
317
318        # Disable the main window
319        palmbuildline_save = palmbuildline
320        self.tabWidget.setEnabled(False)
321        self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setEnabled(False)
322        self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setEnabled(False)
323        self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setText("wait...")
324        self.group_execution.findChild(QtWidgets.QPushButton,"button_palmbuild").setText("wait...")
325        self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").setText("Executing palmbuild in xterm...")
326       
327        # Wait until all commands have been executed (ugly) ?
328        #for i in range(0,21):
329        #    qApp->processEvents()       
330       
331        # Start xterm as QProcess
332        palmbuild = QProcess()
333        palmbuild.setProcessChannelMode(QProcess.MergedChannels) # mergedChannels
334        palmbuild.setWorkingDirectory(palm_dir)
335   
336        geomet = self.frameGeometry()
337       
338        posx = geomet.x()+geomet.width()
339        posy = geomet.y()
340     
341        s = " -title \"Executing palmbuild...\" -fa \"Monospace\" -fs 11 -geometry \"80x38+%d+%d\" -e \"" % (posx,posy)
342        palmbuildline = "%s%s;echo -n '--> Press enter to continue...';read yesno\"</dev/stdin" % (s, palmbuildline.replace("\"","\'"))
343       
344        mString = "xterm %s" % (palmbuildline)
345        palmbuild.start(mString)
346   
347        if( palmbuild.waitForStarted() is False ):
348            return
349       
350        # Wait until palmbuild has finished or wait for 200 minutes
351        palmbuild.waitForFinished(3600000)       
352       
353         
354       
355        # Enable main window again
356        self.tabWidget.setEnabled(True)
357        self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setEnabled(True)
358        self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setEnabled(True)
359        self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setText("palmrun")
360        self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").setText(palmrunline_save)
361        self.group_execution.findChild(QtWidgets.QPushButton,"button_palmbuild").setText("(re-)build")
362        # Reload recent jobs
363        self.recent_jobs(50)
364
365    # loads recent jobs
366    ######################################
367    def recent_jobs(self, number):
368        fileDir = "%s/.palmrungui.history" % (palm_dir)
369        if os.path.exists(fileDir):
370            pass
371        else:
372            return
373
374        file = open(fileDir,"r")
375        history = file.readlines()
376        tmphistory = list()
377        tmptag = list()
378        file.close()
379        j = 0
380
381        list_jobname = self.group_history.findChild(QtWidgets.QListWidget,"list_jobname")
382        list_jobname.clear()
383
384        # Read history entries and append to recent job list
385        i=len(history)-1
386        count = 0
387        while i>=0 and count<number:
388            timestamp = history[i][:16]
389            listitem = history[i][17:len(history[i])-1]
390            tagitem = listitem
391            configitem = listitem
392            matchitems = list_jobname.findItems(listitem, QtCore.Qt.MatchExactly)
393
394            if ( len(matchitems) == 0 ):
395                listitem = list(filter(None,listitem.split(" -r")))[1]
396                listitem = listitem.strip()
397                listitem = list(filter(None,listitem.split(" ")))[0]
398                listitem = listitem.replace("\"","") 
399                list_jobname.addItem(listitem)
400               
401                configitem = list(filter(None,configitem.split(" -c")))
402                if ( len(configitem) < 2):
403                   count = count +1
404                   continue
405                else:
406                   configitem = configitem[1].strip()
407                configitem = list(filter(None,configitem.split(" ")))[0]
408                configitem = configitem.replace("\"","") 
409
410                s = "%s: %s (%s)" % (timestamp,listitem,configitem)
411                tmphistory.append(s)
412               
413               
414                tagitem = list(filter(None,tagitem.split(" (")))[1]
415                tagitem = tagitem.replace(")","") 
416                if ( len(tagitem) == 0 ): 
417                   s = "Tag: empty"
418                else:
419                   s = "Tag: %s" % (tagitem)               
420                tmptag.append(s)
421                count = count +1
422
423                j = j+1
424               
425            if ( j == number ):
426                break
427            i = i-1
428           
429        # Send to list
430        list_jobname.clear()
431       
432        i=0
433        while i<len(tmphistory):
434            list_jobname.addItem(tmphistory[i])
435            list_jobname.item(i).setToolTip(tmptag[i])
436            i = i+1
437           
438
439    # Enables coupled settings
440    ###############################
441    def enable_coupled(self):
442        coupledState = self.group_execution.findChild(QtWidgets.QComboBox, "drop_job").currentText()
443        group = self.group_execution.findChild(QtWidgets.QGroupBox, "group_coupled")
444       
445        if (coupledState == "Restart run (coupled atmosphere ocean)" or coupledState == "Initial run (coupled atmosphere ocean)"):
446            self.group_coupled.setEnabled(True)
447        else: 
448            self.group_coupled.setEnabled(False)
449           
450
451    # select a job via click from list
452    #################################
453    def choosejob_list(self):
454        #  Get selected item from list
455        list_jobname = self.group_history.findChild(QtWidgets.QListWidget,"list_jobname")
456        filename = str(list_jobname.currentItem().text())
457
458        timestamp = filename[:16]
459        jobname = filename[18:].split(" ")[0]
460
461        itemint = list_jobname.currentRow()
462
463        # Reload list
464        self.recent_jobs(50)
465        self.load_jobs()
466   
467        # Set selected item to jobname
468        list_jobname.item(itemint).setSelected(True)
469   
470        # Set selected item to jobname in "available jobs" list
471        item2int = self.list_jobs.findItems(jobname,QtCore.Qt.MatchCaseSensitive)
472       
473        if ( item2int != [] ):
474           self.list_jobs.setCurrentItem(item2int[0])
475        self.update_input()
476           
477   
478        fileDir = "%s/.palmrungui.history" % (palm_dir)
479        file = open(fileDir,"r")
480        history = file.readlines()
481        tmphistory = list()
482        file.close()       
483   
484        i = len(history)
485        while i>=1:
486            listitem = history[i-1][17:len(history[i-1])-1]
487            listitem = list(filter(None,listitem.split(" -r")))[1]
488            listitem = listitem.strip()
489            listitem = list(filter(None,listitem.split(" ")))[0]
490            listitem = listitem.replace("\"","") 
491
492            # Select command line with correct timestamp and jobname
493            if (history[i-1][:16] == timestamp and listitem == jobname):
494                palmrunline = history[i-1]
495                palmrunline = palmrunline[17:]
496                palmrunline = palmrunline[:len(palmrunline)-1]
497                palmrunline = list(filter(None,palmrunline.split("(")))[0]
498                self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").setText(palmrunline)
499               
500             
501                tag = history[i-1].split('\n')[0]
502                tag = list(filter(None,tag.split("(")))[1]
503                tag = tag.replace(")","")
504
505                self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setText(tag)
506                self.setup_gui(palmrunline)
507                self.list_jobname.item(itemint).setSelected(True)   
508               
509                return
510            i = i-1
511               
512    # Change run identifer (initial, restart, coupled...)
513    ######################################################
514    def change_rc_list(self):
515        drop_job = self.group_execution.findChild(QtWidgets.QComboBox,"drop_job").currentText()
516        self.change_commandline("a","")
517   
518        # Enable PE distribution for atmosphere/ocean
519        if ( drop_job == "Restart run (coupled atmosphere ocean)" or drop_job == "Initial run (coupled atmosphere ocean)"):
520            drop_atmos = self.group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_atmos").text()
521            drop_ocean = self.group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_ocean").text()
522            s = "%s %s" % (drop_atmos,drop_ocean)
523            self.change_commandline("Y",s)
524   
525   
526        if ( drop_job == "Restart run" or drop_job == "Restart run (coupled atmosphere ocean)"):
527           self.change_commandline("r","")
528
529        # Check of ocean runs
530        else:
531            self.delete_commandline("Y")
532            if (drop_job == "Precursor run (ocean)"):
533                self.activate_flag("y")
534            else:
535                self.deactivate_flag("y")
536           
537    # changes commandline depending on parameters
538    ##########################################################     
539    def change_commandline(self, id_str, fwt_str):
540        fwt_str = str(fwt_str) 
541        initialize = False
542        palmrunline = str(self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").text())
543        s = " -%s " % (id_str)
544        splitline = list(filter(None,palmrunline.split(s)))
545
546        if ( len(splitline) == 0 ):
547                splitline.append("palmrun")
548                splitline.append(" ")
549                initialize = True
550
551        elif ( len(splitline) == 1 ):
552            splitline.append(" ")
553       
554        param = splitline[1].split("-")
555   
556        # Change in parameter "r" (jobname)
557        if (id_str == "r"):
558            filename = str(self.group_execution.findChild(QtWidgets.QLineEdit,"line_jobname").text())
559            s = filename.split("JOBS/") 
560            param[0] = s[len(s)-1]
561     
562            if ( initialize == True ):#and self.group_runcontrol.isEnabled() == True ):
563                self.group_execution.setEnabled(True)
564                self.group_execution.findChild(QtWidgets.QComboBox,"drop_job").setEnabled(True)
565                self.group_advanced.setEnabled(True)
566                self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setEnabled(True)
567                self.menuBar.findChild(QtWidgets.QMenu,"menuStart").actions()[3].setEnabled(True)
568                self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setEnabled(True)
569           
570            elif ( param[0] == ""):           
571                self.group_execution.setEnabled(False)
572                self.group_execution.findChild(QtWidgets.QComboBox,"drop_job").setEnabled(False)
573                self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setEnabled(False)
574                self.menuBar.findChild(QtWidgets.QMenu,"menuStart").actions()[3].setEnabled(False)
575                self.group_advanced.setEnabled(False)
576                self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setEnabled(True)
577                self.delete_commandline("r")
578                self.change_commandline("a","remove")
579                return 1 
580           
581            else:
582
583                self.group_execution.setEnabled(True)
584                self.drop_job.setEnabled(True)
585                self.group_advanced.setEnabled(True)
586                   
587        # Change in parameter "a" (run control list)
588        elif (id_str == "a"): 
589   
590            drop_job = self.group_execution.findChild(QtWidgets.QComboBox,"drop_job").currentText()
591            rc_flag = "#"
592   
593            if (drop_job == "Initial run"):
594                rc_flag = "#"
595           
596            elif (drop_job == "Restart run"):           
597                rc_flag = "r"
598           
599            elif (drop_job == "Precursor run (atmosphere)"):           
600                rc_flag = "#"
601           
602            elif (drop_job == "Precursor run (ocean)"):           
603                rc_flag = "o#"
604
605            elif (drop_job == "Initial run (coupled atmosphere ocean)"):           
606                rc_flag = "#"
607           
608            elif (drop_job == "Restart run (coupled atmosphere ocean)"):           
609                rc_flag = "r"
610           
611            param[0] = "\"d3%s" % (rc_flag)
612   
613   
614            if (drop_job == "Restart run (coupled atmosphere ocean)" or drop_job == "Initial run (coupled atmosphere ocean)"):
615                if (rc_flag == "#"):
616                   rc_flag = "o#"
617                else:
618                   rc_flag = "or"
619
620                param[0] = "%s d3%s" % (param[0],rc_flag)
621   
622            status_restarts = self.group_execution.findChild(QtWidgets.QCheckBox,"check_restarts").checkState()
623
624            if (status_restarts == 2):
625                param[0]="%s restart" % (param[0])
626
627
628            status_cycfill = self.group_execution.findChild(QtWidgets.QCheckBox,"check_cycfill").checkState()
629   
630            if (status_cycfill == 2):           
631                param[0]="%s rec" % (param[0])
632
633            status_svf = self.group_execution.findChild(QtWidgets.QCheckBox,"check_svf").checkState()
634
635            if (status_svf == 2):           
636               param[0]="%s svfin" % (param[0])
637 
638            status_svf_2 = self.group_execution.findChild(QtWidgets.QCheckBox,"check_svf_2").checkState()
639
640            if (status_svf_2 == 2):
641               param[0]="%s svfout" % (param[0])
642
643            param[0]="%s\"" % (param[0])
644
645            if ( fwt_str == "remove"):           
646                self.delete_commandline(id_str)
647                return 1
648           
649            else:           
650                self.button_start.setEnabled(True)
651                self.action_save.setEnabled(True)
652                self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setEnabled(True)
653
654        # Change in any other parameter
655        else:
656            if ( fwt_str != ""):           
657                param[0] = "\"%s\"" % (fwt_str)
658           
659            else:           
660                self.delete_commandline(id_str)
661                return 1
662                       
663        # Join the new palmrunline
664        splitline[1]= " -".join(param)
665               
666               
667        s = " -%s " % (id_str)
668        newpalmrunline = s.join(splitline)
669   
670        # Print the new palmrunline to mainwindow
671        newpalmrunline = newpalmrunline.replace("  "," ")
672        self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").setText(newpalmrunline)
673
674    # change lineinput depending on sender
675    ###################################################################################
676    def change_lineinput(self):
677        if ( self.sender() == self.group_execution.findChild(QtWidgets.QComboBox, "combo_configuration") ):
678            tmptext = self.group_execution.findChild(QtWidgets.QComboBox, "combo_configuration").currentText()
679            if not tmptext:
680               self.change_commandline("c"," ")
681               self.group_execution.findChild(QtWidgets.QPushButton,'button_palmbuild').setEnabled(False)
682            else:
683               self.change_commandline("c",tmptext)
684               self.group_execution.findChild(QtWidgets.QPushButton,'button_palmbuild').setEnabled(True)
685
686        elif ( self.sender() == self.group_execution.findChild(QtWidgets.QLineEdit,"line_q")):
687            tmptext = self.group_execution.findChild(QtWidgets.QLineEdit,"line_q").text()
688            self.change_commandline("q",tmptext)
689       
690        elif ( self.sender() == self.group_execution.findChild(QtWidgets.QLineEdit,"line_account")):
691            tmptext = self.group_execution.findChild(QtWidgets.QLineEdit,"line_account").text()
692            self.change_commandline("A",tmptext)
693       
694        elif ( self.sender() ==  self.group_execution.findChild(QtWidgets.QLineEdit,"line_pe")):
695            tmptext = self.group_execution.findChild(QtWidgets.QLineEdit,"line_pe").text()
696            self.change_commandline("X",tmptext)
697       
698        elif ( self.sender() == self.group_execution.findChild(QtWidgets.QLineEdit,"line_tpn")):
699            tmptext = self.group_execution.findChild(QtWidgets.QLineEdit,"line_tpn").text()
700            self.change_commandline("T",tmptext)
701               
702        elif ( self.sender() == self.group_execution.findChild(QtWidgets.QLineEdit,"line_time")):
703            tmptext = self.group_execution.findChild(QtWidgets.QLineEdit,"line_time").text()
704            self.change_commandline("t",tmptext)
705       
706        elif ( self.sender() == self.group_advanced.findChild(QtWidgets.QLineEdit,"line_M")):
707            tmptext = self.group_advanced.findChild(QtWidgets.QLineEdit,"line_M").text()
708            self.change_commandline("M",tmptext)
709       
710        elif ( self.sender() == self.group_advanced.findChild(QtWidgets.QLineEdit,"line_m")):
711            tmptext = self.group_advanced.findChild(QtWidgets.QLineEdit,"line_m").text()
712            self.change_commandline("m",tmptext)
713       
714        elif ( self.sender() == self.group_advanced.findChild(QtWidgets.QLineEdit,"line_D")):
715            tmptext = self.group_advanced.findChild(QtWidgets.QLineEdit,"line_D").text()
716            self.change_commandline("D",tmptext)
717       
718        elif ( self.sender() == self.group_advanced.findChild(QtWidgets.QLineEdit,"line_c")):
719            tmptext = self.group_advanced.findChild(QtWidgets.QLineEdit,"line_c").text()
720            if ( tmptext == ".palmrungui.config"):
721                tmptext = ""
722            self.change_commandline("c",tmptext)
723       
724        elif ( self.sender() == self.group_advanced.findChild(QtWidgets.QLineEdit,"line_s")):
725            tmptext = self.group_advanced.findChild(QtWidgets.QLineEdit,"line_s").text()
726            self.change_commandline("s",tmptext)
727               
728        elif ( self.sender() == self.group_advanced.findChild(QtWidgets.QLineEdit,"line_w")):
729            tmptext = self.group_advanced.findChild(QtWidgets.QLineEdit,"line_w").text()
730            self.change_commandline("w",tmptext)
731       
732        elif ( self.sender() == self.group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_atmos") or
733               self.sender() == self.group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_ocean")):
734            t1 = self.group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_atmos").text()
735            t2 = self.group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_ocean").text()
736            tmptext = "%s %s" % (t1,t2)
737           
738            self.change_commandline("Y",tmptext)
739
740            # try catch sowas in der art
741            pe1 = 0
742            pe2 = 0
743           
744            try:
745                pe1 = int(t1)
746            except ValueError:           
747                pass
748
749            try:
750                pe2 = int(t2)
751            except ValueError:
752                pass
753
754            PE_total = pe1+pe2   
755            self.group_execution.findChild(QtWidgets.QLineEdit,"line_pe").setText(str(PE_total))
756            self.change_commandline("X",str(PE_total))
757
758    # deletes parameter from commandline
759    #####################################################################################
760    def delete_commandline(self, id_str):   
761        # Read palmrunline
762        commandline = self.groupBox.findChild(QtWidgets.QLineEdit,"commandline")
763        palmrunline = str(commandline.text())
764        s = " -%s" % (id_str)
765        splitline = list(filter(None,palmrunline.split(s)))
766       
767        if ( len(splitline) == 1):
768            return 1
769        else:
770            param = splitline[1].split("-")
771            param[0] = ""
772            splitline[1]= " -".join(param)
773            newpalmrunline = "".join(splitline)
774            newpalmrunline = newpalmrunline.replace("  "," ")
775   
776            # Print new palmrunline to screen
777            commandline.setText(newpalmrunline)
778       
779    # controls flags
780    ###################################################################################
781    def check_flags(self):
782        status = self.group_execution.findChild(QtWidgets.QCheckBox,"check_delete_tmp_files" ).checkState()
783        if (status == 2):     
784            self.activate_flag("B")
785        else:
786            self.deactivate_flag("B")
787   
788        status = self.group_execution.findChild(QtWidgets.QCheckBox,"check_verbose" ).checkState()
789        if (status == 2):
790            self.activate_flag("v") 
791        else:
792            self.deactivate_flag("v")
793       
794        status = self.group_advanced.findChild(QtWidgets.QCheckBox,"check_b" ).checkState()
795        if (status == 2):
796            self.activate_flag("b")
797        else:
798            self.deactivate_flag("b")
799   
800        status = self.group_advanced.findChild(QtWidgets.QCheckBox,"check_F" ).checkState()
801        if (status == 2):
802            self.activate_flag("F")
803        else:
804            self.deactivate_flag("F")
805           
806        status = self.group_advanced.findChild(QtWidgets.QCheckBox,"check_I" ).checkState()
807        if (status == 2):
808            self.activate_flag("I")
809        else:
810            self.deactivate_flag("I")
811
812        status = self.group_advanced.findChild(QtWidgets.QCheckBox,"check_k" ).checkState()
813        if (status == 2):
814            self.activate_flag("k")
815        else:
816            self.deactivate_flag("k")
817
818        status = self.group_advanced.findChild(QtWidgets.QCheckBox,"check_O" ).checkState()
819        if (status == 2):
820            self.activate_flag("O")
821        else:
822            self.deactivate_flag("O")
823
824        status = self.group_execution.findChild(QtWidgets.QCheckBox,"check_prebuilt" ).checkState()
825        if (status == 2):
826            self.activate_flag("V")
827        else:
828            self.deactivate_flag("V")
829
830        status = self.group_advanced.findChild(QtWidgets.QCheckBox,"check_x" ).checkState()
831        if (status == 2):
832            self.activate_flag("x")
833        else:
834            self.deactivate_flag("x")
835       
836        status = self.group_advanced.findChild(QtWidgets.QCheckBox,"check_Z" ).checkState()
837        if (status == 2):
838            self.activate_flag("Z")
839        else:
840            self.deactivate_flag("Z")
841       
842    # changes flag to parameter
843    ##################################################################################   
844    def activate_flag(self, id_str):
845        commandline = self.groupBox.findChild(QtWidgets.QLineEdit,"commandline")
846        palmrunline = str(commandline.text())
847        s = " -%s" % (id_str)
848        splitline = list(filter(None,palmrunline.split(s)))
849       
850        if ( len(splitline) == 1):
851            splitline.append("")
852            s = " -%s" % (id_str)
853            newpalmrunline = s.join(splitline)
854            newpalmrunline = newpalmrunline.replace("  "," ")
855            commandline.setText(newpalmrunline)               
856       
857    # deletes flag in commandline
858    ####################################################################################   
859    def deactivate_flag(self, id_str):
860        commandline = self.groupBox.findChild(QtWidgets.QLineEdit,"commandline")
861        palmrunline = str(commandline.text())
862        s = " -%s" % (id_str)
863        splitline = list(filter(None,palmrunline.split(s)))
864 
865        newpalmrunline = "".join(splitline)
866        newpalmrunline = newpalmrunline.replace("  "," ")
867        commandline.setText(newpalmrunline)     
868
869    # Clears window
870    #################################################################################
871    def reset_window(self):
872        self.setupUi(self)
873        self.tabWidget.setCurrentIndex(0)
874        self.palm_logo.setPixmap(QtGui.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png"))
875        self.recent_jobs(50)
876        self.load_jobs()
877       
878
879    # Safes current commandline and user parameters to default file
880    ################################################################################
881    def save_default(self):
882        string_to_file = self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").text()
883
884        filename ="%s/.palmrungui.default" % (palm_dir)
885        tmstamp = strftime("%Y/%m/%d %H:%M")
886
887        file = open(filename,"w")
888        s = "%s %s" % (tmstamp, string_to_file)
889        file.write(s)
890        file.close()       
891
892       
893    # Executes command which starts watchdog (start palm_wd)
894    ########################################################
895    def start_watchdog(self):
896        subprocess.Popen(["nohup","palm_wd",">>","/dev/null", "2>&1","&"])
897
898    # Opens "help" dialog
899    #################################
900    def help(self):       
901        dialog = HelpDialog()
902        dialog.exec_()
903
904    # Opens "about" dialog
905    ##################################
906    def about_gui(self):
907        dialog = AboutDialog()
908        dialog.exec_()
909
910    # commandline to buttons etc
911    ##############################
912    def setup_gui(self, palmrun_str): 
913     
914        #self.palm_logo.setPixmap(QtWidgets.QPixmap(palm_dir + "/trunk/SCRIPTS/palmrungui_files/logo.png"))
915     
916        #  Some initial settings
917        coupled_run = False 
918        ocean_run   = False 
919        nojob       = False 
920
921        #Split parameters in palmrunline
922        splitline = palmrun_str.split(" -")
923       
924        if ( splitline[0] != "palmrun"):
925            return 1
926
927        else:
928            self.group_execution.setEnabled(True) 
929
930        # Loop for all parameters in palmrunline
931        i = len(splitline)-1
932        while i >= 1:
933
934            # Determine parameter
935            splitparameter = splitline[i].split(" ")
936
937            parameter = splitparameter[0] 
938            splitparameter.pop(0)
939            options = " ".join(splitparameter) 
940            options = options.replace("\"","") 
941
942            # Check for suitable switch
943            if ( parameter == "r"):
944             
945                if ( options != ""):
946                    self.group_execution.findChild(QtWidgets.QLineEdit,"line_jobname").setText(options)
947                    nojob = False 
948               
949                else:                 
950                    nojob = True 
951               
952            elif ( parameter == "c"):
953                tmpindex = self.group_execution.findChild(QtWidgets.QComboBox, "combo_configuration").findText(options.strip(),QtCore.Qt.MatchExactly)
954                if tmpindex != -1: 
955                   self.group_execution.findChild(QtWidgets.QComboBox, "combo_configuration").setCurrentIndex(tmpindex)
956                else:
957                   self.group_execution.findChild(QtWidgets.QComboBox, "combo_configuration").setCurrentIndex(0)
958            elif ( parameter == "q"):
959                self.group_execution.findChild(QtWidgets.QLineEdit,"line_q").setText(options)
960             
961            elif ( parameter == "A"):
962                self.group_execution.findChild(QtWidgets.QLineEdit,"line_account").setText(options)
963             
964            elif ( parameter == "X"):
965                self.group_execution.findChild(QtWidgets.QLineEdit,"line_pe").setText(options)
966             
967            elif ( parameter == "T"):
968                self.group_execution.findChild(QtWidgets.QLineEdit,"line_tpn").setText(options)
969             
970            elif ( parameter == "t"):
971                self.group_execution.findChild(QtWidgets.QLineEdit,"line_time").setText(options)
972             
973            elif ( parameter == "B"):
974                self.group_execution.findChild(QtWidgets.QCheckBox,"check_delete_tmp_files").setChecked(True)
975             
976            elif ( parameter == "v"):
977                self.group_execution.findChild(QtWidgets.QCheckBox,"check_verbose").setChecked(True)
978                         
979            elif ( parameter == "b"): 
980                self.group_advanced.findChild(QtWidgets.QCheckBox,"check_b").setChecked(True)
981             
982            elif ( parameter == "F"):
983                self.group_advanced.findChild(QtWidgets.QCheckBox,"check_F").setChecked(True)
984             
985            elif ( parameter == "I"):
986                self.group_advanced.findChild(QtWidgets.QCheckBox,"check_I").setChecked(True)
987             
988            elif ( parameter == "k"):
989                self.group_advanced.findChild(QtWidgets.QCheckBox,"check_k").setChecked(True)
990             
991            elif ( parameter == "O"): 
992                self.group_advanced.findChild(QtWidgets.QCheckBox,"check_O").setChecked(True)
993
994            elif ( parameter == "V"):
995                self.group_execution.findChild(QtWidgets.QCheckBox,"check_prebuilt").setChecked(True)
996
997            elif ( parameter == "x"):             
998                self.group_advanced.findChild(QtWidgets.QCheckBox,"check_x").setChecked(True)
999
1000            elif ( parameter == "Z"):
1001                self.group_advanced.findChild(QtWidgets.QCheckBox,"check_Z").setChecked(True)
1002               
1003            elif ( parameter == "m"):
1004                self.group_advanced.findChild(QtWidgets.QLineEdit,"line_m").setText(options)
1005             
1006            elif ( parameter == "M"):
1007                self.group_advanced.findChild(QtWidgets.QLineEdit,"line_M").setText(options)
1008                         
1009            elif ( parameter == "D"):
1010                self.group_advanced.findChild(QtWidgets.QLineEdit,"line_D").setText(options)
1011             
1012            elif ( parameter == "c"):
1013                self.group_advanced.findChild(QtWidgets.QLineEdit,"line_c").setText(options)
1014                         
1015            elif ( parameter == "s"):
1016                self.group_advanced.findChild(QtWidgets.QLineEdit,"line_s").setText(options)
1017             
1018            elif ( parameter == "w"):
1019                self.group_advanced.findChild(QtWidgets.QLineEdit,"line_w").setText(options)
1020             
1021
1022            # Determine settings for coupled restart runs
1023            elif ( parameter == "Y"):
1024                optionssplit = options.split(" ") 
1025               
1026                group_coupled = self.group_execution.findChild(QtWidgets.QGroupBox,"group_coupled")
1027                group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_atmos").setEnabled(True)
1028                group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_ocean").setEnabled(True)
1029                group_coupled.findChild(QtWidgets.QLabel,"label_coupled1").setEnabled(True)
1030                group_coupled.findChild(QtWidgets.QLabel,"label_coupled2").setEnabled(True)
1031                group_coupled.findChild(QtWidgets.QLabel,"label_coupled3").setEnabled(True)
1032                group_coupled.findChild(QtWidgets.QLabel,"label_coupling").setEnabled(True)
1033
1034                if (optionssplit.count() == 2):
1035                    group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_atmos").setEnabled(optionssplit[0])
1036                    group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_ocean").setEnabled(optionssplit[1])
1037                 
1038                else:                 
1039                    group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_atmos").setText("")
1040                    group_coupled.findChild(QtWidgets.QLineEdit,"line_PE_ocean").setText("")
1041 
1042                 
1043                coupled_run = True 
1044           
1045            elif ( parameter == "y"):             
1046                self.group_execution.findChild(QtWidgets.QComboBox, "drop_job").setCurrentIndex(3)
1047             
1048
1049            # Determine settings for the run control list
1050            elif ( parameter == "a"):
1051             
1052                optionssplit = options.split(" ") 
1053
1054                options_2 = None
1055                options_all = None
1056               
1057                j = 0
1058                while j < len(optionssplit):
1059                 
1060                    options_all = optionssplit[j] 
1061                    options_2 = optionssplit[j][:2] 
1062                                             
1063                    if (options_2 == "d3"):     
1064                        if (options_all[:3][-1] == "#"):
1065                            self.group_execution.findChild(QtWidgets.QComboBox, "drop_job").setCurrentIndex(0)
1066                        elif (options_all[:3][-1] == "r"):
1067                            self.group_execution.findChild(QtWidgets.QComboBox, "drop_job").setCurrentIndex(1)
1068                       
1069                        elif (options_all[:3][-1] == "o"):
1070                            ocean_run = True 
1071                       
1072                    if (options_all == "restart"):
1073                        self.group_execution.findChild(QtWidgets.QCheckBox,"check_restarts").setChecked(True)
1074
1075                    j = j+1
1076            i = i-1
1077        # Change drop box state in case of ocean precursor or coupled restart runs
1078        if ( ocean_run == True ):
1079            if ( coupled_run == True ):
1080                self.group_execution.findChild(QtWidgets.QComboBox, "drop_job").setCurrentIndex(4)
1081           
1082            else:
1083                self.group_execution.findChild(QtWidgets.QComboBox, "drop_job").setCurrentIndex(3)
1084
1085        # Join palmrunline and post it to mainwindow
1086        palmrunline = " -".join(splitline) 
1087        self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").setText(palmrunline)
1088
1089        # Disable mainwindow if no job was found, otherwise enable
1090        if ( nojob == True ):
1091            self.group_execution.setEnabled(False) 
1092            self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setEnabled(False)
1093            self.menuBar.findChild(QtWidgets.QMenu,"menuStart").actions()[3].setEnabled(False)
1094            self.group_execution.findChild(QtWidgets.QComboBox, "drop_job").setEnabled(False)
1095            self.group_advanced.setEnabled(False) 
1096            self.check_advanced.setEnabled(False) 
1097            self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setEnabled(False)
1098         
1099        else:
1100            self.group_execution.setEnabled(True) 
1101            self.groupBox.findChild(QtWidgets.QPushButton,"button_start").setEnabled(True)
1102            self.menuBar.findChild(QtWidgets.QMenu,"menuStart").actions()[3].setEnabled(True)
1103            self.group_execution.findChild(QtWidgets.QComboBox, "drop_job").setEnabled(True)
1104            self.group_advanced.setEnabled(True) 
1105            self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setEnabled(True)
1106
1107
1108        self.tabWidget.setCurrentIndex(0)
1109
1110
1111    ## Open from history
1112    ###################################
1113    def open_from_file(self):
1114
1115#      Show History
1116       opt = OpenHistoryBox()
1117       opt.exec_()
1118
1119       if ( history_entry != "" ):
1120          palmrunline = str(history_entry)
1121          palmrunline = palmrunline[17:]
1122          palmrunline = palmrunline[:len(palmrunline)-1]
1123          palmrunline = list(filter(None,palmrunline.split("(")))[0]
1124          self.groupBox.findChild(QtWidgets.QLineEdit,"commandline").setText(palmrunline)
1125
1126#         Set selected item to jobname in "available jobs" list
1127          jobname = str(history_entry[17:])
1128          jobname = list(filter(None,jobname.split(" -r")))[1]
1129          jobname = jobname.strip()
1130          jobname = list(filter(None,jobname.split(" ")))[0]
1131          jobname = jobname.replace("\"","")
1132          item2int = self.list_jobs.findItems(jobname,QtCore.Qt.MatchCaseSensitive)
1133
1134          if ( item2int != [] ):
1135             self.list_jobs.setCurrentItem(item2int[0])
1136             self.update_input()
1137
1138#         Add tooltip tag
1139          tag = str(history_entry).split('\n')[0]
1140          tag = list(filter(None,tag.split("(")))[1]
1141          tag = tag.replace(")","")
1142          self.groupBox.findChild(QtWidgets.QLineEdit,"line_tag").setText(tag)
1143 
1144#         Process palmrungui to set up gui controls
1145          self.setup_gui(palmrunline)
1146
1147
1148    def update_all(self):
1149 
1150       self.setEnabled(False)
1151       self.list_input.clear() 
1152       self.list_user.clear()
1153       self.list_monitoring.clear()
1154       self.list_output.clear()
1155       self.load_jobs()
1156       self.setEnabled(True)
1157       self.update_input()
1158
1159
1160    # Load jobs into list
1161    def load_jobs(self):
1162       
1163       selected_job = self.list_jobs.currentItem()
1164       
1165       if ( selected_job is not None ):
1166          jobname = selected_job.text()
1167       else:
1168          jobname = ""
1169
1170       self.list_jobs.clear() 
1171       self.line_path.setText(job_dir + "/")
1172       
1173       list_of_files = os.listdir(job_dir)
1174     
1175
1176       for i in range(0,len(list_of_files)):
1177          tmp_file = job_dir + "/" + list_of_files[i]
1178
1179          if ( os.path.isdir(tmp_file) ):
1180             self.list_jobs.addItem(str(list_of_files[i]))
1181       
1182
1183
1184       item2int = self.list_jobs.findItems(jobname,QtCore.Qt.MatchCaseSensitive)
1185       
1186       if ( item2int != [] ):
1187          self.list_jobs.setCurrentItem(item2int[0])
1188
1189
1190    # Update input and user code lists
1191    def update_input(self):
1192
1193       self.labeltimer.stop() 
1194
1195     
1196       self.list_input.clear() 
1197       self.list_user.clear()
1198       self.list_monitoring.clear()
1199       self.list_output.clear()
1200       
1201       jobitem = self.list_jobs.currentItem()
1202       
1203       if ( jobitem != None ):
1204       
1205          job_to_show = job_dir + "/" + jobitem.text() + "/INPUT"
1206
1207          if ( os.path.isdir(job_to_show) ):
1208
1209             list_of_files = os.listdir(job_to_show)
1210         
1211             for i in range(0,len(list_of_files)):
1212                tmp_file = job_to_show + "/" + list_of_files[i]
1213             
1214                if ( os.path.isfile(tmp_file) ):
1215                   self.list_input.addItem(str(list_of_files[i]) + " (" + file_size(tmp_file) + ")")
1216 
1217          job_to_show = job_dir + "/" + jobitem.text() + "/USER_CODE"
1218       
1219          if ( os.path.isdir(job_to_show) ):
1220         
1221             list_of_files = os.listdir(job_to_show)
1222         
1223             for i in range(0,len(list_of_files)):
1224                tmp_file = job_to_show + "/" + list_of_files[i]
1225
1226                if ( os.path.isfile(tmp_file) ):
1227                   self.list_user.addItem(str(list_of_files[i]))
1228
1229          job_to_show = job_dir + "/" + jobitem.text() + "/MONITORING"
1230       
1231          if ( os.path.isdir(job_to_show) ):
1232         
1233             list_of_files = os.listdir(job_to_show)
1234         
1235             for i in range(0,len(list_of_files)):
1236                tmp_file = job_to_show + "/" + list_of_files[i]
1237
1238                if ( os.path.isfile(tmp_file) ):
1239                   self.list_monitoring.addItem(str(list_of_files[i]) + " (" + file_size(tmp_file) + ")")
1240
1241          job_to_show = job_dir + "/" + jobitem.text() + "/OUTPUT"
1242
1243          if ( os.path.isdir(job_to_show) ):
1244
1245             list_of_files = os.listdir(job_to_show)
1246
1247             for i in range(0,len(list_of_files)):
1248                tmp_file = job_to_show + "/" + list_of_files[i]
1249
1250                if ( os.path.isfile(tmp_file) ):
1251                   self.list_output.addItem(str(list_of_files[i]) + " (" + file_size(tmp_file) + ")")
1252 
1253          self.group_execution.findChild(QtWidgets.QLineEdit,"line_jobname").setText(jobitem.text())
1254       self.group_history.findChild(QtWidgets.QListWidget,"list_jobname").clearSelection()
1255
1256       self.timetimer.start()
1257       self.timer.start(update_frequency)
1258       self.labeltimer.start(update_frequency/10)
1259       self.push_update.setText("Update (" + str(int(update_frequency/1000/60)) + " min)")
1260       QtWidgets.QApplication.processEvents()
1261
1262       # Change palmrunline accordingly
1263       self.change_commandline("r","")
1264       self.change_commandline("a","") 
1265
1266    # Create a new (empty) job
1267    def create_new_job(self):
1268
1269       self.setEnabled(False)
1270
1271       text, ret = QtWidgets.QInputDialog.getText(self, "Create new job", "Enter new job name:", QtWidgets.QLineEdit.Normal, text = '')
1272
1273       if ( ret ):
1274          new_job_name = str(text)
1275       else:
1276          self.setEnabled(True)
1277          return
1278
1279       new_input_dir  = job_dir + "/" + new_job_name + "/INPUT"
1280
1281#      check if a job exists with the new job name. If not, the new job is created and an empty _p3d file is created.
1282       if ( os.path.isdir(new_input_dir) ):
1283          notify = QtWidgets.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.")
1284          self.setEnabled(True)
1285          return
1286       else:
1287          os.makedirs(new_input_dir)
1288          os.mknod(new_input_dir + '/' + new_job_name + '_p3d')
1289
1290#      write default namelists into _p3d file
1291       filename = open(new_input_dir + '/' + new_job_name + '_p3d', "w")
1292       filename.write('&initialization_parameters\n    nx = 39,\n    ny = 39,\n    nz = 40,\n    dx = 50.0,\n    dy = 50.0,\n    dz = 50.0,\n/\n\n')
1293       filename.write('&runtime_parameters\n    end_time = 3600.0,\n/\n')
1294       filename.close()
1295
1296
1297#      create empty USER_CODE folder for convenience
1298       new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
1299       os.makedirs(new_user_dir)
1300
1301
1302       self.load_jobs()
1303       self.list_input.clear()
1304       self.list_user.clear()
1305       self.list_monitoring.clear()
1306       self.list_output.clear()
1307       self.setEnabled(True)
1308
1309
1310    # Make a copy of a job
1311    def copy_job(self):
1312
1313       self.setEnabled(False)
1314       old_job_name = self.list_jobs.currentItem().text()
1315       
1316       text, ret = QtWidgets.QInputDialog.getText(self, "Copy job", "Enter new job name:", QtWidgets.QLineEdit.Normal, text = old_job_name)
1317       if ( ret ):
1318          new_job_name = str(text)
1319       else:
1320          self.setEnabled(True)
1321          return
1322
1323       new_input_dir  = job_dir + "/" + new_job_name + "/INPUT"
1324
1325#      check if a job exists with the new job name 
1326       if ( os.path.isdir(new_input_dir) ):
1327          notify = QtWidgets.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.")
1328          self.setEnabled(True)
1329          return
1330       else:
1331          os.makedirs(new_input_dir)
1332
1333#      copy and rename input files (if present)       
1334       job_to_copy = job_dir + "/" + old_job_name + "/INPUT"
1335
1336       if ( os.path.isdir(job_to_copy) ):
1337
1338          list_of_files = os.listdir(job_to_copy)
1339
1340          for i in range(0,len(list_of_files)):
1341
1342             tmp_file = job_to_copy + "/" + list_of_files[i]         
1343             new_file = new_input_dir + "/" + list_of_files[i].replace(old_job_name, new_job_name)
1344             shutil.copy(tmp_file, new_file)
1345
1346
1347
1348
1349       new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
1350
1351#      check if user code exists in the new job directory
1352       if ( os.path.isdir(new_user_dir) ):
1353          notify = QtWidgets.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.")
1354          self.setEnabled(True)
1355          return
1356       else:
1357          os.makedirs(new_user_dir)
1358
1359
1360#      copy user code files (if present)       
1361       user_to_copy = job_dir + "/" + old_job_name + "/USER_CODE"
1362
1363       if ( os.path.isdir(user_to_copy) ):
1364
1365          list_of_files = os.listdir(user_to_copy)
1366         
1367          for i in range(0,len(list_of_files)):
1368
1369             tmp_file = user_to_copy + "/" + list_of_files[i]         
1370             new_file = new_user_dir + "/" + list_of_files[i]
1371             shutil.copy(tmp_file, new_file)
1372
1373       self.load_jobs()
1374       self.list_input.clear() 
1375       self.list_user.clear()
1376       self.list_monitoring.clear()
1377       self.list_output.clear()
1378       self.setEnabled(True)
1379
1380
1381    # Create a whole set of jobs
1382    def create_set(self):
1383 
1384       global set_list
1385#      disable mainwindow 
1386       self.setEnabled(False)
1387     
1388#      show Options Dialog     
1389       opt = CreateSetBox()
1390       opt.exec_()
1391
1392       old_job_name = self.list_jobs.currentItem().text()
1393
1394       for j in range(0,len(set_list)):
1395
1396          if ( set_list[j] != "" ):
1397             new_job_name   = str(set_list[j])
1398             new_input_dir  = job_dir + "/" + str(set_list[j]) + "/INPUT"
1399          else:
1400             continue
1401
1402#         check if a job exists with the new job name 
1403          if ( os.path.isdir(new_input_dir) ):
1404             notify = QtWidgets.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.")
1405             self.setEnabled(True)
1406             return
1407          else:
1408             os.makedirs(new_input_dir)
1409
1410#         copy and rename input files (if present)       
1411          job_to_copy = job_dir + "/" + old_job_name + "/INPUT"
1412
1413          if ( os.path.isdir(job_to_copy) ):
1414
1415             list_of_files = os.listdir(job_to_copy)
1416         
1417             for i in range(0,len(list_of_files)):
1418
1419                tmp_file = job_to_copy + "/" + list_of_files[i]         
1420                new_file = new_input_dir + "/" + list_of_files[i].replace(old_job_name, new_job_name)
1421                shutil.copy(tmp_file, new_file)
1422
1423
1424          new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
1425
1426#         check if user code exists in the new job directory
1427          if ( os.path.isdir(new_user_dir) ):
1428             notify = QtWidgets.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.")
1429             self.setEnabled(True)
1430             return
1431          else:
1432             os.makedirs(new_user_dir)
1433
1434
1435#         copy user code files (if present)       
1436          user_to_copy = job_dir + "/" + old_job_name + "/USER_CODE"
1437
1438          if ( os.path.isdir(user_to_copy) ):
1439
1440             list_of_files = os.listdir(user_to_copy)
1441         
1442             for i in range(0,len(list_of_files)):
1443
1444                tmp_file = user_to_copy + "/" + list_of_files[i]         
1445                new_file = new_user_dir + "/" + list_of_files[i]
1446                shutil.copy(tmp_file, new_file)
1447
1448          self.load_jobs()
1449          self.list_input.clear() 
1450          self.list_user.clear()
1451          self.list_monitoring.clear()
1452          self.list_output.clear()
1453
1454       self.setEnabled(True) 
1455       set_list = []
1456
1457
1458 # Add a custom context menu for the job selection list
1459    def openmenujob(self, position):
1460
1461        menu = QtWidgets.QMenu()
1462
1463
1464        newAction = QtWidgets.QAction('Create new job', self)
1465        newAction.triggered.connect(self.create_new_job)
1466        menu.addAction(newAction)
1467        selection = self.list_jobs.selectedItems()
1468
1469        if ( len(selection) != 0 ):
1470
1471
1472           copyAction = QtWidgets.QAction('Copy job', self)
1473           copyAction.triggered.connect(self.copy_job)
1474           createAction = QtWidgets.QAction('Create set from job', self)
1475           createAction.triggered.connect(self.create_set)
1476           delAction = QtWidgets.QAction('Delete job', self)
1477           delAction.triggered.connect(self.DeleteJob)
1478
1479           menu.addAction(copyAction)
1480           menu.addAction(createAction)
1481           menu.addAction(delAction)
1482
1483        action = menu.exec_(self.list_jobs.mapToGlobal(position))
1484
1485 # Add a custom context menu
1486    def openmenuinput(self, position):
1487
1488        menu = QtWidgets.QMenu()
1489
1490        selection = self.list_input.selectedItems()
1491       
1492        if ( len(selection) != 0 ):
1493
1494
1495           openAction = QtWidgets.QAction('Open file(s)', self)
1496           openAction.setStatusTip('Open file(s) in your favorite editor')
1497           openAction.triggered.connect(self.OpenFilesInput)
1498
1499
1500           delAction = QtWidgets.QAction('Delete selected file(s)', self)
1501           delAction.triggered.connect(self.DeleteFilesInput)
1502
1503           menu.addAction(openAction)
1504           menu.addAction(delAction)
1505
1506        delallAction = QtWidgets.QAction('Delete all files', self)
1507        delallAction.triggered.connect(self.DeleteAllFilesInput)
1508        menu.addAction(delallAction)
1509
1510        action = menu.exec_(self.list_input.mapToGlobal(position))
1511
1512 # Add a custom context menu
1513    def openmenuuser(self, position):
1514
1515        menu = QtWidgets.QMenu()
1516
1517        selection = self.list_user.selectedItems()
1518       
1519        if ( len(selection) != 0 ):
1520
1521           openAction = QtWidgets.QAction('Open file(s)', self)
1522           openAction.setStatusTip('Open file(s) in your favorite editor')
1523           openAction.triggered.connect(self.OpenFilesUser)
1524
1525
1526           delAction = QtWidgets.QAction('Delete file(s)', self)
1527           delAction.triggered.connect(self.DeleteFilesUser)
1528
1529           menu.addAction(openAction)
1530           menu.addAction(delAction)
1531
1532        delallAction = QtWidgets.QAction('Delete all files', self)
1533        delallAction.triggered.connect(self.DeleteAllFilesUser)
1534        menu.addAction(delallAction)
1535
1536        action = menu.exec_(self.list_user.mapToGlobal(position))
1537
1538 # Add a custom context menu
1539    def openmenuoutput(self, position):
1540
1541        menu = QtWidgets.QMenu()
1542
1543        selection = self.list_output.selectedItems()
1544
1545        if ( len(selection) != 0 ):
1546
1547           openAction = QtWidgets.QAction('Open file(s)', self)
1548           openAction.setStatusTip('Open file(s) in your favorite editor')
1549           openAction.triggered.connect(self.OpenFilesOutput)
1550
1551           delAction = QtWidgets.QAction('Delete file(s)', self)
1552           delAction.triggered.connect(self.DeleteFilesOutput)
1553
1554
1555
1556           menu.addAction(openAction)
1557           menu.addAction(delAction)
1558
1559        delallAction = QtWidgets.QAction('Delete all files', self)
1560        delallAction.triggered.connect(self.DeleteAllFilesOutput)
1561        menu.addAction(delallAction)
1562
1563        action = menu.exec_(self.list_output.mapToGlobal(position))
1564
1565 # Add a custom context menu
1566    def openmenumonitoring(self, position):
1567
1568        menu = QtWidgets.QMenu()
1569
1570        selection = self.list_monitoring.selectedItems()
1571       
1572        if ( len(selection) != 0 ):
1573
1574           openAction = QtWidgets.QAction('Open file(s)', self)
1575           openAction.setStatusTip('Open file(s) in your favorite editor')
1576           openAction.triggered.connect(self.OpenFilesMonitoring)
1577
1578           delAction = QtWidgets.QAction('Delete file(s)', self)
1579           delAction.triggered.connect(self.DeleteFilesMonitoring)
1580
1581
1582
1583           menu.addAction(openAction)
1584           menu.addAction(delAction)
1585
1586        delallAction = QtWidgets.QAction('Delete all files', self)
1587        delallAction.triggered.connect(self.DeleteAllFilesMonitoring)
1588        menu.addAction(delallAction)
1589
1590        action = menu.exec_(self.list_monitoring.mapToGlobal(position))
1591
1592    def OpenConfig(self):
1593
1594       config = str(self.group_execution.findChild(QtWidgets.QComboBox, "combo_configuration").currentText())
1595       if ( config != "" ):
1596          filename = ".palm.config." + config
1597          open_file = "xdg-open " + filename
1598          os.system(str(open_file))
1599
1600    def OpenFilesInput(self):
1601   
1602       sel_job = self.list_jobs.currentItem().text()
1603       sel_files = self.list_input.selectedItems()
1604       
1605       input_dir = job_dir + "/" + sel_job + "/INPUT/"
1606       
1607       open_files = ""
1608       for i in range(0,len(sel_files)):
1609          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text().split("(")[0] + "; "
1610
1611       os.system(str(open_files))
1612
1613    def OpenFilesUser(self):
1614   
1615       sel_job = self.list_jobs.currentItem().text()
1616       sel_files = self.list_user.selectedItems()
1617       
1618       input_dir = job_dir + "/" + sel_job + "/USER_CODE/"
1619       
1620       open_files = ""
1621       for i in range(0,len(sel_files)):
1622          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text() + "; "
1623
1624       os.system(str(open_files)) 
1625       selection = self.list_jobs.selectedItems()
1626 
1627    def OpenFilesMonitoring(self):
1628   
1629       sel_job = self.list_jobs.currentItem().text()
1630       sel_files = self.list_monitoring.selectedItems()
1631       
1632       input_dir = job_dir + "/" + sel_job + "/MONITORING/"
1633       
1634       open_files = ""
1635       for i in range(0,len(sel_files)):
1636          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text().split("(")[0]  + "; "
1637
1638       os.system(str(open_files)) 
1639       selection = self.list_jobs.selectedItems()
1640 
1641    def OpenFilesOutput(self):
1642   
1643       sel_job = self.list_jobs.currentItem().text()
1644       sel_files = self.list_output.selectedItems()
1645       
1646       input_dir = job_dir + "/" + sel_job + "/OUTPUT/"
1647       
1648       open_files = ""
1649       for i in range(0,len(sel_files)):
1650          open_files = open_files + "xdg-open " + input_dir +  sel_files[i].text().split("(")[0] + "; "
1651
1652       os.system(str(open_files)) 
1653       selection = self.list_jobs.selectedItems()
1654
1655    def DeleteFilesInput(self):
1656
1657       status = QtWidgets.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete these files?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
1658
1659       if status == QtWidgets.QMessageBox.Yes:
1660
1661          sel_job = self.list_jobs.currentItem().text()
1662          sel_files = self.list_input.selectedItems()
1663
1664          input_dir = job_dir + "/" + sel_job + "/INPUT/"
1665
1666          for i in range(0,len(sel_files)):
1667             filename = input_dir +  sel_files[i].text().split("(")[0].strip()
1668             os.remove(filename)
1669
1670          self.update_all()
1671
1672
1673    def DeleteFilesUser(self):
1674
1675       status = QtWidgets.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete these files?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
1676
1677       if status == QtWidgets.QMessageBox.Yes:
1678
1679          sel_job = self.list_jobs.currentItem().text()
1680          sel_files = self.list_user.selectedItems()
1681
1682          input_dir = job_dir + "/" + sel_job + "/USER_CODE/"
1683
1684          for i in range(0,len(sel_files)):
1685             filename = input_dir +  sel_files[i].text().split("(")[0].strip()
1686             os.remove(filename)
1687
1688          self.update_all()
1689
1690
1691    def DeleteFilesMonitoring(self):
1692
1693       status = QtWidgets.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete these files?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
1694
1695       if status == QtWidgets.QMessageBox.Yes:
1696
1697          sel_job = self.list_jobs.currentItem().text()
1698          sel_files = self.list_monitoring.selectedItems()
1699
1700          input_dir = job_dir + "/" + sel_job + "/MONITORING/"
1701
1702          for i in range(0,len(sel_files)):
1703             filename = input_dir +  sel_files[i].text().split("(")[0].strip()
1704             os.remove(filename)
1705
1706          self.update_all()
1707
1708
1709    def DeleteFilesOutput(self):
1710
1711       status = QtWidgets.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete these files?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
1712
1713       if status == QtWidgets.QMessageBox.Yes:
1714
1715          sel_job = self.list_jobs.currentItem().text()
1716          sel_files = self.list_output.selectedItems()
1717
1718          input_dir = job_dir + "/" + sel_job + "/OUTPUT/"
1719
1720          for i in range(0,len(sel_files)):
1721             filename = input_dir +  sel_files[i].text().split("(")[0].strip()
1722             os.remove(filename)
1723
1724          self.update_all()
1725
1726
1727    def DeleteAllFilesInput(self):
1728
1729       status = QtWidgets.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
1730
1731       if status == QtWidgets.QMessageBox.Yes:
1732
1733          check = self.list_jobs.currentItem()
1734          if ( check ):
1735             sel_job = self.list_jobs.currentItem().text()
1736             sel_files = self.list_input.selectedItems()
1737
1738             input_dir = job_dir + "/" + sel_job + "/INPUT/"
1739
1740             if os.path.exists(str(input_dir)):
1741                shutil.rmtree(str(input_dir))
1742                os.makedirs(str(input_dir))
1743
1744                self.update_all()
1745
1746
1747    def DeleteAllFilesUser(self):
1748
1749       status = QtWidgets.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
1750
1751       if status == QtWidgets.QMessageBox.Yes:
1752
1753          check = self.list_jobs.currentItem()
1754          if ( check ):
1755             sel_job = self.list_jobs.currentItem().text()
1756             sel_files = self.list_input.selectedItems()
1757
1758             input_dir = job_dir + "/" + sel_job + "/USER_CODE/"
1759
1760             if os.path.exists(str(input_dir)):
1761                shutil.rmtree(str(input_dir))
1762                os.makedirs(str(input_dir))
1763
1764                self.update_all()
1765
1766
1767
1768    def DeleteAllFilesOutput(self):
1769
1770       status = QtWidgets.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
1771
1772       if status == QtWidgets.QMessageBox.Yes:
1773
1774          check = self.list_jobs.currentItem()
1775          if ( check ):
1776             sel_job = self.list_jobs.currentItem().text()
1777             sel_files = self.list_input.selectedItems()
1778
1779             input_dir = job_dir + "/" + sel_job + "/OUTPUT/"
1780
1781             if os.path.exists(str(input_dir)):
1782                shutil.rmtree(str(input_dir))
1783                os.makedirs(str(input_dir))
1784
1785                self.update_all()
1786
1787
1788
1789    def DeleteAllFilesMonitoring(self):
1790
1791       status = QtWidgets.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
1792
1793       if status == QtWidgets.QMessageBox.Yes:
1794
1795          check = self.list_jobs.currentItem()
1796          if ( check ):
1797             sel_job = self.list_jobs.currentItem().text()
1798             sel_files = self.list_input.selectedItems()
1799
1800             input_dir = job_dir + "/" + sel_job + "/MONITORING/"
1801
1802             if os.path.exists(str(input_dir)):
1803                shutil.rmtree(str(input_dir))
1804                os.makedirs(str(input_dir))
1805
1806                self.update_all()
1807
1808
1809
1810    def DeleteJob(self):
1811
1812       status = QtWidgets.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete this job?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
1813
1814       if status == QtWidgets.QMessageBox.Yes:
1815
1816          sel_job = self.list_jobs.currentItem().text()
1817
1818          input_dir = job_dir + "/" + sel_job
1819          shutil.rmtree(str(input_dir))
1820
1821          self.update_all()
1822
1823# Message box for showing RUN_CONTROL output
1824class CreateSetBox(QtWidgets.QDialog):
1825    def __init__(self):
1826
1827        super(CreateSetBox, self).__init__()
1828
1829        uic.loadUi(palm_bin + '/palmrungui_files/create_set.ui', self)
1830
1831        self.show()
1832
1833        return
1834
1835#   Cancel button
1836    def rejected(self):
1837
1838       self.close()
1839
1840       return
1841
1842#   OK button
1843    def accept(self):
1844
1845       global set_list
1846
1847       text = self.list.toPlainText() 
1848       set_list = text.split('\n')
1849       self.close()
1850
1851       return
1852
1853# Message box for showing RUN_CONTROL output
1854class OpenHistoryBox(QtWidgets.QDialog):
1855    def __init__(self):
1856
1857        super(OpenHistoryBox, self).__init__()
1858
1859        uic.loadUi(palm_bin + '/palmrungui_files/history.ui', self)
1860
1861        if os.path.exists(palm_dir + "/.palmrungui.history"):
1862            pass
1863        else:
1864            return
1865
1866        filename = open(palm_dir + "/.palmrungui.history","r")
1867        history = filename.readlines()
1868        filename.close()
1869
1870
1871        list_jobname = self.findChild(QtWidgets.QListWidget,"list_history")
1872
1873        # Read history entries and append to recent job list
1874        len_history=len(history)-1
1875        i = 0
1876        while i<=len_history:
1877            list_jobname.addItem(history[i])
1878            i = i + 1
1879
1880        self.show()
1881
1882        return
1883
1884#   Select item / activate Load button
1885    def ItemSelected(self):
1886
1887       self.push_open.setEnabled(True)
1888
1889       return
1890
1891
1892#   Load job from history
1893    def OpenFromHistory(self):
1894
1895       global history_entry
1896       history_entry = self.list_history.selectedItems()[0].text()
1897
1898       self.close()
1899
1900       return
1901
1902#   Close history window
1903    def DiscardHistory(self):
1904
1905       global history_entry
1906       history_entry = ""
1907       self.close()
1908
1909       return
1910
1911#   Clear history
1912    def ClearHistory(self):
1913
1914       status = QtWidgets.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete your history?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
1915
1916       if status == QtWidgets.QMessageBox.Yes:
1917
1918          if os.path.exists(palm_dir + "/.palmrungui.history"):
1919             os.remove(palm_dir + "/.palmrungui.history")
1920
1921
1922       return
1923
1924if __name__ == "__main__":
1925    app = QtWidgets.QApplication(sys.argv)
1926    window = Mainwindow()
1927    window.show()
1928    sys.exit(app.exec_())
Note: See TracBrowser for help on using the repository browser.