aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2020-11-08 22:09:40 +0100
committerNao Pross <np@0hm.ch>2020-11-08 22:09:40 +0100
commita7a8006145cccde8a1bbdc09cdba72a7734e25b8 (patch)
treee17ffc08152bd02202131c52c6c3822ac5060b1b
parentReplace UI code with Qt designer file (diff)
downloadMuddle-a7a8006145cccde8a1bbdc09cdba72a7734e25b8.tar.gz
Muddle-a7a8006145cccde8a1bbdc09cdba72a7734e25b8.zip
Add regexp search feature
Diffstat (limited to '')
-rw-r--r--gui.py52
-rw-r--r--muddle.ui35
2 files changed, 57 insertions, 30 deletions
diff --git a/gui.py b/gui.py
index d5ea752..b2fc552 100644
--- a/gui.py
+++ b/gui.py
@@ -15,18 +15,30 @@ import tempfile
from PyQt5 import uic
from PyQt5.QtGui import QFont
from PyQt5.Qt import QStyle
-from PyQt5.QtCore import Qt, QThread, pyqtSlot, pyqtSignal, QObject
+
+from PyQt5.QtCore import (
+ Qt,
+ QThread,
+ pyqtSlot,
+ pyqtSignal,
+ QObject,
+ QSortFilterProxyModel,
+)
+
from PyQt5.QtWidgets import (
QApplication,
QMainWindow,
QWidget,
+ QTreeView,
QTreeWidget,
QTreeWidgetItem,
QTreeWidgetItemIterator,
+ QHeaderView,
QGridLayout,
QHBoxLayout,
QPushButton,
QToolButton,
+ QLineEdit,
QProgressBar,
QTabWidget,
QPlainTextEdit
@@ -94,6 +106,7 @@ class MoodleItem(QTreeWidgetItem):
self.setChildIndicatorPolicy(QTreeWidgetItem.DontShowIndicatorWhenChildless)
self.setText(0, html.unescape(self.metadata.title))
+
class MoodleFetcher(QThread):
loadedItem = pyqtSignal(MoodleItem.Type, object)
@@ -146,17 +159,28 @@ class MoodleFetcher(QThread):
return []
+class MoodleTreeFilterModel(QSortFilterProxyModel):
+ def __init__(self):
+ super().__init__()
+
+
class MoodleTreeWidget(QTreeWidget):
def __init__(self, parent):
super().__init__(parent)
self.itemDoubleClicked.connect(self.onItemDoubleClicked, Qt.QueuedConnection)
+ self.setHeaderLabels(["Item", "Size"])
+ self.sortByColumn(0, Qt.AscendingOrder)
+
self.lastInsertedItem = None
self.worker = None
@pyqtSlot(str, str)
def refresh(self, instance_url, token):
- if not self.worker or not self.worker.isFinished():
+ if not self.worker or self.worker.isFinished():
+ self.setSortingEnabled(False)
+ # TODO: remove elements if present
+
self.worker = MoodleFetcher(self, instance_url, token)
self.worker.loadedItem.connect(self.onWorkerLoadedItem)
self.worker.finished.connect(self.onWorkerDone)
@@ -222,7 +246,6 @@ class MoodleTreeWidget(QTreeWidget):
@pyqtSlot()
def onWorkerDone(self):
log.debug("worker done")
- self.sortByColumn(0, Qt.AscendingOrder)
self.setSortingEnabled(True)
@@ -249,13 +272,34 @@ class MuddleWindow(QMainWindow):
self.loghandler.newLogMessage.connect(self.onNewLogMessage)
logging.getLogger("muddle").addHandler(self.loghandler)
+ # set up proxymodel for moodle treeview
+ moodleTreeWidget = MoodleTreeWidget(None)
+ self.filter = MoodleTreeFilterModel()
+ self.filter.setRecursiveFilteringEnabled(True)
+
+ moodleTreeView = self.findChild(QTreeView, "moodleTree")
+ self.filter.setSourceModel(moodleTreeWidget.model())
+ moodleTreeView.setModel(self.filter)
+ moodleTreeView.setColumnWidth(0, 420)
+
+ # refresh moodle treeview
refreshBtn = self.findChild(QToolButton, "refreshBtn")
- moodleTreeWidget = self.findChild(MoodleTreeWidget, "moodleTree")
refreshBtn.clicked.connect(lambda b: moodleTreeWidget.refresh(instance_url, token))
+ # searchbar
+ searchBar = self.findChild(QLineEdit, "searchBar")
+ searchBar.textChanged.connect(self.onSearchBarTextChanged)
+
self.show()
@pyqtSlot(str)
+ def onSearchBarTextChanged(self, text):
+ if not text:
+ self.filter.invalidateFilter()
+ else:
+ self.filter.setFilterRegExp(text)
+
+ @pyqtSlot(str)
def onNewLogMessage(self, msg):
self.findChild(QPlainTextEdit, "logsTab").appendPlainText(msg)
diff --git a/muddle.ui b/muddle.ui
index e25a1a9..9737c7a 100644
--- a/muddle.ui
+++ b/muddle.ui
@@ -57,13 +57,13 @@
<item row="0" column="0">
<widget class="QLineEdit" name="searchBar">
<property name="enabled">
- <bool>false</bool>
+ <bool>true</bool>
</property>
<property name="inputMask">
<string/>
</property>
<property name="placeholderText">
- <string>Search</string>
+ <string>Search (regexp)</string>
</property>
</widget>
</item>
@@ -77,23 +77,6 @@
</property>
</widget>
</item>
- <item row="1" column="0" colspan="2">
- <widget class="MoodleTreeWidget" name="moodleTree">
- <property name="headerHidden">
- <bool>false</bool>
- </property>
- <column>
- <property name="text">
- <string notr="true">Item</string>
- </property>
- </column>
- <column>
- <property name="text">
- <string>Size</string>
- </property>
- </column>
- </widget>
- </item>
<item row="0" column="1">
<widget class="QToolButton" name="refreshBtn">
<property name="text">
@@ -111,6 +94,13 @@
</property>
</widget>
</item>
+ <item row="1" column="0" colspan="2">
+ <widget class="QTreeView" name="moodleTree">
+ <property name="headerHidden">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<widget class="QTreeWidget" name="localTab">
@@ -223,13 +213,6 @@
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
- <customwidgets>
- <customwidget>
- <class>MoodleTreeWidget</class>
- <extends>QTreeWidget</extends>
- <header>gui</header>
- </customwidget>
- </customwidgets>
<resources/>
<connections/>
</ui>