CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TextDialog.py
Go to the documentation of this file.
1 from PyQt4.QtCore import SIGNAL
2 from PyQt4.QtGui import QTextEdit,QPushButton,QGridLayout,QTextCursor,QDialog,QMessageBox
3 
4 class TextDialog(QDialog):
5  """ QDialog object to edit text by using an editor window.
6  """
7  def __init__(self, parent=None, title="Edit text...", text="", readonly=False, help=None):
8  super(TextDialog,self).__init__(parent)
9  self.setWindowTitle(title)
10  self.resize(600,500)
11  self.text=text
12  self.help=help
13  self.ok = QPushButton('Ok', self)
14  self.connect(self.ok, SIGNAL('clicked()'), self.accept)
15  if not readonly:
16  self.cancel = QPushButton('Cancel', self)
17  self.connect(self.cancel, SIGNAL('clicked()'), self.reject)
18  if help:
19  self.helpButton = QPushButton('Help', self)
20  self.connect(self.helpButton, SIGNAL('clicked()'), self.showHelp)
21  self.edit=QTextEdit()
22  self.edit.setPlainText(self.text)
23  layout=QGridLayout()
24  layout.addWidget(self.edit,0,0,1,4)
25  layout.addWidget(self.ok,1,3)
26  if not readonly:
27  layout.addWidget(self.cancel,1,0)
28  if help:
29  layout.addWidget(self.helpButton,1,1)
30  self.setLayout(layout)
31  self.edit.setReadOnly(readonly)
32  self.edit.setFocus()
33  self.edit.moveCursor(QTextCursor.End)
34 
35  def getText(self):
36  return self.edit.toPlainText().toAscii()
37 
38  def showHelp(self):
39  QMessageBox.about(self, 'Info', self.help)