Add/remove files/folders in Site Generate dialog
authorHarishankar <v.harishankar@gmail.com>
Tue, 30 Nov 2010 06:03:36 +0000 (11:33 +0530)
committerHarishankar <v.harishankar@gmail.com>
Tue, 30 Nov 2010 06:03:36 +0000 (11:33 +0530)
Implemented the add/remove files and folders to destination
path in the Generate site dialog

generate_dialog.py
generate_dialog.ui
ui_generate_dialog.py

index 0d7bbed..eb49933 100644 (file)
@@ -2,6 +2,8 @@
 # Generate site dialog
 
 import PyQt4
+import os
+import os.path
 import ui_generate_dialog
 
 class GenerateDialog (PyQt4.QtGui.QDialog, ui_generate_dialog.Ui_SiteGenerateDialog):
@@ -11,3 +13,53 @@ class GenerateDialog (PyQt4.QtGui.QDialog, ui_generate_dialog.Ui_SiteGenerateDia
 
                # set the database
                self.current_db = currentdb
+
+       # when folder add is clicked
+       def onFolderAdd (self):
+               folder_to_add = PyQt4.QtGui.QFileDialog.getExistingDirectory (self,
+                                                       "Folder whose contents to add to destination", os.path.expanduser ("~"))
+               # if cancelled return
+               if not folder_to_add:
+                       return
+
+               dest_rel_path, ok = PyQt4.QtGui.QInputDialog.getText (self, "Desination",
+                                                       "Copy to location (within destination path)")
+               if not ok:
+                       return
+
+               folderitem = PyQt4.QtGui.QTreeWidgetItem ([folder_to_add, dest_rel_path])
+               self.additional_folders.addTopLevelItem (folderitem)
+
+       # when folder remove is clicked
+       def onFolderRemove (self):
+               selitem = self.additional_folders.currentItem ()
+               selindex = self.additional_folders.indexOfTopLevelItem (selitem)
+               # if none selected
+               if selindex == -1:
+                       return
+               self.additional_folders.takeTopLevelItem (selindex)
+
+
+       # when file add is clicked
+       def onFileAdd (self):
+               file_to_add = PyQt4.QtGui.QFileDialog.getOpenFileName (self, "File to add to destination",
+                                                       os.path.expanduser ("~"))
+               # if cancelled return
+               if not file_to_add:
+                       return
+               dest_rel_path, ok = PyQt4.QtGui.QInputDialog.getText (self, "Destination",
+                                                               "Copy to location (within destination path)")
+               if not ok:
+                       return
+
+               fileitem = PyQt4.QtGui.QTreeWidgetItem ([file_to_add, dest_rel_path])
+               self.additional_files.addTopLevelItem (fileitem)
+
+       # when file remove is clicked
+       def onFileRemove (self):
+               selitem = self.additional_files.currentItem ()
+               selindex = self.additional_files.indexOfTopLevelItem (selitem)
+               # if none selected
+               if selindex == -1:
+                       return
+               self.additional_files.takeTopLevelItem (selindex)
\ No newline at end of file
index 21a3928..2330f19 100644 (file)
@@ -213,5 +213,75 @@ p, li { white-space: pre-wrap; }
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>addfile</sender>
+   <signal>clicked()</signal>
+   <receiver>SiteGenerateDialog</receiver>
+   <slot>onFileAdd()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>354</x>
+     <y>205</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>356</x>
+     <y>433</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>removefile</sender>
+   <signal>clicked()</signal>
+   <receiver>SiteGenerateDialog</receiver>
+   <slot>onFileRemove()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>471</x>
+     <y>207</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>492</x>
+     <y>434</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>addfolder</sender>
+   <signal>clicked()</signal>
+   <receiver>SiteGenerateDialog</receiver>
+   <slot>onFolderAdd()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>360</x>
+     <y>203</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>420</x>
+     <y>444</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>removefolder</sender>
+   <signal>clicked()</signal>
+   <receiver>SiteGenerateDialog</receiver>
+   <slot>onFolderRemove()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>518</x>
+     <y>206</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>563</x>
+     <y>449</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
+ <slots>
+  <slot>onFileAdd()</slot>
+  <slot>onFileRemove()</slot>
+  <slot>onFolderAdd()</slot>
+  <slot>onFolderRemove()</slot>
+ </slots>
 </ui>
index a14ac37..c28205d 100644 (file)
@@ -2,7 +2,7 @@
 
 # Form implementation generated from reading ui file 'generate_dialog.ui'
 #
-# Created: Mon Nov 29 22:36:32 2010
+# Created: Tue Nov 30 10:55:19 2010
 #      by: PyQt4 UI code generator 4.7.4
 #
 # WARNING! All changes made in this file will be lost!
@@ -82,6 +82,10 @@ class Ui_SiteGenerateDialog(object):
         self.retranslateUi(SiteGenerateDialog)
         self.tabWidget.setCurrentIndex(0)
         QtCore.QObject.connect(self.close, QtCore.SIGNAL("clicked()"), SiteGenerateDialog.reject)
+        QtCore.QObject.connect(self.addfile, QtCore.SIGNAL("clicked()"), SiteGenerateDialog.onFileAdd)
+        QtCore.QObject.connect(self.removefile, QtCore.SIGNAL("clicked()"), SiteGenerateDialog.onFileRemove)
+        QtCore.QObject.connect(self.addfolder, QtCore.SIGNAL("clicked()"), SiteGenerateDialog.onFolderAdd)
+        QtCore.QObject.connect(self.removefolder, QtCore.SIGNAL("clicked()"), SiteGenerateDialog.onFolderRemove)
         QtCore.QMetaObject.connectSlotsByName(SiteGenerateDialog)
         SiteGenerateDialog.setTabOrder(self.tabWidget, self.addfile)
         SiteGenerateDialog.setTabOrder(self.addfile, self.removefile)