X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=generate_dialog.py;h=dc0448b52f6af0b58902047761d50a42d233ef4a;hp=0d7bbed827dca1ebc8cb7fbf63122751d3d5771c;hb=f37ae5235dba470cf02e25a885b83a2bc9c78694;hpb=9321b80905bca48d49a6b12a4d463c268736b166 diff --git a/generate_dialog.py b/generate_dialog.py index 0d7bbed..dc0448b 100644 --- a/generate_dialog.py +++ b/generate_dialog.py @@ -2,7 +2,10 @@ # Generate site dialog import PyQt4 +import os +import os.path import ui_generate_dialog +import biaweb_exporter class GenerateDialog (PyQt4.QtGui.QDialog, ui_generate_dialog.Ui_SiteGenerateDialog): def __init__ (self, master, currentdb): @@ -11,3 +14,101 @@ class GenerateDialog (PyQt4.QtGui.QDialog, ui_generate_dialog.Ui_SiteGenerateDia # set the database self.current_db = currentdb + + # to return the list of items from a tree widget + def get_list_from_tree (self, treewidget): + lstfiles = [] + iter = PyQt4.QtGui.QTreeWidgetItemIterator (treewidget) + + # iterate through the list of files + item = iter.value () + # while there is still a valid item + while item: + # get the text in columns 0 and 1 + src = str (item.text (0)) + dst = str (item.text (1)) + # add it to the list + lstfiles.append ( (src, dst) ) + # increase iterator by 1 + iter += 1 + item = iter.value () + + return lstfiles + + # when site generate button is clicked + def onSiteGenerate (self): + files_list = self.get_list_from_tree (self.additional_files) + folder_list = self.get_list_from_tree (self.additional_folders) + if self.fulltextindex.isChecked (): + searchtype = True + else: + searchtype = False + + # confirm whether to delete the destination tree and work afresh + ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm", + "This will delete the destination tree completely \ +and recreate the website. Are you sure you wish to proceed?", + PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No) + + # if confirmed + if ans == PyQt4.QtGui.QMessageBox.Yes: + # call the main exporter to do our work + ret = biaweb_exporter.generate_site (self.current_db, files_list, folder_list, searchtype) + + # if failed to generate site or any part thereof + if ret == False: + PyQt4.QtGui.QMessageBox.critical (self, "Error", + "System or SQLite 3 error in generating website or parts thereof") + else: + PyQt4.QtGui.QMessageBox.information (self, "Success", + "Successfully generated website in destination path!") + + # 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