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
)
41 # configuration dialog
42 def onConfiguration (self
):
43 if self
.current_db
== None:
44 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error",
45 "Cannot edit configuration. You need to create or open a website first")
47 dlg
= scd
.SiteConfigDialog (self
)
48 configs
= biaweb_db
.get_configuration (self
.current_db
)
50 dlg
.site_url
.setText (configs
[0])
51 dlg
.site_title
.setText (configs
[1])
52 dlg
.keywords
.setText (configs
[2])
53 dlg
.description
.setPlainText (configs
[3])
54 dlg
.num_rss_items
.setValue (configs
[4])
55 dlg
.destination
.setText (configs
[5])
56 dlg
.copyright
.setText (configs
[6])
58 if (dlg
.exec_ () == PyQt4
.QtGui
.QDialog
.Accepted
):
59 site_title
= str (dlg
.site_title
.text ()).strip ()
60 site_url
= str (dlg
.site_url
.text ()).strip ()
61 keywords
= str (dlg
.keywords
.text ()).strip ()
62 destination
= str (dlg
.destination
.text ()).strip ()
63 description
= str (dlg
.description
.toPlainText ()).strip ()
64 num_rss
= dlg
.num_rss_items
.value ()
65 copyright
= str (dlg
.copyright
.text ()).strip ()
66 flag
= biaweb_db
.set_configuration (self
.current_db
, site_title
, site_url
, keywords
, description
,
67 copyright
, num_rss
, destination
)
69 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error",
70 "SQLite 3 error in updating configuration")
74 def onCategoryAdd (self
):
75 # if there is no database
76 if self
.current_db
== None:
77 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error",
78 "Cannot add category. You need to create or open a website first")
80 # show the category add dialog
81 dlg
= catd
.CategoryDialog (self
)
82 # if OK button is pressed
83 if dlg
.exec_ () == PyQt4
.QtGui
.QDialog
.Accepted
:
84 cat_name
= str (dlg
.category_name
.text ()).strip ()
85 cat_desc
= str (dlg
.category_desc
.text ()).strip ()
86 cat_stub
= str (dlg
.category_stub
.text ()).strip ()
87 ret
= biaweb_db
.create_category (self
.current_db
, cat_name
, cat_desc
, cat_stub
)
89 PyQt4
.QtGui
.QMessageBox
.information (self
, "Success", "Category successfully created")
90 self
.repopulate_categories ()
91 self
.repopulate_articles ()
93 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error", "SQLite 3 error in creating category")
95 # file open menu is clicked
96 def onFileOpen (self
):
97 filename
= PyQt4
.QtGui
.QFileDialog
.getOpenFileName (self
, "Open Site Database")
99 self
.current_db
= str (filename
)
100 self
.setWindowTitle ("BiaWeb - " + self
.current_db
)
101 self
.repopulate_categories ()
102 self
.repopulate_articles ()
104 # file new menu is clicked
105 def onFileNew (self
):
106 # show the site configuration dialog to get the new site details
107 dlg
= scd
.SiteConfigDialog (self
)
108 # if OK button is pressed
109 if dlg
.exec_ () == PyQt4
.QtGui
.QDialog
.Accepted
:
110 site_title
= str (dlg
.site_title
.text ()).strip ()
111 site_url
= str (dlg
.site_url
.text ()).strip ()
112 keywords
= str (dlg
.keywords
.text ()).strip ()
113 destination
= str (dlg
.destination
.text ()).strip ()
114 description
= str (dlg
.description
.toPlainText ()).strip ()
115 num_rss
= dlg
.num_rss_items
.value ()
116 copyright
= str (dlg
.copyright
.text ()).strip ()
118 savefilename
= PyQt4
.QtGui
.QFileDialog
.getSaveFileName (self
, "Save site database to")
121 self
.current_db
= str (savefilename
)
122 self
.setWindowTitle ("BiaWeb - " + self
.current_db
)
123 flag
= biaweb_db
.create_db (self
.current_db
, site_title
, site_url
, keywords
, description
,
124 copyright
, num_rss
, destination
)
126 PyQt4
.QtGui
.QMessageBox
.information (self
, "Success",
127 "New site db successfully created")
128 self
.articles
.clear ()
129 self
.categories
.clear ()
131 PyQt4
.QtGui
.QMessageBox
.critical (self
, "Error", "System or SQLite 3 error in creating database")
133 # file quit is clicked
134 def onFileQuit (self
):