Add/remove files/folders in Site Generate dialog
[biaweb_qt.git] / generate_dialog.py
1 # BiaWeb Website content manager (c) 2010 V.Harishankar
2 # Generate site dialog
3
4 import PyQt4
5 import os
6 import os.path
7 import ui_generate_dialog
8
9 class GenerateDialog (PyQt4.QtGui.QDialog, ui_generate_dialog.Ui_SiteGenerateDialog):
10 def __init__ (self, master, currentdb):
11 PyQt4.QtGui.QDialog.__init__ (self, master)
12 self.setupUi (self)
13
14 # set the database
15 self.current_db = currentdb
16
17 # when folder add is clicked
18 def onFolderAdd (self):
19 folder_to_add = PyQt4.QtGui.QFileDialog.getExistingDirectory (self,
20 "Folder whose contents to add to destination", os.path.expanduser ("~"))
21 # if cancelled return
22 if not folder_to_add:
23 return
24
25 dest_rel_path, ok = PyQt4.QtGui.QInputDialog.getText (self, "Desination",
26 "Copy to location (within destination path)")
27 if not ok:
28 return
29
30 folderitem = PyQt4.QtGui.QTreeWidgetItem ([folder_to_add, dest_rel_path])
31 self.additional_folders.addTopLevelItem (folderitem)
32
33 # when folder remove is clicked
34 def onFolderRemove (self):
35 selitem = self.additional_folders.currentItem ()
36 selindex = self.additional_folders.indexOfTopLevelItem (selitem)
37 # if none selected
38 if selindex == -1:
39 return
40 self.additional_folders.takeTopLevelItem (selindex)
41
42
43 # when file add is clicked
44 def onFileAdd (self):
45 file_to_add = PyQt4.QtGui.QFileDialog.getOpenFileName (self, "File to add to destination",
46 os.path.expanduser ("~"))
47 # if cancelled return
48 if not file_to_add:
49 return
50 dest_rel_path, ok = PyQt4.QtGui.QInputDialog.getText (self, "Destination",
51 "Copy to location (within destination path)")
52 if not ok:
53 return
54
55 fileitem = PyQt4.QtGui.QTreeWidgetItem ([file_to_add, dest_rel_path])
56 self.additional_files.addTopLevelItem (fileitem)
57
58 # when file remove is clicked
59 def onFileRemove (self):
60 selitem = self.additional_files.currentItem ()
61 selindex = self.additional_files.indexOfTopLevelItem (selitem)
62 # if none selected
63 if selindex == -1:
64 return
65 self.additional_files.takeTopLevelItem (selindex)