+ # 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<table>\n"]
+ if headerflag == PyQt4.QtGui.QMessageBox.Yes:
+ tablelist.append (" <thead>\n")
+ tablelist.append (" <tr>\n")
+ for i in range (cols):
+ tablelist.append (" <th></th>\n")
+ tablelist.append (" </tr>\n")
+ tablelist.append (" </thead>\n")
+
+ tablelist.append (" <tbody>\n")
+ for j in range (rows):
+ tablelist.append (" <tr>\n")
+ for i in range (cols):
+ tablelist.append (" <td></td>\n")
+ tablelist.append (" </tr>\n")
+ tablelist.append (" </tbody>\n")
+ tablelist.append ("</table>\n")
+
+ # insert the table
+ textcur = self.content.textCursor ()
+ textcur.clearSelection ()
+ for item in tablelist:
+ textcur.insertText (item)
+
+