Index: palm/trunk/SCRIPTS/palmrungui
===================================================================
--- palm/trunk/SCRIPTS/palmrungui	(revision 4481)
+++ palm/trunk/SCRIPTS/palmrungui	(revision 4482)
@@ -25,4 +25,8 @@
 # -----------------
 # $Id$
+# Added possibility to delete all files in a directory and option to create
+# blank new jobs
+# 
+# 4481 2020-03-31 18:55:54Z maronga
 # Bugfixes: - reading history lines discard button caused error message
 #           - deleting of USER_CODE files did not work
@@ -1263,4 +1267,48 @@
        self.change_commandline("a","")  
 
+    # Create a new (empty) job
+    def create_new_job(self):
+
+       self.setEnabled(False)
+
+       text, ret = QtGui.QInputDialog.getText(self, "Create new job", "Enter new job name:", mode = QtGui.QLineEdit.Normal, text = '')
+
+       if ( ret ):
+          new_job_name = str(text)
+       else:
+          self.setEnabled(True)
+          return
+
+       new_input_dir  = job_dir + "/" + new_job_name + "/INPUT"
+
+#      check if a job exists with the new job name. If not, the new job is created and an empty _p3d file is created.
+       if ( os.path.isdir(new_input_dir) ):
+          notify = QtGui.QMessageBox.warning(self,'Create new job directory',"Error. Could not create job directory. A job with the new name already exists.")
+          self.setEnabled(True)
+          return
+       else:
+          os.makedirs(new_input_dir)
+          os.mknod(new_input_dir + '/' + new_job_name + '_p3d')
+
+#      write default namelists into _p3d file
+       filename = open(new_input_dir + '/' + new_job_name + '_p3d', "w")
+       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')
+       filename.write('&runtime_parameters\n    end_time = 3600.0,\n/\n')
+       filename.close()
+
+
+#      create empty USER_CODE folder for convenience
+       new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
+       os.makedirs(new_user_dir)
+
+
+       self.load_jobs()
+       self.list_input.clear()
+       self.list_user.clear()
+       self.list_monitoring.clear()
+       self.list_output.clear()
+       self.setEnabled(True)
+
+
     # Make a copy of a job
     def copy_job(self):
@@ -1293,5 +1341,5 @@
 
           list_of_files = os.listdir(job_to_copy)
-         
+
           for i in range(0,len(list_of_files)):
 
@@ -1304,5 +1352,5 @@
 
        new_user_dir  = job_dir + "/" + new_job_name + "/USER_CODE"
-       
+
 #      check if user code exists in the new job directory 
        if ( os.path.isdir(new_user_dir) ):
@@ -1417,7 +1465,12 @@
         menu = QtGui.QMenu()
 
+
+        newAction = QtGui.QAction('Create new job', self)
+        newAction.triggered.connect(self.create_new_job)
+        menu.addAction(newAction)
         selection = self.list_jobs.selectedItems()
 
         if ( len(selection) != 0 ):
+
 
            copyAction = QtGui.QAction('Copy job', self)
@@ -1432,7 +1485,6 @@
            menu.addAction(delAction)
 
-           action = menu.exec_(self.list_jobs.mapToGlobal(position))
-       
-       
+        action = menu.exec_(self.list_jobs.mapToGlobal(position))
+
  # Add a custom context menu
     def openmenuinput(self, position):
@@ -1450,5 +1502,5 @@
 
 
-           delAction = QtGui.QAction('Delete file(s)', self)
+           delAction = QtGui.QAction('Delete selected file(s)', self)
            delAction.triggered.connect(self.DeleteFilesInput)
 
@@ -1456,5 +1508,9 @@
            menu.addAction(delAction)
 
-           action = menu.exec_(self.list_input.mapToGlobal(position))
+        delallAction = QtGui.QAction('Delete all files', self)
+        delallAction.triggered.connect(self.DeleteAllFilesInput)
+        menu.addAction(delallAction)
+
+        action = menu.exec_(self.list_input.mapToGlobal(position))
 
  # Add a custom context menu
@@ -1477,5 +1533,10 @@
            menu.addAction(openAction)
            menu.addAction(delAction)
-           action = menu.exec_(self.list_user.mapToGlobal(position))
+
+        delallAction = QtGui.QAction('Delete all files', self)
+        delallAction.triggered.connect(self.DeleteAllFilesUser)
+        menu.addAction(delallAction)
+
+        action = menu.exec_(self.list_user.mapToGlobal(position))
 
  # Add a custom context menu
@@ -1485,5 +1546,5 @@
 
         selection = self.list_output.selectedItems()
-        
+
         if ( len(selection) != 0 ):
 
@@ -1492,11 +1553,17 @@
            openAction.triggered.connect(self.OpenFilesOutput)
 
-
            delAction = QtGui.QAction('Delete file(s)', self)
            delAction.triggered.connect(self.DeleteFilesOutput)
 
+
+
            menu.addAction(openAction)
            menu.addAction(delAction)
-           action = menu.exec_(self.list_output.mapToGlobal(position))
+
+        delallAction = QtGui.QAction('Delete all files', self)
+        delallAction.triggered.connect(self.DeleteAllFilesOutput)
+        menu.addAction(delallAction)
+
+        action = menu.exec_(self.list_output.mapToGlobal(position))
 
  # Add a custom context menu
@@ -1513,11 +1580,17 @@
            openAction.triggered.connect(self.OpenFilesMonitoring)
 
-
            delAction = QtGui.QAction('Delete file(s)', self)
            delAction.triggered.connect(self.DeleteFilesMonitoring)
 
+
+
            menu.addAction(openAction)
            menu.addAction(delAction)
-           action = menu.exec_(self.list_monitoring.mapToGlobal(position))
+
+        delallAction = QtGui.QAction('Delete all files', self)
+        delallAction.triggered.connect(self.DeleteAllFilesMonitoring)
+        menu.addAction(delallAction)
+
+        action = menu.exec_(self.list_monitoring.mapToGlobal(position))
 
     def OpenConfig(self):
@@ -1655,4 +1728,88 @@
           self.update_all()
 
+
+    def DeleteAllFilesInput(self):
+
+       status = QtGui.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
+
+       if status == QtGui.QMessageBox.Yes:
+
+          check = self.list_jobs.currentItem()
+          if ( check ):
+             sel_job = self.list_jobs.currentItem().text()
+             sel_files = self.list_input.selectedItems()
+
+             input_dir = job_dir + "/" + sel_job + "/INPUT/"
+
+             if os.path.exists(str(input_dir)):
+                shutil.rmtree(str(input_dir))
+                os.makedirs(str(input_dir))
+
+                self.update_all()
+
+
+    def DeleteAllFilesUser(self):
+
+       status = QtGui.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
+
+       if status == QtGui.QMessageBox.Yes:
+
+          check = self.list_jobs.currentItem()
+          if ( check ):
+             sel_job = self.list_jobs.currentItem().text()
+             sel_files = self.list_input.selectedItems()
+
+             input_dir = job_dir + "/" + sel_job + "/USER_CODE/"
+
+             if os.path.exists(str(input_dir)):
+                shutil.rmtree(str(input_dir))
+                os.makedirs(str(input_dir))
+
+                self.update_all()
+
+
+
+    def DeleteAllFilesOutput(self):
+
+       status = QtGui.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
+
+       if status == QtGui.QMessageBox.Yes:
+
+          check = self.list_jobs.currentItem()
+          if ( check ):
+             sel_job = self.list_jobs.currentItem().text()
+             sel_files = self.list_input.selectedItems()
+
+             input_dir = job_dir + "/" + sel_job + "/OUTPUT/"
+
+             if os.path.exists(str(input_dir)):
+                shutil.rmtree(str(input_dir))
+                os.makedirs(str(input_dir))
+
+                self.update_all()
+
+
+
+    def DeleteAllFilesMonitoring(self):
+
+       status = QtGui.QMessageBox.question(self,'Delete Confirmation', "Are you sure you want to delete all files?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
+
+       if status == QtGui.QMessageBox.Yes:
+
+          check = self.list_jobs.currentItem()
+          if ( check ):
+             sel_job = self.list_jobs.currentItem().text()
+             sel_files = self.list_input.selectedItems()
+
+             input_dir = job_dir + "/" + sel_job + "/MONITORING/"
+
+             if os.path.exists(str(input_dir)):
+                shutil.rmtree(str(input_dir))
+                os.makedirs(str(input_dir))
+
+                self.update_all()
+
+
+
     def DeleteJob(self):
 
