X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=templates_dialog.py;h=efd5bd72e0688b1b989542f8e287b1b0063ee590;hp=7d8fbf0e114eea5fba2b449ebd020cdcd0535857;hb=b517d55320f54925d862aca9dedb363b6d3b156d;hpb=c78ebaf4ae0e486c54907edf51159615f2b4f81e diff --git a/templates_dialog.py b/templates_dialog.py index 7d8fbf0..efd5bd7 100644 --- a/templates_dialog.py +++ b/templates_dialog.py @@ -3,10 +3,33 @@ import PyQt4 import ui_templates_dialog -import highlighter +import editor_dialog +import biaweb_db class TemplatesDialog (PyQt4.QtGui.QDialog, ui_templates_dialog.Ui_TemplatesDialog): - def __init__ (self, master): + def __init__ (self, master, currentdb): PyQt4.QtGui.QDialog.__init__ (self, master) self.setupUi (self) - self.setWindowFlags (PyQt4.QtCore.Qt.Window) + + # set the current database + self.current_db = currentdb + + # populate the templates + 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 = self.templates.currentItem ().data (0).toString () + + # get the template content from the database + tpl_str = biaweb_db.get_template_text (self.current_db, str (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) + edlg.exec_ ()