CMS 3D CMS Logo

BoxContentDialog.py
Go to the documentation of this file.
1 import logging
2 
3 from PyQt4.QtCore import *
4 from PyQt4.QtGui import *
5 
6 class BoxContentDialog(QDialog):
7  def __init__(self, parent=None):
8  logging.debug(__name__ + ': __init__')
9  QDialog.__init__(self, parent)
10  self.setWindowFlags(Qt.Window)
11  self.setWindowTitle("Set box content...")
12 
13  self._buttons = []
14 
15  self.fill()
16  self.hide()
17 
18  def fill(self):
19  logging.debug(__name__ + ': fill')
20  self._scriptLabel = QLabel("Script: ")
21  self._scriptTextEdit = QTextEdit()
22 
23  self._applyButton = QPushButton("&Apply")
24  self._applyButton.setDefault(True)
25  self._helpButton = QPushButton("&Help")
26  self._cancelButton = QPushButton("&Cancel")
27 
28  self.setLayout(QVBoxLayout())
29  self._layout3 = QHBoxLayout()
30  self._layout4 = QHBoxLayout()
31 
32  self.layout().addWidget(self._scriptLabel)
33  self.layout().addWidget(self._scriptTextEdit)
34  self.layout().addStretch()
35  self.layout().addLayout(self._layout3)
36  self.layout().addLayout(self._layout4)
37 
38  self._layout4.addWidget(self._cancelButton)
39  self._layout4.addWidget(self._helpButton)
40  self._layout4.addStretch()
41  self._layout4.addWidget(self._applyButton)
42 
43  self.connect(self._applyButton, SIGNAL('clicked(bool)'), self.apply)
44  self.connect(self._helpButton, SIGNAL('clicked(bool)'), self.help)
45  self.connect(self._cancelButton, SIGNAL('clicked(bool)'), self.reject)
46 
47  self._addLabelLabel = QLabel("Add: ")
48  self._layout3.addWidget(self._addLabelLabel)
49  self.addButton("&Space", "' '")
50  self.addButton("&New line", "'\n'")
51  self._layout3.addStretch()
52 
53  def addButton(self, name, script):
54  button = QPushButton(name)
55  button.script = script
56  self._buttons += [button]
57  self._layout3.addWidget(button)
58  self.connect(button, SIGNAL('pressed()'), self.buttonPressed)
59 
60  def buttonPressed(self):
61  for button in self._buttons:
62  if button.isDown():
63  if self.script() != "":
64  self._scriptTextEdit.textCursor().insertText("+")
65  self._scriptTextEdit.textCursor().insertText(button.script)
66 
67  def onScreen(self):
68  logging.debug(__name__ + ': onScreen')
69  self.show()
70  self.raise_()
71  self.activateWindow()
72  self._scriptTextEdit.setFocus()
73 
74  def keyPressEvent(self, event):
75  """
76  """
77  if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_W:
78  self.close()
79  QDialog.keyPressEvent(self, event)
80 
81  def script(self):
82  return str(self._scriptTextEdit.toPlainText().toAscii()).replace("\n", "\\n")
83 
84  def setScript(self, script):
85  self._scriptTextEdit.insertPlainText(script)
86 
87  def apply(self):
88  self.emit(SIGNAL("scriptChanged"), self.script())
89  self.accept()
90 
91  def help(self):
92  QMessageBox.about(self, 'Info', "This dialog allows you to specify what text shall be displayed inside the boxes of the center view. You can specify any valid Python string or use the buttons to fill the string.")
93 
def replace(string, replacements)
#define str(s)