Implemented category delete and more
authorHarishankar <v.harishankar@gmail.com>
Sat, 27 Nov 2010 15:41:39 +0000 (21:11 +0530)
committerHarishankar <v.harishankar@gmail.com>
Sat, 27 Nov 2010 15:41:39 +0000 (21:11 +0530)
* Implemented category deletion
* When category selection changes, articles from selected category
  are displayed now
* View->Refresh menu implemented

biaweb_db.py
main_window.py
main_window.ui
ui_main_window.py

index 4487339..9caad08 100644 (file)
@@ -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):
index 4d4afa3..0d6c91a 100644 (file)
@@ -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
index 74c1602..d539c32 100644 (file)
@@ -62,6 +62,9 @@
        <property name="alternatingRowColors">
         <bool>true</bool>
        </property>
+       <property name="selectionMode">
+        <enum>QAbstractItemView::SingleSelection</enum>
+       </property>
        <property name="allColumnsShowFocus">
         <bool>false</bool>
        </property>
     <addaction name="separator"/>
     <addaction name="action_Quit"/>
    </widget>
+   <widget class="QMenu" name="menu_View">
+    <property name="title">
+     <string>&amp;View</string>
+    </property>
+    <addaction name="action_Refresh"/>
+   </widget>
    <addaction name="menu_File_2"/>
    <addaction name="menu_Content"/>
    <addaction name="menu_Settings"/>
+   <addaction name="menu_View"/>
    <addaction name="menu_About"/>
   </widget>
   <action name="actionOpen_DB">
     <string>asasas</string>
    </property>
   </action>
+  <action name="action_Refresh">
+   <property name="text">
+    <string>&amp;Refresh</string>
+   </property>
+   <property name="statusTip">
+    <string>Reload categories and articles in the view</string>
+   </property>
+   <property name="shortcut">
+    <string>F5</string>
+   </property>
+  </action>
  </widget>
  <resources/>
  <connections>
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>action_RemoveCategory</sender>
+   <signal>triggered()</signal>
+   <receiver>MainWindow</receiver>
+   <slot>onCategoryDelete()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>-1</x>
+     <y>-1</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>316</x>
+     <y>228</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>categories</sender>
+   <signal>itemSelectionChanged()</signal>
+   <receiver>MainWindow</receiver>
+   <slot>onCategorySelectionChanged()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>226</x>
+     <y>211</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>279</x>
+     <y>233</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>action_Refresh</sender>
+   <signal>triggered()</signal>
+   <receiver>MainWindow</receiver>
+   <slot>onViewRefresh()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>-1</x>
+     <y>-1</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>316</x>
+     <y>228</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
  <slots>
   <slot>onFileNew()</slot>
   <slot>onFileOpen()</slot>
   <slot>onConfiguration()</slot>
   <slot>onCategoryEdit()</slot>
+  <slot>onCategoryDelete()</slot>
+  <slot>onCategorySelectionChanged()</slot>
+  <slot>onViewRefresh()</slot>
  </slots>
 </ui>
index 8080f31..fdca9eb 100644 (file)
@@ -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))