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):
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",
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
<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>&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>&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>
# 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!
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)
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")
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()
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)
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):
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))
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))