def occur(self, what, regex=False): content = self.toPlainText().split('\n') if regex: regexp = QRegExp(what, Qt.CaseInsensitive) content = [line for line in content if regexp.indexIn(line) >= 0] else: what = what.lower() content = [line for line in content if what in line.lower()] content = '\n'.join(content) window = QMainWindow(self) window.resize(600, 800) window.setWindowTitle('Lines matching %r' % what) widget = QTextEdit(window) widget.setFont(self.font()) window.setCentralWidget(widget) widget.setText(content) window.show()
def on_filter_editTextChanged(self, text): for i in range(self.filter.count()): if text == self.filter.itemText(i): rx = QRegExp(self.filter.itemData(i)) break else: rx = QRegExp(text) for i in range(self.tree.topLevelItemCount()): setupitem = self.tree.topLevelItem(i) all_children_hidden = True for j in range(setupitem.childCount()): devitem = setupitem.child(j) if rx.indexIn(devitem.text(0)) == -1: devitem.setHidden(True) else: devitem.setHidden(False) all_children_hidden = False setupitem.setHidden(all_children_hidden)