X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=main_window.py;h=799fdf8b02d10a6b317fc82f03e97131fc390b68;hp=6b7f31ad7f919c0e369bf4c8c81199465cb2a60c;hb=cd074c8da38f6cc0ad808783ca7e631967dfdd47;hpb=2687a3c3b18c3a267ca60ecdd3759ed0856471e0
diff --git a/main_window.py b/main_window.py
index 6b7f31a..799fdf8 100644
--- a/main_window.py
+++ b/main_window.py
@@ -9,6 +9,7 @@ import site_configuration_dialog as scd
import category_dialog as catd
import article_dialog as artd
import templates_dialog as tpld
+import generate_dialog as gend
import biaweb_db
class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
@@ -24,13 +25,16 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
# 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
+ return False
self.categories.clear ()
for (id, name, desc, stub) in recs:
qrow = PyQt4.QtGui.QTreeWidgetItem ([str(id), str(name)])
self.categories.addTopLevelItem (qrow)
+ # return true when successful
+ return True
+
# refresh the articles list
def repopulate_articles (self, catid=None):
recs = biaweb_db.get_articles (self.current_db, catid)
@@ -38,12 +42,14 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
# 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
+ return False
self.articles.clear ()
for item in recs:
qrow = PyQt4.QtGui.QTreeWidgetItem ([str(item[0]), str(item[1])])
self.articles.addTopLevelItem (qrow)
+ # return true when successful
+ return True
# when the view is refreshed
def onViewRefresh (self):
@@ -329,9 +335,21 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
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 ()
+
+ # added to check whether categories are loaded successfully or not
+ # if not, then reset the current_db to None
+ loaded_cats = self.repopulate_categories ()
+ loaded_arts = self.repopulate_articles ()
+ # if failed in loading either categories or articles (note: checking against
+ # False and not None)
+ if loaded_cats == False or loaded_arts == False:
+ self.current_db = None
+ PyQt4.QtGui.QMessageBox.critical (self, "Error",
+ "SQLite 3 error in loading site database. This appears to be an invalid BiaWeb database")
+ else:
+ # set the window title to the database
+ self.setWindowTitle ("BiaWeb - " + self.current_db)
+
# file new menu is clicked
def onFileNew (self):
@@ -362,6 +380,23 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
else:
PyQt4.QtGui.QMessageBox.critical (self, "Error", "System or SQLite 3 error in creating database")
+ # when generate site menu is triggered
+ def onGenerateSite (self):
+ if self.current_db is None:
+ PyQt4.QtGui.QMessageBox.critical (self, "Error",
+ "Cannot generate site. You need to create or open a website first")
+ else:
+ # run the generate site dialog
+ gendlg = gend.GenerateDialog (self, self.current_db)
+ gendlg.exec_ ()
+
+ # about menu is triggered
+ def onAbout (self):
+ PyQt4.QtGui.QMessageBox.about (self, "BiaWeb Qt",
+ "A static website/weblog content management system
\
+Copyright © 2010 Harishankar
\
+Licensed under GNU/GPL v3")
+
# file quit is clicked
def onFileQuit (self):
sys.exit (0)