X-Git-Url: https://harishankar.org/repos/?p=biaweb_qt.git;a=blobdiff_plain;f=editor_dialog.py;fp=editor_dialog.py;h=9c35a22d4ba5cbc3f44caebdc67129d924ac2bb7;hp=0000000000000000000000000000000000000000;hb=b517d55320f54925d862aca9dedb363b6d3b156d;hpb=2687a3c3b18c3a267ca60ecdd3759ed0856471e0 diff --git a/editor_dialog.py b/editor_dialog.py new file mode 100644 index 0000000..9c35a22 --- /dev/null +++ b/editor_dialog.py @@ -0,0 +1,41 @@ +# BiaWeb Website content manager (c) 2010 V.Harishankar +# Editor dialog class + +import PyQt4 +import ui_editor_dialog +import highlighter + +class EditorDialog (PyQt4.QtGui.QDialog, ui_editor_dialog.Ui_EditorDialog): + def __init__ (self, master, title, init_text): + PyQt4.QtGui.QDialog.__init__ (self, master) + self.setupUi (self) + + # set the flags to a normal maximizable window + self.setWindowFlags (PyQt4.QtCore.Qt.Window) + + # set the title + self.setWindowTitle ("Editor - " + title) + + # set text highlighting + highlighter.SimpleHtmlHighlighter (self.template_text.document ()) + + self.template_text.setPlainText (init_text) + # set modified flag to false + self.modified = False + + # when cancelled check if modified and confirm first + def reject (self): + # if modified ask confirmation first + if self.modified == True: + ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm", + "Changes will be lost. Are you sure you wish to cancel editing?", + PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No) + # if confirmed + if ans == PyQt4.QtGui.QMessageBox.Yes: + PyQt4.QtGui.QDialog.reject (self) + # not modified + else: + PyQt4.QtGui.QDialog.reject (self) + + def onTextChanged (self): + self.modified = True