1 # BiaWeb Website content manager (c) 2010 V.Harishankar
6 import site_configuration_dialog
as scd
7 import category_dialog
as catd
11 class MainWindow (PyQt4
.QtGui
.QMainWindow
, ui_main_window
.Ui_MainWindow
):
13 PyQt4
.QtGui
.QMainWindow
.__init
__ (self
)
15 self
.current_db
= None
17 # refresh the category list
18 def repopulate_categories (self
):
19 recs
= biaweb_db
.get_categories (self
.current_db
)
21 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error", "SQLite 3 error in getting the categories")
24 self
.categories
.clear ()
25 for (id, name
, desc
, stub
) in recs
:
26 qrow
= PyQt4
.QtGui
.QTreeWidgetItem ([str(id), str(name
)])
27 self
.categories
.addTopLevelItem (qrow
)
29 # refresh the articles list
30 def repopulate_articles (self
, catid
=None):
31 recs
= biaweb_db
.get_articles (self
.current_db
, catid
)
33 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error", "SQLite 3 error in getting the articles")
36 self
.articles
.clear ()
38 qrow
= PyQt4
.QtGui
.QTreeWidgetItem ([str(item
[0]), str(item
[1])])
39 self
.articles
.addTopLevelItem (qrow
)
42 def onCategoryAdd (self
):
43 # if there is no database
44 if self
.current_db
== None:
45 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error",
46 "Cannot add category. You need to create or open a website first.")
48 # show the category add dialog
49 dlg
= catd
.CategoryDialog (self
)
50 # if OK button is pressed
51 if dlg
.exec_ () == PyQt4
.QtGui
.QDialog
.Accepted
:
52 cat_name
= str (dlg
.category_name
.text ()).strip ()
53 cat_desc
= str (dlg
.category_desc
.text ()).strip ()
54 cat_stub
= str (dlg
.category_stub
.text ()).strip ()
55 ret
= biaweb_db
.create_category (self
.current_db
, cat_name
, cat_desc
, cat_stub
)
57 PyQt4
.QtGui
.QMessageBox
.information (self
, "Success", "Category successfully created")
58 self
.repopulate_categories ()
59 self
.repopulate_articles ()
61 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error", "SQLite 3 error in creating category")
63 # file open menu is clicked
64 def onFileOpen (self
):
65 filename
= PyQt4
.QtGui
.QFileDialog
.getOpenFileName (self
, "Open Site Database")
67 self
.current_db
= str (filename
)
68 self
.setWindowTitle ("BiaWeb - " + self
.current_db
)
69 self
.repopulate_categories ()
70 self
.repopulate_articles ()
72 # file new menu is clicked
74 # show the site configuration dialog to get the new site details
75 dlg
= scd
.SiteConfigDialog (self
)
76 # if OK button is pressed
77 if dlg
.exec_ () == PyQt4
.QtGui
.QDialog
.Accepted
:
78 site_title
= str (dlg
.site_title
.text ()).strip ()
79 site_url
= str (dlg
.site_url
.text ()).strip ()
80 keywords
= str (dlg
.keywords
.text ()).strip ()
81 destination
= str (dlg
.destination
.text ()).strip ()
82 description
= str (dlg
.description
.toPlainText ()).strip ()
83 num_rss
= dlg
.num_rss_items
.value ()
84 copyright
= str (dlg
.copyright
.text ()).strip ()
86 savefilename
= PyQt4
.QtGui
.QFileDialog
.getSaveFileName (self
, "Save site database to")
89 self
.current_db
= str (savefilename
)
90 self
.setWindowTitle ("BiaWeb - " + self
.current_db
)
91 flag
= biaweb_db
.create_db (self
.current_db
, site_title
, site_url
, keywords
, description
,
92 copyright
, num_rss
, destination
)
94 PyQt4
.QtGui
.QMessageBox
.information (self
, "Success",
95 "New site db successfully created")
96 self
.articles
.clear ()
97 self
.categories
.clear ()
99 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error", "System or SQLite 3 error in creating database")
101 # file quit is clicked
102 def onFileQuit (self
):