1 # BiaWeb Website content manager (c) 2010 V.Harishankar
2 # Category dialog class
5 import ui_article_dialog
7 class ArticleDialog (PyQt4
.QtGui
.QDialog
, ui_article_dialog
.Ui_ArticleDialog
):
8 def __init__ (self
, parent
):
9 PyQt4
.QtGui
.QDialog
.__init
__ (self
, parent
)
12 # when rejected, confirm first
14 ans
= PyQt4
.QtGui
.QMessageBox
.question (self
, "Confirm",
15 "Are you sure you wish to cancel all changes?",
16 PyQt4
.QtGui
.QMessageBox
.Yes
, PyQt4
.QtGui
.QMessageBox
.No
)
17 if ans
== PyQt4
.QtGui
.QMessageBox
.Yes
:
18 PyQt4
.QtGui
.QDialog
.reject (self
)
21 # when bold is clicked
23 textcur
= self
.content
.textCursor ()
24 sel
= textcur
.selectedText ()
25 boldsel
= "<b>" + sel
+ "</b>"
26 textcur
.insertText (boldsel
)
28 # when block quote is clicked
30 textcur
= self
.content
.textCursor ()
31 sel
= textcur
.selectedText ()
32 quotesel
= "<blockquote>\n" + sel
+ "\n</blockquote>"
33 textcur
.insertText (quotesel
)
35 # when bullet is clicked
37 # insert bulleted list
38 self
.insert_list_items ()
40 # when code is clicked
42 textcur
= self
.content
.textCursor ()
43 sel
= textcur
.selectedText ()
44 codesel
= "<code>" + str (sel
) + "</code>"
45 textcur
.insertText (codesel
)
47 # when horiz rule is clicked
49 textcur
= self
.content
.textCursor ()
51 textcur
.clearSelection ()
52 textcur
.insertText (hrule
)
54 # when image is clicked
56 img_url
, ok
= PyQt4
.QtGui
.QInputDialog
.getText (self
, "Image URL", "URL of the image to insert")
57 if not ok
or img_url
.isEmpty ():
59 alt_txt
, ok
= PyQt4
.QtGui
.QInputDialog
.getText (self
, "Alt text", "Alternate text of the image")
60 if not ok
or alt_txt
.isEmpty ():
63 textcur
= self
.content
.textCursor ()
64 imgtag
= '<img src="' + img_url
+ '" alt="' + alt_txt
+ '" />'
65 textcur
.clearSelection ()
66 textcur
.insertText (imgtag
)
68 # when italic is clicked
70 textcur
= self
.content
.textCursor ()
71 sel
= textcur
.selectedText ()
72 italsel
= "<i>" + sel
+ "</i>"
73 textcur
.insertText (italsel
)
75 # when link is clicked
77 linkhref
, ok
= PyQt4
.QtGui
.QInputDialog
.getText (self
, "Link URL", "URL of the link to insert")
78 if not ok
or linkhref
.isEmpty ():
80 textcur
= self
.content
.textCursor ()
81 sel
= textcur
.selectedText ()
82 linksel
= '<a href="' + linkhref
+ '">' + sel
+ "</a>"
83 textcur
.insertText (linksel
)
85 # when numbered is clicked
88 self
.insert_list_items (True)
90 # get a list of items in numbered or bulleted list
91 def insert_list_items (self
, numbered
= False):
93 title
= "Numbered list"
97 title
= "Bulleted list"
103 num_item
, ok
= PyQt4
.QtGui
.QInputDialog
.getText (self
, title
,
104 "List item content (leave blank to finish the list)")
108 # if item is empty then close the list
109 if num_item
.isEmpty ():
111 itemlist
.append (" <li>" + num_item
+ "</li>\n")
112 itemlist
.append (ctag
)
114 textcur
= self
.content
.textCursor ()
115 textcur
.clearSelection ()
116 for item
in itemlist
:
117 textcur
.insertText (item
)
120 # when center is clicked
122 textcur
= self
.content
.textCursor ()
123 sel
= textcur
.selectedText ()
124 paracentersel
= '<p style="text-align:center;">' + sel
+ "</p>"
125 textcur
.insertText (paracentersel
)
127 # when justify is clicked
128 def onJustify (self
):
129 textcur
= self
.content
.textCursor ()
130 sel
= textcur
.selectedText ()
131 parajustsel
= '<p style="text-align:justify;">' + sel
+ "</p>"
132 textcur
.insertText (parajustsel
)
134 # when left is clicked
136 textcur
= self
.content
.textCursor ()
137 sel
= textcur
.selectedText ()
138 paraleftsel
= '<p style="text-align:left;">' + sel
+ "</p>"
139 textcur
.insertText (paraleftsel
)
141 # when right is clicked
143 textcur
= self
.content
.textCursor ()
144 sel
= textcur
.selectedText ()
145 pararightsel
= '<p style="text-align:right;">' + sel
+ "</p>"
146 textcur
.insertText (pararightsel
)
148 # when pre is clicked
150 textcur
= self
.content
.textCursor ()
151 sel
= textcur
.selectedText ()
152 presel
= "<pre>" + sel
+ "</pre>"
153 textcur
.insertText (presel
)
155 # when para is clicked
157 textcur
= self
.content
.textCursor ()
158 sel
= textcur
.selectedText ()
159 parasel
= "<p>" + sel
+ "</p>"
160 textcur
.insertText (parasel
)
162 # when table is clicked
164 # get the number of rows
165 rows
, ok
= PyQt4
.QtGui
.QInputDialog
.getInt (self
, "Table", "Number of table rows")
168 # get the number of columns
169 cols
, ok
= PyQt4
.QtGui
.QInputDialog
.getInt (self
, "Table", "Number of table columns")
172 # should there be a header row?
173 headerflag
= PyQt4
.QtGui
.QMessageBox
.question (self
, "Header", "Do you want additional header row?",
174 PyQt4
.QtGui
.QMessageBox
.Yes
, PyQt4
.QtGui
.QMessageBox
.No
,
175 PyQt4
.QtGui
.QMessageBox
.Cancel
)
176 if headerflag
== PyQt4
.QtGui
.QMessageBox
.Cancel
:
179 # build the table tag
180 tablelist
= ["\n<table>\n"]
181 if headerflag
== PyQt4
.QtGui
.QMessageBox
.Yes
:
182 tablelist
.append (" <thead>\n")
183 tablelist
.append (" <tr>\n")
184 for i
in range (cols
):
185 tablelist
.append (" <th></th>\n")
186 tablelist
.append (" </tr>\n")
187 tablelist
.append (" </thead>\n")
189 tablelist
.append (" <tbody>\n")
190 for j
in range (rows
):
191 tablelist
.append (" <tr>\n")
192 for i
in range (cols
):
193 tablelist
.append (" <td></td>\n")
194 tablelist
.append (" </tr>\n")
195 tablelist
.append (" </tbody>\n")
196 tablelist
.append ("</table>\n")
199 textcur
= self
.content
.textCursor ()
200 textcur
.clearSelection ()
201 for item
in tablelist
:
202 textcur
.insertText (item
)
206 # when break is clicked
208 textcur
= self
.content
.textCursor ()
209 breaktxt
= "\n<br />\n"
210 textcur
.clearSelection ()
211 textcur
.insertText (breaktxt
)