added delay for the search and filter functions

This commit is contained in:
DYefremov
2018-08-24 12:03:51 +03:00
parent 0dcbf98d1f
commit 76a0f43485
2 changed files with 30 additions and 4 deletions

View File

@@ -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

View File

@@ -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())