import sqlite3
import os
import os.path
-import pprint
+
+# function to set the configuration and update the database
+def set_configuration (dbname, site_title, site_url, keywords, description, copyright,
+ num_rss, dest_path):
+ try:
+ conn = sqlite3.connect (dbname)
+ c = conn.cursor ()
+ c.executemany ("UPDATE config SET config_param=? WHERE config_name=?;",
+ [[site_url, "Website URL"],
+ [site_title, "Website Title"],
+ [keywords, "Keywords"],
+ [description, "Description"],
+ [num_rss, "No. of RSS items"],
+ [dest_path, "Destination path"],
+ [copyright, "Copyright"]])
+ conn.commit ()
+ conn.close ()
+ return True
+ except sqlite3.Error:
+ return False
+
+# function to get the existing site configuration and return it as a tuple
+def get_configuration (dbname):
+ try:
+ conn = sqlite3.connect (dbname)
+ c = conn.cursor ()
+ c.execute ("SELECT * FROM config;")
+ conn.commit ()
+ recs = c.fetchall ()
+ conn.close ()
+ for name, param in recs:
+ if name == "Website URL":
+ website_url = param
+ elif name == "Website Title":
+ website_title = param
+ elif name == "Keywords":
+ keywords = param
+ elif name == "Description":
+ description = param
+ elif name == "No. of RSS items":
+ num_rss = int (param)
+ elif name == "Destination path":
+ destination = param
+ elif name == "Copyright":
+ copyright = param
+ return (website_url, website_title, keywords, description, num_rss, destination, copyright)
+ except sqlite3.Error:
+ return False
+
# function to create a category
def create_category (dbname, category_name, category_desc, category_stub):
c.execute ("SELECT * FROM articles WHERE cid=?", (category_id,))
conn.commit ()
rows = c.fetchall ()
+ conn.close ()
return rows
except sqlite3.Error:
return False
qrow = PyQt4.QtGui.QTreeWidgetItem ([str(item[0]), str(item[1])])
self.articles.addTopLevelItem (qrow)
+ # configuration dialog
+ def onConfiguration (self):
+ if self.current_db == None:
+ PyQt4.QtGui.QMessageBox.critical (self, "Error",
+ "Cannot edit configuration. You need to create or open a website first")
+ else:
+ dlg = scd.SiteConfigDialog (self)
+ configs = biaweb_db.get_configuration (self.current_db)
+
+ dlg.site_url.setText (configs[0])
+ dlg.site_title.setText (configs[1])
+ dlg.keywords.setText (configs[2])
+ dlg.description.setPlainText (configs[3])
+ dlg.num_rss_items.setValue (configs[4])
+ dlg.destination.setText (configs[5])
+ dlg.copyright.setText (configs[6])
+
+ if (dlg.exec_ () == PyQt4.QtGui.QDialog.Accepted):
+ site_title = str (dlg.site_title.text ()).strip ()
+ site_url = str (dlg.site_url.text ()).strip ()
+ keywords = str (dlg.keywords.text ()).strip ()
+ destination = str (dlg.destination.text ()).strip ()
+ description = str (dlg.description.toPlainText ()).strip ()
+ num_rss = dlg.num_rss_items.value ()
+ copyright = str (dlg.copyright.text ()).strip ()
+ flag = biaweb_db.set_configuration (self.current_db, site_title, site_url, keywords, description,
+ copyright, num_rss, destination)
+ if flag == False:
+ PyQt4.QtGui.QMessageBox.critical (self, "Error",
+ "SQLite 3 error in updating configuration")
+
+
# category add action
def onCategoryAdd (self):
# if there is no database
if self.current_db == None:
PyQt4.QtGui.QMessageBox.critical (self, "Error",
- "Cannot add category. You need to create or open a website first.")
+ "Cannot add category. You need to create or open a website first")
else:
# show the category add dialog
dlg = catd.CategoryDialog (self)
</item>
<item row="1" column="0">
<widget class="QTreeWidget" name="articles">
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
<column>
<property name="text">
<string>Article ID</string>
</hint>
</hints>
</connection>
+ <connection>
+ <sender>action_Configuration</sender>
+ <signal>triggered()</signal>
+ <receiver>MainWindow</receiver>
+ <slot>onConfiguration()</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>
+ <slot>onConfiguration()</slot>
</slots>
</ui>
# Form implementation generated from reading ui file 'main_window.ui'
#
-# Created: Sat Nov 27 14:06:22 2010
+# Created: Sat Nov 27 16:21:08 2010
# by: PyQt4 UI code generator 4.7.4
#
# WARNING! All changes made in this file will be lost!
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 0, 0, 1, 1)
self.articles = QtGui.QTreeWidget(self.centralwidget)
+ self.articles.setAlternatingRowColors(True)
self.articles.setObjectName("articles")
self.gridLayout.addWidget(self.articles, 1, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
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.QObject.connect(self.action_Configuration, QtCore.SIGNAL("triggered()"), MainWindow.onConfiguration)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):