From: Harishankar Date: Mon, 29 Nov 2010 10:01:07 +0000 (+0530) Subject: Modified the template editing setup X-Git-Url: https://harishankar.org/repos/?a=commitdiff_plain;h=2687a3c3b18c3a267ca60ecdd3759ed0856471e0;p=biaweb_qt.git Modified the template editing setup Changed the main template editing setup since the originally planned concept seems tricky to implement. Now a separate editor window will be opened for template editing. --- diff --git a/biaweb_db.py b/biaweb_db.py index dd3e333..80e3915 100644 --- a/biaweb_db.py +++ b/biaweb_db.py @@ -6,6 +6,19 @@ import os import os.path import time +# function to retrieve the templates from the database +def get_templates (dbname): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("SELECT * FROM templates;") + conn.commit () + rows = c.fetchall () + conn.close () + return rows + except sqlite3.Error: + return False + # function to get an article from the database def get_article (dbname, artid): try: @@ -222,192 +235,192 @@ def create_db (dbname, site_title, site_url, keywords, description, copyright, templates (template_name TEXT, template_content);") template_main = """ - - - - ${site_title} - - - - - - - - - -
- ${contents_bit} -
- - - - """ + + + +${site_title} + + + + + + + + + +
+ ${contents_bit} +
+ + + +""" template_article_bit = """

${article_title}

-
Created: ${article_cdate} | Last modified: ${article_mdate}
-
Rating: ${rating}
-
${article_contents}
- """ +
Created: ${article_cdate} | Last modified: ${article_mdate}
+
Rating: ${rating}
+
${article_contents}
+""" template_news_item_bit = """

${news_title}

-
${news_datetime}
-
${news_description}
- """ +
${news_datetime}
+
${news_description}
+""" template_index_bit = """

Welcome to ${site_name}

-
- Welcome to my site, ${site_name}. -
-

Latest Articles

- ${news_updates} - """ +
+Welcome to my site, ${site_name}. +
+

Latest Articles

+${news_updates} +""" template_table_bit = """

${category_title}

-

${category_desc}

- - - - - - - - - - ${table_rows} - -
TitleCreated onRated
- """ +

${category_desc}

+ + + + + + + + + + ${table_rows} + +
TitleCreated onRated
+""" template_tablerow_bit = """ - ${title} - ${created} - ${rating} - - """ + ${title} + ${created} + ${rating} + +""" template_style = """body { - font-family: "Bitstream Vera Sans", Verdana, Arial, Sans Serif; - font-size: 0.9em; - background-color: #ffffff; - color: #000000; - margin: auto - } - #head { - width: 98%; - background-color: #efefef; - padding: 1%; - text-align: center; - } - - #main { - width: 73%; - padding: 1%; - float: left; - } - - #sidebar { - width: 23%; - padding: 1%; - float: right; - } - - #footer { - width: 100%; - padding-top: 5px; - padding-bottom: 5px; - font-size: 0.9em; - text-align: center; - float: left; - background-color: #efefef; - } - - .headerdesc { - font-variant: small-caps; - font-size: 1.1em; - } - - .content { - text-align: justify; - line-height: 1.1em; - } - - .categorytable { - width: 100%; - } - - .categorytable thead { - font-weight: bold; - } - - .modified { - font-size: 0.8em; - color: #666666; - } - - .rating { - font-size: 0.8em; - color: #666666; - } - - h1, h2, h3 { - font-family: "Bitstream Vera Serif", Serif; - padding: 0; - margin: 0; - margin-top: 5px; - margin-bottom: 5px; - } - - hr { - border: 0; - border-bottom: 1px solid; - border-color: #888888; - } - - h1 { - font-size: 2.4em; - color: #000099; - - } - h1 a, h1 a:hover, h1 a:visited, h2 a:active { - text-decoration: none; - } - h2 { - font-size: 1.4em; - background-color: #efefef; - } - h2 a, h2 a:hover, h2 a:visited, h2 a:active { - text-decoration: none; - } - h3 { - font-size: 1.2em; - a { - color: #0000dd; - } - a:visited { - color: #0000aa; - } - a:active, a:hover { - color: #0000ff; - }""" + font-family: "Bitstream Vera Sans", Verdana, Arial, Sans Serif; + font-size: 0.9em; + background-color: #ffffff; + color: #000000; + margin: auto +} +#head { + width: 98%; + background-color: #efefef; + padding: 1%; + text-align: center; +} + +#main { + width: 73%; + padding: 1%; + float: left; +} + +#sidebar { + width: 23%; + padding: 1%; + float: right; +} + +#footer { + width: 100%; + padding-top: 5px; + padding-bottom: 5px; + font-size: 0.9em; + text-align: center; + float: left; + background-color: #efefef; +} + +.headerdesc { + font-variant: small-caps; + font-size: 1.1em; +} + +.content { + text-align: justify; + line-height: 1.1em; +} + +.categorytable { + width: 100%; +} + +.categorytable thead { + font-weight: bold; +} + +.modified { + font-size: 0.8em; + color: #666666; +} + +.rating { + font-size: 0.8em; + color: #666666; +} + +h1, h2, h3 { + font-family: "Bitstream Vera Serif", Serif; + padding: 0; + margin: 0; + margin-top: 5px; + margin-bottom: 5px; +} + +hr { + border: 0; + border-bottom: 1px solid; + border-color: #888888; +} + +h1 { + font-size: 2.4em; + color: #000099; + +} +h1 a, h1 a:hover, h1 a:visited, h2 a:active { + text-decoration: none; +} +h2 { + font-size: 1.4em; + background-color: #efefef; +} +h2 a, h2 a:hover, h2 a:visited, h2 a:active { + text-decoration: none; +} +h3 { + font-size: 1.2em; +a { + color: #0000dd; +} +a:visited { + color: #0000aa; +} +a:active, a:hover { + color: #0000ff; +}""" c.executemany ("INSERT INTO templates (template_name, template_content) VALUES (?, ?);", [["main_template", template_main], diff --git a/main_window.py b/main_window.py index 32e39f9..6b7f31a 100644 --- a/main_window.py +++ b/main_window.py @@ -20,7 +20,9 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): # refresh the category list def repopulate_categories (self): recs = biaweb_db.get_categories (self.current_db) - if not recs: + + # check with False because None is returned when no records exist + if recs == False: PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in getting the categories") return @@ -32,7 +34,9 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): # refresh the articles list def repopulate_articles (self, catid=None): recs = biaweb_db.get_articles (self.current_db, catid) - if not recs: + + # check with False because None is returned when no records exist + if recs == False: PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in getting the articles") return @@ -218,7 +222,7 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): PyQt4.QtGui.QMessageBox.critical (self, "Error", "Cannot edit templates. You need to create or open a website first") else: - tdlg = tpld.TemplatesDialog (self) + tdlg = tpld.TemplatesDialog (self, self.current_db) tdlg.exec_ () # function to get the category or article ID from current selected item in a tree widget diff --git a/templates_dialog.py b/templates_dialog.py index 7d8fbf0..8a57482 100644 --- a/templates_dialog.py +++ b/templates_dialog.py @@ -3,10 +3,17 @@ import PyQt4 import ui_templates_dialog -import highlighter +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)) diff --git a/templates_dialog.ui b/templates_dialog.ui index 2b9be0a..e3f77aa 100644 --- a/templates_dialog.ui +++ b/templates_dialog.ui @@ -6,32 +6,25 @@ 0 0 - 751 - 535 + 350 + 256 - Template Editor + Templates - + - Template + Choose template - - - - - 250 - 0 - - - + + - + Click to edit the @@ -40,32 +33,15 @@ selected template &Edit - - - - - - Save the template -modified below - - - &Save - - - - - - - - Monospace - + + false - - true + + false - + &Close @@ -75,10 +51,7 @@ modified below - templates edit - pushButton - template_text close @@ -90,8 +63,8 @@ modified below accept() - 515 - 383 + 741 + 525 288 @@ -100,4 +73,8 @@ modified below + + onEdit() + onTemplateTextChanged() + diff --git a/ui_templates_dialog.py b/ui_templates_dialog.py index 6845dc2..895e2be 100644 --- a/ui_templates_dialog.py +++ b/ui_templates_dialog.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'templates_dialog.ui' # -# Created: Mon Nov 29 13:37:20 2010 +# Created: Mon Nov 29 15:30:13 2010 # by: PyQt4 UI code generator 4.7.4 # # WARNING! All changes made in this file will be lost! @@ -12,49 +12,34 @@ from PyQt4 import QtCore, QtGui class Ui_TemplatesDialog(object): def setupUi(self, TemplatesDialog): TemplatesDialog.setObjectName("TemplatesDialog") - TemplatesDialog.resize(751, 535) + TemplatesDialog.resize(350, 256) self.gridLayout = QtGui.QGridLayout(TemplatesDialog) self.gridLayout.setObjectName("gridLayout") self.label = QtGui.QLabel(TemplatesDialog) self.label.setObjectName("label") - self.gridLayout.addWidget(self.label, 0, 0, 1, 1) - self.templates = QtGui.QComboBox(TemplatesDialog) - self.templates.setMinimumSize(QtCore.QSize(250, 0)) + self.gridLayout.addWidget(self.label, 0, 0, 1, 2) + self.templates = QtGui.QListWidget(TemplatesDialog) self.templates.setObjectName("templates") - self.gridLayout.addWidget(self.templates, 0, 1, 1, 1) + self.gridLayout.addWidget(self.templates, 1, 0, 1, 3) self.edit = QtGui.QPushButton(TemplatesDialog) + self.edit.setCheckable(False) + self.edit.setChecked(False) self.edit.setObjectName("edit") - self.gridLayout.addWidget(self.edit, 0, 2, 1, 1) - self.pushButton = QtGui.QPushButton(TemplatesDialog) - self.pushButton.setObjectName("pushButton") - self.gridLayout.addWidget(self.pushButton, 0, 3, 1, 1) - self.template_text = QtGui.QPlainTextEdit(TemplatesDialog) - font = QtGui.QFont() - font.setFamily("Monospace") - self.template_text.setFont(font) - self.template_text.setTabChangesFocus(True) - self.template_text.setObjectName("template_text") - self.gridLayout.addWidget(self.template_text, 1, 0, 1, 4) + self.gridLayout.addWidget(self.edit, 2, 1, 1, 1) self.close = QtGui.QPushButton(TemplatesDialog) self.close.setObjectName("close") - self.gridLayout.addWidget(self.close, 2, 3, 1, 1) + self.gridLayout.addWidget(self.close, 2, 2, 1, 1) self.retranslateUi(TemplatesDialog) QtCore.QObject.connect(self.close, QtCore.SIGNAL("clicked()"), TemplatesDialog.accept) QtCore.QMetaObject.connectSlotsByName(TemplatesDialog) - TemplatesDialog.setTabOrder(self.templates, self.edit) - TemplatesDialog.setTabOrder(self.edit, self.pushButton) - TemplatesDialog.setTabOrder(self.pushButton, self.template_text) - TemplatesDialog.setTabOrder(self.template_text, self.close) + TemplatesDialog.setTabOrder(self.edit, self.close) def retranslateUi(self, TemplatesDialog): - TemplatesDialog.setWindowTitle(QtGui.QApplication.translate("TemplatesDialog", "Template Editor", None, QtGui.QApplication.UnicodeUTF8)) - self.label.setText(QtGui.QApplication.translate("TemplatesDialog", "Template", None, QtGui.QApplication.UnicodeUTF8)) + TemplatesDialog.setWindowTitle(QtGui.QApplication.translate("TemplatesDialog", "Templates", None, QtGui.QApplication.UnicodeUTF8)) + self.label.setText(QtGui.QApplication.translate("TemplatesDialog", "Choose template", None, QtGui.QApplication.UnicodeUTF8)) self.edit.setToolTip(QtGui.QApplication.translate("TemplatesDialog", "Click to edit the\n" "selected template", None, QtGui.QApplication.UnicodeUTF8)) self.edit.setText(QtGui.QApplication.translate("TemplatesDialog", "&Edit", None, QtGui.QApplication.UnicodeUTF8)) - self.pushButton.setToolTip(QtGui.QApplication.translate("TemplatesDialog", "Save the template\n" -"modified below", None, QtGui.QApplication.UnicodeUTF8)) - self.pushButton.setText(QtGui.QApplication.translate("TemplatesDialog", "&Save", None, QtGui.QApplication.UnicodeUTF8)) self.close.setText(QtGui.QApplication.translate("TemplatesDialog", "&Close", None, QtGui.QApplication.UnicodeUTF8))