X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=templates_dialog.py;h=64cc70ca3158fa6b1f37dc49ee929e1f6396b7cb;hp=8a57482cd183e06be0d9f49e38574799da4cebb4;hb=54389d5adbbb1830a7e85545b2bdde816713a272;hpb=2687a3c3b18c3a267ca60ecdd3759ed0856471e0 diff --git a/templates_dialog.py b/templates_dialog.py index 8a57482..64cc70c 100644 --- a/templates_dialog.py +++ b/templates_dialog.py @@ -3,6 +3,7 @@ import PyQt4 import ui_templates_dialog +import editor_dialog import biaweb_db class TemplatesDialog (PyQt4.QtGui.QDialog, ui_templates_dialog.Ui_TemplatesDialog): @@ -17,3 +18,27 @@ class TemplatesDialog (PyQt4.QtGui.QDialog, ui_templates_dialog.Ui_TemplatesDial tpls = biaweb_db.get_templates (self.current_db) for tpl_name, tpl_content in tpls: self.templates.addItem (str (tpl_name)) + + def onEdit (self): + # get the currently selected list item + tpl_name = str (self.templates.currentItem ().data (0).toString ()) + + # get the template content from the database + tpl_str = biaweb_db.get_template_text (self.current_db, tpl_name) + + # if template string cannot be obtained for some reason + if tpl_str == False: + PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in retrieving template") + else: + # open edit dialog with title "template name" and text as the template string + edlg = editor_dialog.EditorDialog (self, tpl_name, tpl_str) + # if editing is confirmed + if edlg.exec_ () == PyQt4.QtGui.QDialog.Accepted: + upd_tpl_str = str (edlg.text.toPlainText ()).strip () + + # update the template with the new template string + ret = biaweb_db.update_template (self.current_db, tpl_name, upd_tpl_str) + # if update failed + if ret == False: + PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in updating template") +