Article dialog internals implemented
authorHarishankar <v.harishankar@gmail.com>
Sun, 28 Nov 2010 14:57:40 +0000 (20:27 +0530)
committerHarishankar <v.harishankar@gmail.com>
Sun, 28 Nov 2010 14:57:40 +0000 (20:27 +0530)
Fully implemented the internals of the article dialog. Only the
create/edit functionality is left to be implemented.

article_dialog.py
article_dialog.ui
highlighter.py
main_window.py
main_window.ui
ui_article_dialog.py
ui_main_window.py

index ddd9d18..3923a26 100644 (file)
@@ -20,6 +20,25 @@ class ArticleDialog (PyQt4.QtGui.QDialog, ui_article_dialog.Ui_ArticleDialog):
                if ans == PyQt4.QtGui.QMessageBox.Yes:
                        PyQt4.QtGui.QDialog.reject (self)
 
+       # when accepted check the data
+       def accept (self):
+               title = str (self.article_title.text ()).strip ()
+               content = str (self.content.toPlainText ()).strip ()
+               stub = str (self.stub.text ()).strip ()
+
+               if title <> "" and content <> "" and stub <> "":
+                       PyQt4.QtGui.QDialog.accept (self)
+               else:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Missing fields", "Some required fields are missing")
+
+       # populate categories in combo box
+       def populate_categories (self, category_list, selected_cat = None):
+               for catid, catname, catdesc, stub in category_list:
+                       self.category.addItem (catname, int (catid))
+
+               # set the index to the selected category item
+               if selected_cat is not None:
+                       self.category.setCurrentIndex (self.category.findData (selected_cat))
 
        # when bold is clicked
        def onBold (self):
index 3d3b726..62ee75f 100644 (file)
    <bool>true</bool>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="0" column="0">
+   <item row="0" column="0" colspan="3">
     <widget class="QLabel" name="label">
+     <property name="font">
+      <font>
+       <weight>75</weight>
+       <bold>true</bold>
+      </font>
+     </property>
      <property name="text">
       <string>Title</string>
      </property>
    <item row="0" column="3" colspan="19">
     <widget class="QLineEdit" name="article_title"/>
    </item>
-   <item row="1" column="0" colspan="2">
+   <item row="1" column="0" colspan="3">
     <widget class="QLabel" name="label_2">
+     <property name="font">
+      <font>
+       <weight>50</weight>
+       <bold>false</bold>
+      </font>
+     </property>
      <property name="text">
       <string>Keywords</string>
      </property>
    <item row="1" column="3" colspan="19">
     <widget class="QLineEdit" name="keywords"/>
    </item>
-   <item row="2" column="0" colspan="2">
+   <item row="2" column="0" colspan="3">
     <widget class="QLabel" name="label_3">
+     <property name="font">
+      <font>
+       <weight>50</weight>
+       <bold>false</bold>
+      </font>
+     </property>
      <property name="text">
       <string>Summary</string>
      </property>
      </property>
     </widget>
    </item>
-   <item row="3" column="0" colspan="3">
+   <item row="3" column="0" colspan="4">
     <widget class="QLabel" name="label_5">
+     <property name="font">
+      <font>
+       <weight>75</weight>
+       <bold>true</bold>
+      </font>
+     </property>
      <property name="text">
       <string>Article content</string>
      </property>
@@ -434,7 +458,7 @@ p, li { white-space: pre-wrap; }
    <item row="6" column="16" colspan="6">
     <widget class="QSpinBox" name="rating">
      <property name="minimum">
-      <number>1</number>
+      <number>-1</number>
      </property>
      <property name="maximum">
       <number>10</number>
@@ -443,6 +467,12 @@ p, li { white-space: pre-wrap; }
    </item>
    <item row="7" column="0" colspan="11">
     <widget class="QLabel" name="label_7">
+     <property name="font">
+      <font>
+       <weight>75</weight>
+       <bold>true</bold>
+      </font>
+     </property>
      <property name="text">
       <string>Stub (file name without HTML extension)</string>
      </property>
@@ -619,6 +649,9 @@ p, li { white-space: pre-wrap; }
      <property name="verticalScrollBarPolicy">
       <enum>Qt::ScrollBarAlwaysOn</enum>
      </property>
+     <property name="tabChangesFocus">
+      <bool>true</bool>
+     </property>
     </widget>
    </item>
   </layout>
@@ -627,23 +660,6 @@ p, li { white-space: pre-wrap; }
   <tabstop>article_title</tabstop>
   <tabstop>keywords</tabstop>
   <tabstop>summary</tabstop>
-  <tabstop>bold</tabstop>
-  <tabstop>italic</tabstop>
-  <tabstop>preformat</tabstop>
-  <tabstop>image</tabstop>
-  <tabstop>link</tabstop>
-  <tabstop>paraleft</tabstop>
-  <tabstop>paracenter</tabstop>
-  <tabstop>pararight</tabstop>
-  <tabstop>parajustify</tabstop>
-  <tabstop>bullets</tabstop>
-  <tabstop>numbered</tabstop>
-  <tabstop>blockquote</tabstop>
-  <tabstop>codeblock</tabstop>
-  <tabstop>table</tabstop>
-  <tabstop>hrule</tabstop>
-  <tabstop>paragraph</tabstop>
-  <tabstop>linebreak</tabstop>
   <tabstop>content</tabstop>
   <tabstop>category</tabstop>
   <tabstop>rating</tabstop>
index 95cfa90..3213755 100644 (file)
@@ -9,16 +9,24 @@ class SimpleHtmlHighlighter (PyQt4.QtGui.QSyntaxHighlighter):
 
        def highlightBlock (self, text):
                # define the character highlight formats
+
+               # for tags
                charfmt1 = PyQt4.QtGui.QTextCharFormat ()
                charfmt1.setFontWeight (PyQt4.QtGui.QFont.Bold)
                charfmt1.setForeground (PyQt4.QtCore.Qt.blue)
 
+               # for strings
                charfmt2 = PyQt4.QtGui.QTextCharFormat ()
                charfmt2.setForeground (PyQt4.QtCore.Qt.darkGreen)
 
+               # for html entities
+               charfmt3 = PyQt4.QtGui.QTextCharFormat ()
+               charfmt3.setForeground (PyQt4.QtCore.Qt.magenta)
+
                # matching regular expressions
                htmltagexps = [ (PyQt4.QtCore.QRegExp ("<[^<>]+>"), charfmt1),
-                                               (PyQt4.QtCore.QRegExp ("\"[^\"]+\""), charfmt2)
+                                               (PyQt4.QtCore.QRegExp ("\"[^\"]+\""), charfmt2),
+                                               (PyQt4.QtCore.QRegExp ("&[^;]+;"), charfmt3)
                                        ]
 
                # run through the list of regular expressions to highlight
index b2547b6..ff4f3cf 100644 (file)
@@ -57,8 +57,10 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
                                PyQt4.QtGui.QMessageBox.critical (self, "Error", "No category selected for article")
                                return
                        artdlg = artd.ArticleDialog (self)
-                       artdlg.exec_ ()
+                       cats = biaweb_db.get_categories (self.current_db)
 
+                       artdlg.populate_categories (cats, catid)
+                       artdlg.exec_ ()
 
        # when edit article is triggered
        def onArticleEdit (self):
@@ -68,6 +70,10 @@ class MainWindow (PyQt4.QtGui.QMainWindow, ui_main_window.Ui_MainWindow):
        def onArticleDelete (self):
                pass
 
+       # when category item is activated
+       def onCategoryItemActivated (self):
+               self.onCategoryEdit ()
+
        # when item selection is changed in categories tree widget
        def onCategorySelectionChanged (self):
                if self.current_db is not None:
index ab98a30..5849977 100644 (file)
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>categories</sender>
+   <signal>itemActivated(QTreeWidgetItem*,int)</signal>
+   <receiver>MainWindow</receiver>
+   <slot>onCategoryItemActivated()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>212</x>
+     <y>156</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>276</x>
+     <y>272</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
  <slots>
   <slot>onFileNew()</slot>
   <slot>onArticleAdd()</slot>
   <slot>onArticleEdit()</slot>
   <slot>onArticleDelete()</slot>
+  <slot>onCategoryItemActivated()</slot>
  </slots>
 </ui>
index d9dc575..5f0876a 100644 (file)
@@ -2,7 +2,7 @@
 
 # Form implementation generated from reading ui file 'article_dialog.ui'
 #
-# Created: Sun Nov 28 17:32:45 2010
+# Created: Sun Nov 28 20:16:53 2010
 #      by: PyQt4 UI code generator 4.7.4
 #
 # WARNING! All changes made in this file will be lost!
@@ -19,28 +19,44 @@ class Ui_ArticleDialog(object):
         self.gridLayout = QtGui.QGridLayout(ArticleDialog)
         self.gridLayout.setObjectName("gridLayout")
         self.label = QtGui.QLabel(ArticleDialog)
+        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.gridLayout.addWidget(self.label, 0, 0, 1, 3)
         self.article_title = QtGui.QLineEdit(ArticleDialog)
         self.article_title.setObjectName("article_title")
         self.gridLayout.addWidget(self.article_title, 0, 3, 1, 19)
         self.label_2 = QtGui.QLabel(ArticleDialog)
+        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, 2)
+        self.gridLayout.addWidget(self.label_2, 1, 0, 1, 3)
         self.keywords = QtGui.QLineEdit(ArticleDialog)
         self.keywords.setObjectName("keywords")
         self.gridLayout.addWidget(self.keywords, 1, 3, 1, 19)
         self.label_3 = QtGui.QLabel(ArticleDialog)
+        font = QtGui.QFont()
+        font.setWeight(50)
+        font.setBold(False)
+        self.label_3.setFont(font)
         self.label_3.setObjectName("label_3")
-        self.gridLayout.addWidget(self.label_3, 2, 0, 1, 2)
+        self.gridLayout.addWidget(self.label_3, 2, 0, 1, 3)
         self.summary = QtGui.QPlainTextEdit(ArticleDialog)
         self.summary.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
         self.summary.setTabChangesFocus(True)
         self.summary.setObjectName("summary")
         self.gridLayout.addWidget(self.summary, 2, 3, 1, 19)
         self.label_5 = QtGui.QLabel(ArticleDialog)
+        font = QtGui.QFont()
+        font.setWeight(75)
+        font.setBold(True)
+        self.label_5.setFont(font)
         self.label_5.setObjectName("label_5")
-        self.gridLayout.addWidget(self.label_5, 3, 0, 1, 3)
+        self.gridLayout.addWidget(self.label_5, 3, 0, 1, 4)
         self.bold = QtGui.QToolButton(ArticleDialog)
         font = QtGui.QFont()
         font.setWeight(75)
@@ -166,11 +182,15 @@ class Ui_ArticleDialog(object):
         self.label_6.setObjectName("label_6")
         self.gridLayout.addWidget(self.label_6, 6, 13, 1, 2)
         self.rating = QtGui.QSpinBox(ArticleDialog)
-        self.rating.setMinimum(1)
+        self.rating.setMinimum(-1)
         self.rating.setMaximum(10)
         self.rating.setObjectName("rating")
         self.gridLayout.addWidget(self.rating, 6, 16, 1, 6)
         self.label_7 = QtGui.QLabel(ArticleDialog)
+        font = QtGui.QFont()
+        font.setWeight(75)
+        font.setBold(True)
+        self.label_7.setFont(font)
         self.label_7.setObjectName("label_7")
         self.gridLayout.addWidget(self.label_7, 7, 0, 1, 11)
         self.stub = QtGui.QLineEdit(ArticleDialog)
@@ -234,6 +254,7 @@ class Ui_ArticleDialog(object):
         font.setFamily("Monospace")
         self.content.setFont(font)
         self.content.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
+        self.content.setTabChangesFocus(True)
         self.content.setObjectName("content")
         self.gridLayout.addWidget(self.content, 5, 0, 1, 22)
 
@@ -260,24 +281,7 @@ class Ui_ArticleDialog(object):
         QtCore.QMetaObject.connectSlotsByName(ArticleDialog)
         ArticleDialog.setTabOrder(self.article_title, self.keywords)
         ArticleDialog.setTabOrder(self.keywords, self.summary)
-        ArticleDialog.setTabOrder(self.summary, self.bold)
-        ArticleDialog.setTabOrder(self.bold, self.italic)
-        ArticleDialog.setTabOrder(self.italic, self.preformat)
-        ArticleDialog.setTabOrder(self.preformat, self.image)
-        ArticleDialog.setTabOrder(self.image, self.link)
-        ArticleDialog.setTabOrder(self.link, self.paraleft)
-        ArticleDialog.setTabOrder(self.paraleft, self.paracenter)
-        ArticleDialog.setTabOrder(self.paracenter, self.pararight)
-        ArticleDialog.setTabOrder(self.pararight, self.parajustify)
-        ArticleDialog.setTabOrder(self.parajustify, self.bullets)
-        ArticleDialog.setTabOrder(self.bullets, self.numbered)
-        ArticleDialog.setTabOrder(self.numbered, self.blockquote)
-        ArticleDialog.setTabOrder(self.blockquote, self.codeblock)
-        ArticleDialog.setTabOrder(self.codeblock, self.table)
-        ArticleDialog.setTabOrder(self.table, self.hrule)
-        ArticleDialog.setTabOrder(self.hrule, self.paragraph)
-        ArticleDialog.setTabOrder(self.paragraph, self.linebreak)
-        ArticleDialog.setTabOrder(self.linebreak, self.content)
+        ArticleDialog.setTabOrder(self.summary, self.content)
         ArticleDialog.setTabOrder(self.content, self.category)
         ArticleDialog.setTabOrder(self.category, self.rating)
         ArticleDialog.setTabOrder(self.rating, self.stub)
index e14e758..9298f1f 100644 (file)
@@ -2,7 +2,7 @@
 
 # Form implementation generated from reading ui file 'main_window.ui'
 #
-# Created: Sun Nov 28 15:30:11 2010
+# Created: Sun Nov 28 20:24:17 2010
 #      by: PyQt4 UI code generator 4.7.4
 #
 # WARNING! All changes made in this file will be lost!
@@ -135,6 +135,7 @@ class Ui_MainWindow(object):
         QtCore.QObject.connect(self.action_NewArticle, QtCore.SIGNAL("triggered()"), MainWindow.onArticleAdd)
         QtCore.QObject.connect(self.action_EditArticle, QtCore.SIGNAL("triggered()"), MainWindow.onArticleEdit)
         QtCore.QObject.connect(self.action_DeleteArticle, QtCore.SIGNAL("triggered()"), MainWindow.onArticleDelete)
+        QtCore.QObject.connect(self.categories, QtCore.SIGNAL("itemActivated(QTreeWidgetItem*,int)"), MainWindow.onCategoryItemActivated)
         QtCore.QMetaObject.connectSlotsByName(MainWindow)
         MainWindow.setTabOrder(self.categories, self.articles)