Specific boolean comparisons in code made literal
[biaweb_qt.git] / templates_dialog.py
index 64cc70c..db61404 100644 (file)
@@ -16,18 +16,26 @@ class TemplatesDialog (PyQt4.QtGui.QDialog, ui_templates_dialog.Ui_TemplatesDial
 
                # populate the templates
                tpls = biaweb_db.get_templates (self.current_db)
-               for tpl_name, tpl_content in tpls:
-                       self.templates.addItem (str (tpl_name))
+               # if templates populated
+               if tpls:
+                       for tpl_name, tpl_content in tpls:
+                               self.templates.addItem (str (tpl_name))
+               else:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in retrieving templates")
 
        def onEdit (self):
                # get the currently selected list item
-               tpl_name = str (self.templates.currentItem ().data (0).toString ())
+               sel_item = self.templates.currentItem ()
+               # if no item is selected return
+               if sel_item is None:
+                       return
+               tpl_name = str (sel_item.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:
+               if tpl_str is 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
@@ -39,6 +47,6 @@ class TemplatesDialog (PyQt4.QtGui.QDialog, ui_templates_dialog.Ui_TemplatesDial
                                # 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:
+                               if ret is False:
                                        PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in updating template")