mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00

* Boolean naming convention * Rename no_strict_optional -> strict_optional * Update CONTRIBUTORS * Enable strict optional for aqt module * Fix errors * Enable strict optional for aqt browser * Fix layout.py errors * Fix find_duplicates.py errors * Fix browser.py errors * Revert a0 a1 names * Fix tree.py errors * Fix previewer.py errors * Fix model.py errors * Fix find_and_replace.py errors * Fix item.py errors * Fix toolbar.py errors * Fix table/__init__.py errors * Fix model.py errors * Fix state.py errors * Fix table.py errors * Fix errors in card_info.py * Fix searchbar.py errors * Fix name * Fix assert in browser.py * Formatting * Fix assert vh * assert is not None instead of truthy * Split _move_current() up to correct type signature (dae) We want either index or direction, but not both.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
# Copyright: Ankitects Pty Ltd and contributors
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
from __future__ import annotations
|
|
|
|
import aqt
|
|
import aqt.browser
|
|
import aqt.gui_hooks
|
|
from aqt.qt import *
|
|
|
|
|
|
class SidebarSearchBar(QLineEdit):
|
|
def __init__(self, sidebar: aqt.browser.sidebar.SidebarTreeView) -> None:
|
|
QLineEdit.__init__(self, sidebar)
|
|
self.setPlaceholderText(sidebar.col.tr.browsing_sidebar_filter())
|
|
self.sidebar = sidebar
|
|
self.timer = QTimer(self)
|
|
self.timer.setInterval(600)
|
|
self.timer.setSingleShot(True)
|
|
self.setFrame(False)
|
|
|
|
qconnect(self.timer.timeout, self.onSearch)
|
|
qconnect(self.textChanged, self.onTextChanged)
|
|
|
|
def onTextChanged(self, text: str) -> None:
|
|
if not self.timer.isActive():
|
|
self.timer.start()
|
|
|
|
def onSearch(self) -> None:
|
|
self.sidebar.search_for(self.text())
|
|
|
|
def keyPressEvent(self, evt: QKeyEvent | None) -> None:
|
|
assert evt is not None
|
|
if evt.key() in (Qt.Key.Key_Up, Qt.Key.Key_Down):
|
|
self.sidebar.setFocus()
|
|
elif evt.key() in (Qt.Key.Key_Enter, Qt.Key.Key_Return):
|
|
self.onSearch()
|
|
else:
|
|
QLineEdit.keyPressEvent(self, evt)
|