mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2026-07-14 19:33:17 +02:00
added delay for the search and filter functions
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
from functools import wraps
|
||||
from threading import Thread
|
||||
from threading import Thread, Timer
|
||||
|
||||
from gi.repository import GLib
|
||||
|
||||
@@ -43,5 +43,31 @@ def run_task(func):
|
||||
return wrapper
|
||||
|
||||
|
||||
def run_with_delay(timeout=5):
|
||||
""" Starts the function with a delay.
|
||||
|
||||
If the previous timer still works, it will canceled!
|
||||
"""
|
||||
|
||||
def run_with(func):
|
||||
timer = None
|
||||
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
nonlocal timer
|
||||
if timer and timer.is_alive():
|
||||
timer.cancel()
|
||||
|
||||
def run():
|
||||
GLib.idle_add(func, *args, **kwargs, priority=GLib.PRIORITY_LOW)
|
||||
|
||||
timer = Timer(interval=timeout, function=run)
|
||||
timer.start()
|
||||
|
||||
return wrapper
|
||||
|
||||
return run_with
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
|
||||
@@ -6,7 +6,7 @@ from functools import lru_cache
|
||||
|
||||
from gi.repository import GLib
|
||||
|
||||
from app.commons import run_idle, log, run_task
|
||||
from app.commons import run_idle, log, run_task, run_with_delay
|
||||
from app.eparser import get_blacklist, write_blacklist, parse_m3u
|
||||
from app.eparser import get_services, get_bouquets, write_bouquets, write_services, Bouquets, Bouquet, Service
|
||||
from app.eparser.ecommons import CAS, Flag
|
||||
@@ -1053,7 +1053,7 @@ class MainAppWindow:
|
||||
self._filter_bar.set_search_mode(active)
|
||||
self._filter_bar.set_visible(active)
|
||||
|
||||
@run_idle
|
||||
@run_with_delay(1)
|
||||
def on_filter_changed(self, entry):
|
||||
self._services_model_filter.refilter()
|
||||
|
||||
@@ -1072,7 +1072,7 @@ class MainAppWindow:
|
||||
def on_search_up(self, item):
|
||||
self._search_provider.on_search_up()
|
||||
|
||||
@run_idle
|
||||
@run_with_delay(1)
|
||||
def on_search(self, entry):
|
||||
self._search_provider.search(entry.get_text())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user