From 35c21d64e5d7554d2c610599a87c7f236b83d992 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Fri, 26 Nov 2010 20:15:37 +0530 Subject: [PATCH] Category creation completed Category creation dialog and functionality successfully implemented --- biaweb_db.py | 23 +++++++++++++++++++++++ category_dialog.py | 18 ++++++++++++++++++ category_dialog.ui | 18 ++++++++++++++++++ main_window.py | 31 ++++++++++++++++++++++++++++--- main_window.ui | 17 +++++++++++++++++ site_configuration_dialog.py | 1 + ui_category_dialog.py | 14 +++++++++++++- ui_main_window.py | 3 ++- 8 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 category_dialog.py diff --git a/biaweb_db.py b/biaweb_db.py index 9be184d..5496453 100644 --- a/biaweb_db.py +++ b/biaweb_db.py @@ -2,9 +2,32 @@ # Database handling functions import sqlite3 +import os +import os.path +# function to create a category +def create_category (dbname, category_name, category_desc, category_stub): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("INSERT INTO categories (name, desc, stub) VALUES (?, ?, ?);", + (category_name, category_desc, category_stub)) + conn.commit () + conn.close () + return True + except sqlite3.Error: + return False + + +# function to create a new site database def create_db (dbname, site_title, site_url, keywords, description, copyright, num_rss, dest_path): + try: + if os.path.exists (dbname): + os.remove (dbname) + except OSError: + return False + try: conn = sqlite3.connect (dbname) c = conn.cursor () diff --git a/category_dialog.py b/category_dialog.py new file mode 100644 index 0000000..af7f773 --- /dev/null +++ b/category_dialog.py @@ -0,0 +1,18 @@ +# BiaWeb Website content manager (c) 2010 V.Harishankar +# Category dialog class + +import PyQt4 +import ui_category_dialog + +class CategoryDialog (PyQt4.QtGui.QDialog, ui_category_dialog.Ui_CategoryDialog): + def __init__ (self, parent): + PyQt4.QtGui.QDialog.__init__ (self, parent) + self.setupUi (self) + + def accept (self): + category_name = str (self.category_name.text ()).strip () + category_stub = str (self.category_stub.text ()).strip () + if category_name <> "" and category_stub <> "": + PyQt4.QtGui.QDialog.accept (self) + else: + PyQt4.QtGui.QMessageBox.critical (self, "Missing fields", "Some required fields are missing") diff --git a/category_dialog.ui b/category_dialog.ui index 39d2e43..89bcbed 100644 --- a/category_dialog.ui +++ b/category_dialog.ui @@ -16,6 +16,12 @@ + + + 75 + true + + Category name @@ -26,6 +32,12 @@ + + + 50 + false + + Category description @@ -36,6 +48,12 @@ + + + 75 + true + + Stub (directory) 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) diff --git a/main_window.ui b/main_window.ui index 6d83adb..61423a3 100644 --- a/main_window.ui +++ b/main_window.ui @@ -269,9 +269,26 @@ + + action_AddCategory + triggered() + MainWindow + onCategoryAdd() + + + -1 + -1 + + + 316 + 228 + + + onFileNew() onFileQuit() + onCategoryAdd() diff --git a/site_configuration_dialog.py b/site_configuration_dialog.py index 3b74ded..651889c 100644 --- a/site_configuration_dialog.py +++ b/site_configuration_dialog.py @@ -17,6 +17,7 @@ class SiteConfigDialog (PyQt4.QtGui.QDialog, uscd.Ui_SiteConfigDialog): self.destination.setText (destpath) def accept (self): + # check the required fields before accepting site_title = str (self.site_title.text ()).strip () site_url = str (self.site_url.text ()).strip () keywords = str (self.keywords.text ()).strip () diff --git a/ui_category_dialog.py b/ui_category_dialog.py index a27f428..6107c47 100644 --- a/ui_category_dialog.py +++ b/ui_category_dialog.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'category_dialog.ui' # -# Created: Wed Nov 24 14:12:44 2010 +# Created: Fri Nov 26 17:27:34 2010 # by: PyQt4 UI code generator 4.7.4 # # WARNING! All changes made in this file will be lost! @@ -16,18 +16,30 @@ class Ui_CategoryDialog(object): self.gridLayout = QtGui.QGridLayout(CategoryDialog) self.gridLayout.setObjectName("gridLayout") self.label = QtGui.QLabel(CategoryDialog) + font = QtGui.QFont() + font.setWeight(75) + font.setBold(True) + self.label.setFont(font) self.label.setObjectName("label") self.gridLayout.addWidget(self.label, 0, 0, 1, 1) self.category_name = QtGui.QLineEdit(CategoryDialog) self.category_name.setObjectName("category_name") self.gridLayout.addWidget(self.category_name, 0, 1, 1, 1) self.label_2 = QtGui.QLabel(CategoryDialog) + font = QtGui.QFont() + font.setWeight(50) + font.setBold(False) + self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1) self.category_desc = QtGui.QLineEdit(CategoryDialog) self.category_desc.setObjectName("category_desc") self.gridLayout.addWidget(self.category_desc, 1, 1, 1, 1) self.label_3 = QtGui.QLabel(CategoryDialog) + font = QtGui.QFont() + font.setWeight(75) + font.setBold(True) + self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.gridLayout.addWidget(self.label_3, 2, 0, 1, 1) self.category_stub = QtGui.QLineEdit(CategoryDialog) diff --git a/ui_main_window.py b/ui_main_window.py index 3b83164..5d613ca 100644 --- a/ui_main_window.py +++ b/ui_main_window.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'main_window.ui' # -# Created: Fri Nov 26 13:58:47 2010 +# Created: Fri Nov 26 17:19:44 2010 # by: PyQt4 UI code generator 4.7.4 # # WARNING! All changes made in this file will be lost! @@ -115,6 +115,7 @@ class Ui_MainWindow(object): self.retranslateUi(MainWindow) QtCore.QObject.connect(self.actionNew_site, QtCore.SIGNAL("triggered()"), MainWindow.onFileNew) QtCore.QObject.connect(self.action_Quit, QtCore.SIGNAL("triggered()"), MainWindow.onFileQuit) + QtCore.QObject.connect(self.action_AddCategory, QtCore.SIGNAL("triggered()"), MainWindow.onCategoryAdd) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): -- 2.20.1