X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=article_dialog.py;h=6b51e705dc93942a207ec9b46a2384be744d542e;hp=787f8d2bd16d9f625d97320e71df954e6ab11c8b;hb=54389d5adbbb1830a7e85545b2bdde816713a272;hpb=d698bb44596dd96533a9aef0f25c03c20a1bf1d2 diff --git a/article_dialog.py b/article_dialog.py index 787f8d2..6b51e70 100644 --- a/article_dialog.py +++ b/article_dialog.py @@ -1,11 +1,235 @@ # BiaWeb Website content manager (c) 2010 V.Harishankar -# Category dialog class +# Article dialog class import PyQt4 import ui_article_dialog +import highlighter class ArticleDialog (PyQt4.QtGui.QDialog, ui_article_dialog.Ui_ArticleDialog): def __init__ (self, parent): PyQt4.QtGui.QDialog.__init__ (self, parent) self.setupUi (self) + # set window to be able to be maximized or minimized + self.setWindowFlags (PyQt4.QtCore.Qt.Window) + # set the code highlighter to the document + self.hltext = highlighter.SimpleHtmlHighlighter (self.content.document ()) + # when rejected, confirm first + def reject (self): + ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm", + "Are you sure you wish to cancel all changes?", + PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No) + 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): + textcur = self.content.textCursor () + sel = textcur.selectedText () + boldsel = "" + sel + "" + textcur.insertText (boldsel) + + # when block quote is clicked + def onBQuote (self): + textcur = self.content.textCursor () + sel = textcur.selectedText () + quotesel = "
\n" + sel + "\n
" + textcur.insertText (quotesel) + + # when bullet is clicked + def onBullet (self): + # insert bulleted list + self.insert_list_items () + + # when code is clicked + def onCode (self): + textcur = self.content.textCursor () + sel = textcur.selectedText () + codesel = "" + str (sel) + "" + textcur.insertText (codesel) + + # when horiz rule is clicked + def onHRule (self): + textcur = self.content.textCursor () + hrule = "\n
\n" + textcur.clearSelection () + textcur.insertText (hrule) + + # when image is clicked + def onImage (self): + img_url, ok = PyQt4.QtGui.QInputDialog.getText (self, "Image URL", "URL of the image to insert") + if not ok or img_url.isEmpty (): + return + alt_txt, ok = PyQt4.QtGui.QInputDialog.getText (self, "Alt text", "Alternate text of the image") + if not ok or alt_txt.isEmpty (): + return + + textcur = self.content.textCursor () + imgtag = '' + alt_txt + '' + textcur.clearSelection () + textcur.insertText (imgtag) + + # when italic is clicked + def onItalic (self): + textcur = self.content.textCursor () + sel = textcur.selectedText () + italsel = "" + sel + "" + textcur.insertText (italsel) + + # when link is clicked + def onLink (self): + linkhref, ok = PyQt4.QtGui.QInputDialog.getText (self, "Link URL", "URL of the link to insert") + if not ok or linkhref.isEmpty (): + return + textcur = self.content.textCursor () + sel = textcur.selectedText () + linksel = '' + sel + "" + textcur.insertText (linksel) + + # when numbered is clicked + def onNumber (self): + # numbered list + self.insert_list_items (True) + + # get a list of items in numbered or bulleted list + def insert_list_items (self, numbered = False): + if numbered: + title = "Numbered list" + otag = "\n
    \n" + ctag = "
\n" + else: + title = "Bulleted list" + otag = "\n\n" + + itemlist = [ otag ] + while True: + num_item, ok = PyQt4.QtGui.QInputDialog.getText (self, title, + "List item content (leave blank to finish the list)") + # if cancelled quit + if not ok: + return + # if item is empty then close the list + if num_item.isEmpty (): + break + itemlist.append ("
  • " + num_item + "
  • \n") + itemlist.append (ctag) + + textcur = self.content.textCursor () + textcur.clearSelection () + for item in itemlist: + textcur.insertText (item) + + + # when center is clicked + def onCenter (self): + textcur = self.content.textCursor () + sel = textcur.selectedText () + paracentersel = '

    ' + sel + "

    " + textcur.insertText (paracentersel) + + # when justify is clicked + def onJustify (self): + textcur = self.content.textCursor () + sel = textcur.selectedText () + parajustsel = '

    ' + sel + "

    " + textcur.insertText (parajustsel) + + # when left is clicked + def onLeft (self): + textcur = self.content.textCursor () + sel = textcur.selectedText () + paraleftsel = '

    ' + sel + "

    " + textcur.insertText (paraleftsel) + + # when right is clicked + def onRight (self): + textcur = self.content.textCursor () + sel = textcur.selectedText () + pararightsel = '

    ' + sel + "

    " + textcur.insertText (pararightsel) + + # when pre is clicked + def onPre (self): + textcur = self.content.textCursor () + sel = textcur.selectedText () + presel = "
    " + sel + "
    " + textcur.insertText (presel) + + # when para is clicked + def onPara (self): + textcur = self.content.textCursor () + sel = textcur.selectedText () + parasel = "

    " + sel + "

    " + textcur.insertText (parasel) + + # when table is clicked + def onTable (self): + # get the number of rows + rows, ok = PyQt4.QtGui.QInputDialog.getInt (self, "Table", "Number of table rows") + if not ok: + return + # get the number of columns + cols, ok = PyQt4.QtGui.QInputDialog.getInt (self, "Table", "Number of table columns") + if not ok: + return + # should there be a header row? + headerflag = PyQt4.QtGui.QMessageBox.question (self, "Header", "Do you want additional header row?", + PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No, + PyQt4.QtGui.QMessageBox.Cancel) + if headerflag == PyQt4.QtGui.QMessageBox.Cancel: + return + + # build the table tag + tablelist = ["\n\n"] + if headerflag == PyQt4.QtGui.QMessageBox.Yes: + tablelist.append (" \n") + tablelist.append (" \n") + for i in range (cols): + tablelist.append (" \n") + tablelist.append (" \n") + tablelist.append (" \n") + + tablelist.append (" \n") + for j in range (rows): + tablelist.append (" \n") + for i in range (cols): + tablelist.append (" \n") + tablelist.append (" \n") + tablelist.append (" \n") + tablelist.append ("
    \n") + + # insert the table + textcur = self.content.textCursor () + textcur.clearSelection () + for item in tablelist: + textcur.insertText (item) + + + + # when break is clicked + def onBreak (self): + textcur = self.content.textCursor () + breaktxt = "
    \n" + textcur.clearSelection () + textcur.insertText (breaktxt)