4 from PyQt4.QtGui import QDialog,QLabel,QLineEdit,QCheckBox,QPushButton,QVBoxLayout,QHBoxLayout,QMessageBox,QToolButton,QWidget,QLayout
11 logging.debug(__name__ +
': __init__')
12 QDialog.__init__(self,parent)
13 self.setWindowFlags(Qt.Window)
14 self.setWindowTitle(
"Find...")
25 logging.debug(__name__ +
': fill')
28 self._findLabelLineEdit.setToolTip(
"Example: Particle1")
35 self._findPreviousButton.hide()
37 self._findNumberLabel.hide()
43 self.setLayout(QVBoxLayout())
44 self.layout().setSizeConstraint(QLayout.SetFixedSize)
49 self._layout1.setSizeConstraint(QLayout.SetDefaultConstraint)
50 self._layout3.setSizeConstraint(QLayout.SetDefaultConstraint)
51 self._layout4.setSizeConstraint(QLayout.SetDefaultConstraint)
52 self.layout().addLayout(self.
_layout1)
53 self.layout().addLayout(self.
_layout3)
54 self.layout().addStretch()
55 self.layout().addLayout(self.
_layout4)
61 self._layout3.addStretch()
70 self._layout4.addStretch()
82 self.connect(self.
_closeButton, SIGNAL(
'clicked(bool)'), self.reject)
89 if self.sender()
in property:
95 if isinstance(o,QWidget):
97 self.layout().removeItem(object[0])
99 self._properties.remove(object)
101 self._scripts.remove(object)
105 layout2=QHBoxLayout()
107 findPropertyNameLabel = QLabel(
"Property: ")
108 findPropertyNameLineEdit = QLineEdit()
109 findPropertyNameLineEdit.setToolTip(
"Example: Label = Particle1 ")
110 findPropertyValueLabel = QLabel(
" = ")
111 findPropertyValueLineEdit = QLineEdit()
112 findPropertyValueLineEdit.setToolTip(
"Example: Label = Particle1 ")
113 propertyAdd = QToolButton()
114 propertyAdd.setText(
"+")
115 propertyDelete = QToolButton()
116 propertyDelete.setText(
"-")
121 propertyDelete.hide()
122 layout2.addWidget(propertyAdd)
123 layout2.addWidget(propertyDelete)
124 layout2.addWidget(findPropertyNameLabel)
125 layout2.addWidget(findPropertyNameLineEdit)
126 layout2.addWidget(findPropertyValueLabel)
127 layout2.addWidget(findPropertyValueLineEdit)
129 self.connect(findPropertyNameLineEdit, SIGNAL(
'textChanged(QString)'), self.
edited)
130 self.connect(findPropertyValueLineEdit, SIGNAL(
'textChanged(QString)'), self.
edited)
132 self.connect(propertyDelete, SIGNAL(
'clicked(bool)'), self.
_removeProperty)
136 self.
_properties+=[(layout2,findPropertyNameLineEdit,findPropertyValueLineEdit,findPropertyNameLabel,findPropertyValueLabel,propertyAdd,propertyDelete)]
140 if self.sender()
in script:
146 layout2=QHBoxLayout()
148 findScriptLabel = QLabel(
"Filter = ")
149 findScriptLineEdit = QLineEdit(
"")
150 findScriptLineEdit.setToolTip(
"Example: object.Label == 'Particle1' ")
151 scriptAdd = QToolButton()
152 scriptAdd.setText(
"+")
153 scriptDelete = QToolButton()
154 scriptDelete.setText(
"-")
160 layout2.addWidget(scriptAdd)
161 layout2.addWidget(scriptDelete)
162 layout2.addWidget(findScriptLabel)
163 layout2.addWidget(findScriptLineEdit)
165 self.connect(findScriptLineEdit, SIGNAL(
'textChanged(QString)'), self.
edited)
166 self.connect(scriptAdd, SIGNAL(
'clicked(bool)'), self.
_addScript)
167 self.connect(scriptDelete, SIGNAL(
'clicked(bool)'), self.
_removeScript)
171 self.
_scripts+=[(layout2,findScriptLineEdit,findScriptLabel,scriptAdd,scriptDelete)]
174 logging.debug(__name__ +
': onScreen')
178 self._findNextButton.setDefault(
True)
179 self.setWindowTitle(
"Find/Filter...")
181 self._findNextButton.setDefault(
True)
182 self.setWindowTitle(
"Find...")
184 self._filterButton.setDefault(
True)
185 self.setWindowTitle(
"Filter...")
187 self._findNextButton.setVisible(find)
189 self._findPreviousButton.setVisible(find)
190 self._filterButton.setVisible(filter)
193 self.activateWindow()
194 self._findLabelLineEdit.setFocus()
199 if event.modifiers() == Qt.ControlModifier
and event.key() == Qt.Key_W:
201 QDialog.keyPressEvent(self, event)
204 logging.debug(__name__ +
': setFindAlgorithm')
211 return str(self._findLabelLineEdit.text().toAscii())
214 logging.debug(__name__ +
': setLabel '+label)
215 self._findLabelLineEdit.setText(label)
218 return [(str(property[1].
text().toAscii()),str(property[2].
text().toAscii()))
for property
in self.
_properties]
221 return [str(script[1].
text().toAscii())
for script
in self.
_scripts]
224 return self._caseSensitiveCheckBox.checkState()==Qt.Checked
227 return self._exactMatchCheckBox.checkState()==Qt.Checked
230 self._findPreviousButton.hide()
231 if self._findNextButton.isVisible():
232 self._findNumberLabel.hide()
233 self._findNextButton.setText(
"&Find")
236 current=self._findAlgorithm.currentNumber()
237 total=self._findAlgorithm.numberOfResults()
238 message=self._findAlgorithm.message()
241 text=str(total)+
" found"
244 text=str(current)+
"/"+str(total)
248 text+=
" ("+message+
")"
249 self._findNumberLabel.setText(text)
252 logging.debug(__name__ +
': findPrevious')
253 object=self._findAlgorithm.previous()
255 self.emit(SIGNAL(
"found"),object)
258 logging.debug(__name__ +
': findNext')
259 if not self._findPreviousButton.isVisible():
260 self._findNextButton.setVisible(
False)
261 self._filterButton.setVisible(
False)
262 self._resetButton.setVisible(
False)
263 self._findNumberLabel.setText(
"Searching...")
264 self._findNumberLabel.show()
265 thread =
ThreadChain(self._findAlgorithm.findUsingFindDialog, self)
266 while thread.isRunning():
267 if not Application.NO_PROCESS_EVENTS:
268 QCoreApplication.instance().processEvents()
269 object=thread.returnValue()
270 self._findNextButton.setVisible(
True)
272 self._filterButton.setVisible(
True)
273 self._resetButton.setVisible(
True)
274 self._findPreviousButton.show()
275 self._findNextButton.setText(
"&Next")
279 self.emit(SIGNAL(
"found"),object)
282 logging.debug(__name__ +
': filter')
283 self._findNextButton.setVisible(
False)
284 self._filterButton.setVisible(
False)
285 self._resetButton.setVisible(
False)
286 self._findNumberLabel.setText(
"Searching...")
287 self._findNumberLabel.show()
288 thread =
ThreadChain(self._findAlgorithm.findUsingFindDialog, self)
289 while thread.isRunning():
290 if not Application.NO_PROCESS_EVENTS:
291 QCoreApplication.instance().processEvents()
293 self._findNextButton.setVisible(
True)
294 self._filterButton.setVisible(
True)
295 self._resetButton.setVisible(
True)
297 self.emit(SIGNAL(
"filtered"),self._findAlgorithm.results())
305 self._findAlgorithm.clear()
308 self.emit(SIGNAL(
"filtered"),
None)
312 QMessageBox.about(self,
'Info',
"You can find objects \n1. using their label shown in the center view, \n2. their properties shown in the property view, or \n3. using a Python script returning a boolean. Empty fields are ignored. Examples are shown as tool tips.")