From: Harishankar Date: Sat, 27 Nov 2010 15:41:39 +0000 (+0530) Subject: Implemented category delete and more X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=commitdiff_plain;h=e14aab0777f4dcc7200894ee75fab329007adb53 Implemented category delete and more * Implemented category deletion * When category selection changes, articles from selected category are displayed now * View->Refresh menu implemented --- diff --git a/biaweb_db.py b/biaweb_db.py index 4487339..9caad08 100644 --- a/biaweb_db.py +++ b/biaweb_db.py @@ -31,6 +31,19 @@ def update_category (dbname, catid, cat_name, cat_desc, cat_stub): except sqlite3.Error: return False +# function to remove a category +def remove_category (dbname, catid): + try: + conn = sqlite3.connect (dbname) + c = conn.cursor () + c.execute ("DELETE FROM categories WHERE cid=?;", (catid,)) + c.execute ("DELETE FROM articles WHERE cid=?;", (catid,)) + conn.commit () + conn.close () + return True + except sqlite3.Error: + return False + # function to set the configuration and update the database def set_configuration (dbname, site_title, site_url, keywords, description, copyright, num_rss, dest_path): diff --git a/main_window.py b/main_window.py index 4d4afa3..0d6c91a 100644 --- a/main_window.py +++ b/main_window.py @@ -38,7 +38,19 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): qrow = PyQt4.QtGui.QTreeWidgetItem ([str(item[0]), str(item[1])]) self.articles.addTopLevelItem (qrow) - # configuration dialog + # when the view is refreshed + def onViewRefresh (self): + if self.current_db is not None: + self.repopulate_categories () + self.repopulate_articles () + + # when item selection is changed in categories tree widget + def onCategorySelectionChanged (self): + if self.current_db is not None: + catid = self.get_selected_item_id (self.categories) + self.repopulate_articles (catid) + + # when configuration menu is activated def onConfiguration (self): if self.current_db == None: PyQt4.QtGui.QMessageBox.critical (self, "Error", @@ -126,6 +138,32 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow): PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in updating category") + # category delete action + def onCategoryDelete (self): + # if there is no database + if self.current_db == None: + PyQt4.QtGui.QMessageBox.critical (self, "Error", + "Cannot edit category. You need to create or open a website first") + else: + # get the selected category + catid = self.get_selected_item_id (self.categories) + if catid is None: + PyQt4.QtGui.QMessageBox.critical (self, "Error", "No category selected") + # category is selected + else: + # get confirmation first + flag = PyQt4.QtGui.QMessageBox.question (self, "Confirm", + "This will delete the category and all associated articles. Are you sure you wish to continue?", + PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No) + # if confirmed + if flag == PyQt4.QtGui.QMessageBox.Yes: + ret = biaweb_db.remove_category (self.current_db, catid) + if ret == False: + PyQt4.QtGui.QMessageBox.critical (self, "Error", "SQLite 3 error in deleting category") + else: + self.repopulate_categories () + self.repopulate_articles () + # category add action def onCategoryAdd (self): # if there is no database diff --git a/main_window.ui b/main_window.ui index 74c1602..d539c32 100644 --- a/main_window.ui +++ b/main_window.ui @@ -62,6 +62,9 @@ true + + QAbstractItemView::SingleSelection + false @@ -133,9 +136,16 @@ + + + &View + + + + @@ -265,6 +275,17 @@ asasas + + + &Refresh + + + Reload categories and articles in the view + + + F5 + + @@ -364,6 +385,54 @@ + + action_RemoveCategory + triggered() + MainWindow + onCategoryDelete() + + + -1 + -1 + + + 316 + 228 + + + + + categories + itemSelectionChanged() + MainWindow + onCategorySelectionChanged() + + + 226 + 211 + + + 279 + 233 + + + + + action_Refresh + triggered() + MainWindow + onViewRefresh() + + + -1 + -1 + + + 316 + 228 + + + onFileNew() @@ -372,5 +441,8 @@ onFileOpen() onConfiguration() onCategoryEdit() + onCategoryDelete() + onCategorySelectionChanged() + onViewRefresh() diff --git a/ui_main_window.py b/ui_main_window.py index 8080f31..fdca9eb 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: Sat Nov 27 19:17:18 2010 +# Created: Sat Nov 27 21:09:13 2010 # by: PyQt4 UI code generator 4.7.4 # # WARNING! All changes made in this file will be lost! @@ -38,6 +38,7 @@ class Ui_MainWindow(object): self.gridLayout_2.setObjectName("gridLayout_2") self.categories = QtGui.QTreeWidget(self.dockWidgetContents_2) self.categories.setAlternatingRowColors(True) + self.categories.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) self.categories.setAllColumnsShowFocus(False) self.categories.setObjectName("categories") self.gridLayout_2.addWidget(self.categories, 0, 0, 1, 1) @@ -56,6 +57,8 @@ class Ui_MainWindow(object): self.menu_File_2.setObjectName("menu_File_2") self.menu_Export_web = QtGui.QMenu(self.menu_File_2) self.menu_Export_web.setObjectName("menu_Export_web") + self.menu_View = QtGui.QMenu(self.menubar) + self.menu_View.setObjectName("menu_View") MainWindow.setMenuBar(self.menubar) self.actionOpen_DB = QtGui.QAction(MainWindow) self.actionOpen_DB.setObjectName("actionOpen_DB") @@ -91,6 +94,8 @@ class Ui_MainWindow(object): self.actionSamth.setObjectName("actionSamth") self.actionAsasas = QtGui.QAction(MainWindow) self.actionAsasas.setObjectName("actionAsasas") + self.action_Refresh = QtGui.QAction(MainWindow) + self.action_Refresh.setObjectName("action_Refresh") self.menu_About.addAction(self.action_About) self.menu_Settings.addAction(self.action_Configuration) self.menu_Settings.addSeparator() @@ -110,9 +115,11 @@ class Ui_MainWindow(object): self.menu_File_2.addAction(self.menu_Export_web.menuAction()) self.menu_File_2.addSeparator() self.menu_File_2.addAction(self.action_Quit) + self.menu_View.addAction(self.action_Refresh) self.menubar.addAction(self.menu_File_2.menuAction()) self.menubar.addAction(self.menu_Content.menuAction()) self.menubar.addAction(self.menu_Settings.menuAction()) + self.menubar.addAction(self.menu_View.menuAction()) self.menubar.addAction(self.menu_About.menuAction()) self.retranslateUi(MainWindow) @@ -122,6 +129,9 @@ class Ui_MainWindow(object): QtCore.QObject.connect(self.action_Open_site, QtCore.SIGNAL("triggered()"), MainWindow.onFileOpen) QtCore.QObject.connect(self.action_Configuration, QtCore.SIGNAL("triggered()"), MainWindow.onConfiguration) QtCore.QObject.connect(self.action_EditCategory, QtCore.SIGNAL("triggered()"), MainWindow.onCategoryEdit) + QtCore.QObject.connect(self.action_RemoveCategory, QtCore.SIGNAL("triggered()"), MainWindow.onCategoryDelete) + QtCore.QObject.connect(self.categories, QtCore.SIGNAL("itemSelectionChanged()"), MainWindow.onCategorySelectionChanged) + QtCore.QObject.connect(self.action_Refresh, QtCore.SIGNAL("triggered()"), MainWindow.onViewRefresh) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): @@ -137,6 +147,7 @@ class Ui_MainWindow(object): self.menu_Content.setTitle(QtGui.QApplication.translate("MainWindow", "&Content", None, QtGui.QApplication.UnicodeUTF8)) self.menu_File_2.setTitle(QtGui.QApplication.translate("MainWindow", "&File", None, QtGui.QApplication.UnicodeUTF8)) self.menu_Export_web.setTitle(QtGui.QApplication.translate("MainWindow", "&Export web", None, QtGui.QApplication.UnicodeUTF8)) + self.menu_View.setTitle(QtGui.QApplication.translate("MainWindow", "&View", None, QtGui.QApplication.UnicodeUTF8)) self.actionOpen_DB.setText(QtGui.QApplication.translate("MainWindow", "Open existing site...", None, QtGui.QApplication.UnicodeUTF8)) self.action_Quit.setText(QtGui.QApplication.translate("MainWindow", "&Quit", None, QtGui.QApplication.UnicodeUTF8)) self.action_Quit.setStatusTip(QtGui.QApplication.translate("MainWindow", "Quit", None, QtGui.QApplication.UnicodeUTF8)) @@ -168,4 +179,7 @@ class Ui_MainWindow(object): self.actionTemplates.setStatusTip(QtGui.QApplication.translate("MainWindow", "Modify or revert site templates", None, QtGui.QApplication.UnicodeUTF8)) self.actionSamth.setText(QtGui.QApplication.translate("MainWindow", "samth", None, QtGui.QApplication.UnicodeUTF8)) self.actionAsasas.setText(QtGui.QApplication.translate("MainWindow", "asasas", None, QtGui.QApplication.UnicodeUTF8)) + self.action_Refresh.setText(QtGui.QApplication.translate("MainWindow", "&Refresh", None, QtGui.QApplication.UnicodeUTF8)) + self.action_Refresh.setStatusTip(QtGui.QApplication.translate("MainWindow", "Reload categories and articles in the view", None, QtGui.QApplication.UnicodeUTF8)) + self.action_Refresh.setShortcut(QtGui.QApplication.translate("MainWindow", "F5", None, QtGui.QApplication.UnicodeUTF8))