X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=main_window.py;h=5902fbccbc3a362a29036331131c68ca4c4ecb72;hp=36320753c987a4ce42230e259b2596975651cfe5;hb=35c21d64e5d7554d2c610599a87c7f236b83d992;hpb=51a6ece9a63764e7a57230081d299f36d3186918 diff --git a/main_window.py b/main_window.py index 3632075..5902fbc 100644 --- a/main_window.py +++ b/main_window.py @@ -4,6 +4,7 @@ import PyQt4 import ui_main_window import site_configuration_dialog as scd +import category_dialog as catd import biaweb_db import sys @@ -13,8 +14,31 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): self.setupUi (self) self.current_db = None + # 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.") + else: + # show the category add dialog + dlg = catd.CategoryDialog (self) + # if OK button is pressed + if dlg.exec_ () == PyQt4.QtGui.QDialog.Accepted: + cat_name = str (dlg.category_name.text ()).strip () + cat_desc = str (dlg.category_desc.text ()).strip () + cat_stub = str (dlg.category_stub.text ()).strip () + ret = biaweb_db.create_category (self.current_db, cat_name, cat_desc, cat_stub) + if ret == True: + PyQt4.QtGui.QMessageBox.information (self, "Success", "Category successfully created") + else: + PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in creating category") + + # file new menu is clicked def onFileNew (self): + # show the site configuration dialog to get the new site details dlg = scd.SiteConfigDialog (self) + # if OK button is pressed if dlg.exec_ () == PyQt4.QtGui.QDialog.Accepted: site_title = str (dlg.site_title.text ()).strip () site_url = str (dlg.site_url.text ()).strip () @@ -27,15 +51,16 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): savefilename = PyQt4.QtGui.QFileDialog.getSaveFileName (self, "Save site database to") if savefilename: - self.current_db = savefilename + self.current_db = str (savefilename) self.setWindowTitle ("BiaWeb - " + self.current_db) - flag = biaweb_db.create_db (str (savefilename), site_title, site_url, keywords, description, + flag = biaweb_db.create_db (self.current_db, site_title, site_url, keywords, description, copyright, num_rss, destination) if flag == True: PyQt4.QtGui.QMessageBox.information (self, "Success", "New site db successfully created") else: - PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in creating database.") + PyQt4.QtGui.QMessageBox.critical (self, "Error", "System or SQLite 3 error in creating database") + # file quit is clicked def onFileQuit (self): sys.exit (0)