1 # BiaWeb Website content manager (c) 2010 V.Harishankar
7 import ui_generate_dialog
10 class GenerateDialog (PyQt4
.QtGui
.QDialog
, ui_generate_dialog
.Ui_SiteGenerateDialog
):
11 def __init__ (self
, master
, currentdb
):
12 PyQt4
.QtGui
.QDialog
.__init
__ (self
, master
)
16 self
.current_db
= currentdb
18 # to return the list of items from a tree widget
19 def get_list_from_tree (self
, treewidget
):
21 iter = PyQt4
.QtGui
.QTreeWidgetItemIterator (treewidget
)
23 # iterate through the list of files
25 # while there is still a valid item
27 # get the text in columns 0 and 1
28 src
= str (item
.text (0))
29 dst
= str (item
.text (1))
31 lstfiles
.append ( (src
, dst
) )
32 # increase iterator by 1
38 # when site generate button is clicked
39 def onSiteGenerate (self
):
40 files_list
= self
.get_list_from_tree (self
.additional_files
)
41 folder_list
= self
.get_list_from_tree (self
.additional_folders
)
42 if self
.fulltextindex
.isChecked ():
47 # confirm whether to delete the destination tree and work afresh
48 ans
= PyQt4
.QtGui
.QMessageBox
.question (self
, "Confirm",
49 "This will delete the destination tree completely \
50 and recreate the website. Are you sure you wish to proceed?",
51 PyQt4
.QtGui
.QMessageBox
.Yes
, PyQt4
.QtGui
.QMessageBox
.No
)
54 if ans
== PyQt4
.QtGui
.QMessageBox
.Yes
:
55 # call the main exporter to do our work
56 ret
= biaweb_exporter
.generate_site (self
.current_db
, files_list
, folder_list
, searchtype
)
58 # if failed to generate site or any part thereof
60 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error",
61 "System or SQLite 3 error in generating website or parts thereof")
63 PyQt4
.QtGui
.QMessageBox
.information (self
, "Success",
64 "Successfully generated website in destination path!")
66 # when folder add is clicked
67 def onFolderAdd (self
):
68 folder_to_add
= PyQt4
.QtGui
.QFileDialog
.getExistingDirectory (self
,
69 "Folder whose contents to add to destination", os
.path
.expanduser ("~"))
74 dest_rel_path
, ok
= PyQt4
.QtGui
.QInputDialog
.getText (self
, "Desination",
75 "Copy to location (within destination path)")
79 folderitem
= PyQt4
.QtGui
.QTreeWidgetItem ([folder_to_add
, dest_rel_path
])
80 self
.additional_folders
.addTopLevelItem (folderitem
)
82 # when folder remove is clicked
83 def onFolderRemove (self
):
84 selitem
= self
.additional_folders
.currentItem ()
85 selindex
= self
.additional_folders
.indexOfTopLevelItem (selitem
)
89 self
.additional_folders
.takeTopLevelItem (selindex
)
92 # when file add is clicked
94 file_to_add
= PyQt4
.QtGui
.QFileDialog
.getOpenFileName (self
, "File to add to destination",
95 os
.path
.expanduser ("~"))
99 dest_rel_path
, ok
= PyQt4
.QtGui
.QInputDialog
.getText (self
, "Destination",
100 "Copy to location (within destination path)")
104 fileitem
= PyQt4
.QtGui
.QTreeWidgetItem ([file_to_add
, dest_rel_path
])
105 self
.additional_files
.addTopLevelItem (fileitem
)
107 # when file remove is clicked
108 def onFileRemove (self
):
109 selitem
= self
.additional_files
.currentItem ()
110 selindex
= self
.additional_files
.indexOfTopLevelItem (selitem
)
114 self
.additional_files
.takeTopLevelItem (selindex
)