From 592798cba4152c0726edeb629da48cc8ac23a3a3 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Sun, 28 Nov 2010 20:27:40 +0530 Subject: [PATCH] Article dialog internals implemented Fully implemented the internals of the article dialog. Only the create/edit functionality is left to be implemented. --- article_dialog.py | 19 ++++++++++++++ article_dialog.ui | 60 ++++++++++++++++++++++++++++---------------- highlighter.py | 10 +++++++- main_window.py | 8 +++++- main_window.ui | 17 +++++++++++++ ui_article_dialog.py | 52 ++++++++++++++++++++------------------ ui_main_window.py | 3 ++- 7 files changed, 120 insertions(+), 49 deletions(-) diff --git a/article_dialog.py b/article_dialog.py index ddd9d18..3923a26 100644 --- a/article_dialog.py +++ b/article_dialog.py @@ -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): diff --git a/article_dialog.ui b/article_dialog.ui index 3d3b726..62ee75f 100644 --- a/article_dialog.ui +++ b/article_dialog.ui @@ -23,8 +23,14 @@ true - + + + + 75 + true + + Title @@ -33,8 +39,14 @@ - + + + + 50 + false + + Keywords @@ -43,8 +55,14 @@ - + + + + 50 + false + + Summary @@ -60,8 +78,14 @@ - + + + + 75 + true + + Article content @@ -434,7 +458,7 @@ p, li { white-space: pre-wrap; } - 1 + -1 10 @@ -443,6 +467,12 @@ p, li { white-space: pre-wrap; } + + + 75 + true + + Stub (file name without HTML extension) @@ -619,6 +649,9 @@ p, li { white-space: pre-wrap; } Qt::ScrollBarAlwaysOn + + true + @@ -627,23 +660,6 @@ p, li { white-space: pre-wrap; } article_title keywords summary - bold - italic - preformat - image - link - paraleft - paracenter - pararight - parajustify - bullets - numbered - blockquote - codeblock - table - hrule - paragraph - linebreak content category rating diff --git a/highlighter.py b/highlighter.py index 95cfa90..3213755 100644 --- a/highlighter.py +++ b/highlighter.py @@ -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 diff --git a/main_window.py b/main_window.py index b2547b6..ff4f3cf 100644 --- a/main_window.py +++ b/main_window.py @@ -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: diff --git a/main_window.ui b/main_window.ui index ab98a30..5849977 100644 --- a/main_window.ui +++ b/main_window.ui @@ -485,6 +485,22 @@ + + categories + itemActivated(QTreeWidgetItem*,int) + MainWindow + onCategoryItemActivated() + + + 212 + 156 + + + 276 + 272 + + + onFileNew() @@ -499,5 +515,6 @@ onArticleAdd() onArticleEdit() onArticleDelete() + onCategoryItemActivated() diff --git a/ui_article_dialog.py b/ui_article_dialog.py index d9dc575..5f0876a 100644 --- a/ui_article_dialog.py +++ b/ui_article_dialog.py @@ -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) diff --git a/ui_main_window.py b/ui_main_window.py index e14e758..9298f1f 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: 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) -- 2.20.1