import sqlite3
import os
import os.path
+import pprint
# function to create a category
def create_category (dbname, category_name, category_desc, category_stub):
except sqlite3.Error:
return False
+# Function to get list of articles (either full list or just in a category
+def get_articles (dbname, category_id=None):
+ try:
+ conn = sqlite3.connect (dbname)
+ c = conn.cursor ()
+ if category_id == None:
+ c.execute ("SELECT * FROM articles;")
+ else:
+ c.execute ("SELECT * FROM articles WHERE cid=?", (category_id,))
+ conn.commit ()
+ rows = c.fetchall ()
+ return rows
+ except sqlite3.Error:
+ return False
+
+# Function to get list of categories and return a (category_id, category_name) array
+def get_categories (dbname):
+ try:
+ conn = sqlite3.connect (dbname)
+ c = conn.cursor ()
+ c.execute ("SELECT * FROM categories;")
+ conn.commit ()
+ recs = c.fetchall ()
+ conn.close ()
+ return recs
+ except sqlite3.Error:
+ return False
# function to create a new site database
def create_db (dbname, site_title, site_url, keywords, description, copyright,
self.setupUi (self)
self.current_db = None
+ # refresh the category list
+ def repopulate_categories (self):
+ recs = biaweb_db.get_categories (self.current_db)
+ if recs == False:
+ PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in getting the categories")
+ return
+
+ self.categories.clear ()
+ for (id, name, desc, stub) in recs:
+ qrow = PyQt4.QtGui.QTreeWidgetItem ([str(id), str(name)])
+ self.categories.addTopLevelItem (qrow)
+
+ # refresh the articles list
+ def repopulate_articles (self, catid=None):
+ recs = biaweb_db.get_articles (self.current_db, catid)
+ if recs == False:
+ PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in getting the articles")
+ return
+
+ self.articles.clear ()
+ for item in recs:
+ qrow = PyQt4.QtGui.QTreeWidgetItem ([str(item[0]), str(item[1])])
+ self.articles.addTopLevelItem (qrow)
+
# category add action
def onCategoryAdd (self):
# if there is no database
ret = biaweb_db.create_category (self.current_db, cat_name, cat_desc, cat_stub)
if ret == True:
PyQt4.QtGui.QMessageBox.information (self, "Success", "Category successfully created")
+ self.repopulate_categories ()
+ self.repopulate_articles ()
else:
PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in creating category")
+ # file open menu is clicked
+ def onFileOpen (self):
+ filename = PyQt4.QtGui.QFileDialog.getOpenFileName (self, "Open Site Database")
+ if filename:
+ self.current_db = str (filename)
+ self.setWindowTitle ("BiaWeb - " + self.current_db)
+ self.repopulate_categories ()
+ self.repopulate_articles ()
+
# file new menu is clicked
def onFileNew (self):
# show the site configuration dialog to get the new site details
if flag == True:
PyQt4.QtGui.QMessageBox.information (self, "Success",
"New site db successfully created")
+ self.articles.clear ()
+ self.categories.clear ()
else:
PyQt4.QtGui.QMessageBox.critical (self, "Error", "System or SQLite 3 error in creating database")
</widget>
</item>
<item row="1" column="0">
- <widget class="QListWidget" name="articles_list"/>
+ <widget class="QTreeWidget" name="articles">
+ <column>
+ <property name="text">
+ <string>Article ID</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Article Title</string>
+ </property>
+ </column>
+ </widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="dockWidgetContents_2">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
- <widget class="QListWidget" name="categories_list"/>
+ <widget class="QTreeWidget" name="categories">
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
+ <property name="allColumnsShowFocus">
+ <bool>true</bool>
+ </property>
+ <column>
+ <property name="text">
+ <string>Category ID</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Category Name</string>
+ </property>
+ </column>
+ </widget>
</item>
</layout>
</widget>
</hint>
</hints>
</connection>
+ <connection>
+ <sender>action_Open_site</sender>
+ <signal>triggered()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>onFileOpen()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>-1</x>
+ <y>-1</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>316</x>
+ <y>228</y>
+ </hint>
+ </hints>
+ </connection>
</connections>
<slots>
<slot>onFileNew()</slot>
<slot>onFileQuit()</slot>
<slot>onCategoryAdd()</slot>
+ <slot>onFileOpen()</slot>
</slots>
</ui>
# Form implementation generated from reading ui file 'main_window.ui'
#
-# Created: Fri Nov 26 17:19:44 2010
+# Created: Sat Nov 27 14:06:22 2010
# by: PyQt4 UI code generator 4.7.4
#
# WARNING! All changes made in this file will be lost!
self.label_2 = QtGui.QLabel(self.centralwidget)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1)
- self.articles_list = QtGui.QListWidget(self.centralwidget)
- self.articles_list.setObjectName("articles_list")
- self.gridLayout.addWidget(self.articles_list, 1, 0, 1, 1)
+ self.articles = QtGui.QTreeWidget(self.centralwidget)
+ self.articles.setObjectName("articles")
+ self.gridLayout.addWidget(self.articles, 1, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
self.dockWidgetContents_2.setObjectName("dockWidgetContents_2")
self.gridLayout_2 = QtGui.QGridLayout(self.dockWidgetContents_2)
self.gridLayout_2.setObjectName("gridLayout_2")
- self.categories_list = QtGui.QListWidget(self.dockWidgetContents_2)
- self.categories_list.setObjectName("categories_list")
- self.gridLayout_2.addWidget(self.categories_list, 0, 0, 1, 1)
+ self.categories = QtGui.QTreeWidget(self.dockWidgetContents_2)
+ self.categories.setAlternatingRowColors(True)
+ self.categories.setAllColumnsShowFocus(True)
+ self.categories.setObjectName("categories")
+ self.gridLayout_2.addWidget(self.categories, 0, 0, 1, 1)
self.dockWidget_2.setWidget(self.dockWidgetContents_2)
MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.dockWidget_2)
self.menubar = QtGui.QMenuBar(MainWindow)
QtCore.QObject.connect(self.actionNew_site, QtCore.SIGNAL("triggered()"), MainWindow.onFileNew)
QtCore.QObject.connect(self.action_Quit, QtCore.SIGNAL("triggered()"), MainWindow.onFileQuit)
QtCore.QObject.connect(self.action_AddCategory, QtCore.SIGNAL("triggered()"), MainWindow.onCategoryAdd)
+ QtCore.QObject.connect(self.action_Open_site, QtCore.SIGNAL("triggered()"), MainWindow.onFileOpen)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "BiaWeb - Static Website Content Manager", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Articles in category", None, QtGui.QApplication.UnicodeUTF8))
+ self.articles.headerItem().setText(0, QtGui.QApplication.translate("MainWindow", "Article ID", None, QtGui.QApplication.UnicodeUTF8))
+ self.articles.headerItem().setText(1, QtGui.QApplication.translate("MainWindow", "Article Title", None, QtGui.QApplication.UnicodeUTF8))
self.dockWidget_2.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Categories", None, QtGui.QApplication.UnicodeUTF8))
+ self.categories.headerItem().setText(0, QtGui.QApplication.translate("MainWindow", "Category ID", None, QtGui.QApplication.UnicodeUTF8))
+ self.categories.headerItem().setText(1, QtGui.QApplication.translate("MainWindow", "Category Name", None, QtGui.QApplication.UnicodeUTF8))
self.menu_About.setTitle(QtGui.QApplication.translate("MainWindow", "&Help", None, QtGui.QApplication.UnicodeUTF8))
self.menu_Settings.setTitle(QtGui.QApplication.translate("MainWindow", "&Settings", None, QtGui.QApplication.UnicodeUTF8))
self.menu_Content.setTitle(QtGui.QApplication.translate("MainWindow", "&Content", None, QtGui.QApplication.UnicodeUTF8))