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