From 9492c8305e12a3367d105ea652acd3eddf302b7d Mon Sep 17 00:00:00 2001 From: abdo Date: Fri, 29 Jan 2021 03:40:32 +0300 Subject: [PATCH] Wait for some time before performing sidebar search --- qt/aqt/sidebar.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 798ef4301..b9f4ef332 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -185,16 +185,24 @@ class SidebarSearchBar(QLineEdit): def __init__(self, sidebar: SidebarTreeView): QLineEdit.__init__(self, sidebar) self.sidebar = sidebar + self.timer = QTimer(self) + self.timer.setInterval(600) + self.timer.setSingleShot(True) + qconnect(self.timer.timeout, self.onSearch) qconnect(self.textChanged, self.onTextChanged) def onTextChanged(self, text: str): - self.sidebar.search_for(text) + if not self.timer.isActive(): + self.timer.start() + + def onSearch(self): + self.sidebar.search_for(self.text()) def keyPressEvent(self, evt): if evt.key() in (Qt.Key_Up, Qt.Key_Down): self.sidebar.setFocus() elif evt.key() in (Qt.Key_Enter, Qt.Key_Return): - self.onTextChanged(self.text()) + self.onSearch() else: QLineEdit.keyPressEvent(self, evt)