From 684bcd9d36d19308ec8d02ae6e92df6b4e71dcb9 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 9 Nov 2020 11:48:44 +0100 Subject: Improve search - Add clear button - Fix minor some behavior bugs - Expand tree items --- gui.py | 13 ++++++++++--- muddle.ui | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gui.py b/gui.py index 3cb1474..1edf4c9 100644 --- a/gui.py +++ b/gui.py @@ -23,6 +23,7 @@ from PyQt5.QtCore import ( pyqtSlot, pyqtSignal, QObject, + QRegularExpression, QSortFilterProxyModel, ) @@ -276,7 +277,7 @@ class MuddleWindow(QMainWindow): logging.getLogger("muddle").addHandler(self.loghandler) # set up proxymodel for moodle treeview - moodleTreeWidget = MoodleTreeWidget(None) + moodleTreeWidget = MoodleTreeWidget(None) # TODO: refractor into model self.filter = MoodleTreeFilterModel() self.filter.setRecursiveFilteringEnabled(True) @@ -292,6 +293,7 @@ class MuddleWindow(QMainWindow): # searchbar searchBar = self.findChild(QLineEdit, "searchBar") searchBar.textChanged.connect(self.onSearchBarTextChanged) + searchBar.textEdited.connect(self.onSearchBarTextChanged) # local filesystem view self.downloadPath = QDir.homePath() @@ -317,9 +319,14 @@ class MuddleWindow(QMainWindow): @pyqtSlot(str) def onSearchBarTextChanged(self, text): if not text: - self.filter.invalidateFilter() + self.filter.setFilterRegularExpression(".*") else: - self.filter.setFilterRegExp(text) + regexp = QRegularExpression(text) + if regexp.isValid(): + self.filter.setFilterRegularExpression(regexp) + self.findChild(QTreeView, "moodleTree").expandAll() + else: + log.debug("invalid search regular expression, not searching") @pyqtSlot(str) def onNewLogMessage(self, msg): diff --git a/muddle.ui b/muddle.ui index b9b0414..02dbae5 100644 --- a/muddle.ui +++ b/muddle.ui @@ -65,6 +65,9 @@ Search (regexp) + + true + -- cgit v1.2.1