Resource file and enhanced article dialog
[biaweb_qt.git] / main_window.py
1 # BiaWeb Website content manager (c) 2010 V.Harishankar
2 # Main Window class
3
4 import PyQt4
5 import ui_main_window
6 import site_configuration_dialog as scd
7 import category_dialog as catd
8 import biaweb_db
9 import sys
10
11 class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
12 def __init__ (self):
13 PyQt4.QtGui.QMainWindow.__init__ (self)
14 self.setupUi (self)
15 self.current_db = None
16
17 # category add action
18 def onCategoryAdd (self):
19 # if there is no database
20 if self.current_db == None:
21 PyQt4.QtGui.QMessageBox.critical (self, "Error",
22 "Cannot add category. You need to create or open a website first.")
23 else:
24 # show the category add dialog
25 dlg = catd.CategoryDialog (self)
26 # if OK button is pressed
27 if dlg.exec_ () == PyQt4.QtGui.QDialog.Accepted:
28 cat_name = str (dlg.category_name.text ()).strip ()
29 cat_desc = str (dlg.category_desc.text ()).strip ()
30 cat_stub = str (dlg.category_stub.text ()).strip ()
31 ret = biaweb_db.create_category (self.current_db, cat_name, cat_desc, cat_stub)
32 if ret == True:
33 PyQt4.QtGui.QMessageBox.information (self, "Success", "Category successfully created")
34 else:
35 PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in creating category")
36
37 # file new menu is clicked
38 def onFileNew (self):
39 # show the site configuration dialog to get the new site details
40 dlg = scd.SiteConfigDialog (self)
41 # if OK button is pressed
42 if dlg.exec_ () == PyQt4.QtGui.QDialog.Accepted:
43 site_title = str (dlg.site_title.text ()).strip ()
44 site_url = str (dlg.site_url.text ()).strip ()
45 keywords = str (dlg.keywords.text ()).strip ()
46 destination = str (dlg.destination.text ()).strip ()
47 description = str (dlg.description.toPlainText ()).strip ()
48 num_rss = dlg.num_rss_items.value ()
49 copyright = str (dlg.copyright.text ()).strip ()
50
51 savefilename = PyQt4.QtGui.QFileDialog.getSaveFileName (self, "Save site database to")
52
53 if savefilename:
54 self.current_db = str (savefilename)
55 self.setWindowTitle ("BiaWeb - " + self.current_db)
56 flag = biaweb_db.create_db (self.current_db, site_title, site_url, keywords, description,
57 copyright, num_rss, destination)
58 if flag == True:
59 PyQt4.QtGui.QMessageBox.information (self, "Success",
60 "New site db successfully created")
61 else:
62 PyQt4.QtGui.QMessageBox.critical (self, "Error", "System or SQLite 3 error in creating database")
63
64 # file quit is clicked
65 def onFileQuit (self):
66 sys.exit (0)