mirror of
https://github.com/lutris/lutris
synced 2024-10-04 14:59:37 +00:00
Search for Lutris games asynchronously
Use AsynCall to query the Lutris api without freezing the UI. Also, add a Gtk.Spinner that shows when the search is happening. Also, use a SearchEntry for searching.
This commit is contained in:
parent
76b9a48480
commit
33a288cf38
|
@ -54,6 +54,7 @@ class AddGamesWindow(BaseApplicationWindow): # pylint: disable=too-many-public-
|
|||
super().__init__(application=application)
|
||||
self.set_default_size(640, 450)
|
||||
self.search_timer_id = None
|
||||
self.search_spinner = None
|
||||
self.text_query = None
|
||||
self.result_label = None
|
||||
self.title_label = Gtk.Label(visible=True)
|
||||
|
@ -124,8 +125,12 @@ class AddGamesWindow(BaseApplicationWindow): # pylint: disable=too-many-public-
|
|||
"""Search installers with the Lutris API"""
|
||||
self.title_label.set_markup("<b>Search Lutris.net</b>")
|
||||
self.listbox.destroy()
|
||||
entry = Gtk.Entry(visible=True)
|
||||
self.vbox.add(entry)
|
||||
hbox = Gtk.Box(Gtk.Orientation.HORIZONTAL, visible=True)
|
||||
entry = Gtk.SearchEntry(visible=True)
|
||||
hbox.pack_start(entry, True, True, 0)
|
||||
self.search_spinner = Gtk.Spinner(visible=False)
|
||||
hbox.pack_end(self.search_spinner, False, False, 6)
|
||||
self.vbox.add(hbox)
|
||||
self.result_label = self._get_label("")
|
||||
self.vbox.add(self.result_label)
|
||||
entry.connect("changed", self._on_search_updated)
|
||||
|
@ -192,9 +197,25 @@ class AddGamesWindow(BaseApplicationWindow): # pylint: disable=too-many-public-
|
|||
self.destroy()
|
||||
|
||||
def update_search_results(self):
|
||||
if not self.text_query:
|
||||
# Don't start a search while another is going; defer it instead.
|
||||
if self.search_spinner.get_visible():
|
||||
self.search_timer_id = GLib.timeout_add(750, self.update_search_results)
|
||||
return
|
||||
api_games = api.search_games(self.text_query)
|
||||
|
||||
self.search_timer_id = None
|
||||
|
||||
if self.text_query:
|
||||
self.search_spinner.show()
|
||||
self.search_spinner.start()
|
||||
AsyncCall(api.search_games, self.update_search_results_cb, self.text_query)
|
||||
|
||||
def update_search_results_cb(self, api_games, error):
|
||||
if error:
|
||||
ErrorDialog(error)
|
||||
return
|
||||
|
||||
self.search_spinner.stop()
|
||||
self.search_spinner.hide()
|
||||
total_count = api_games.get("count", 0)
|
||||
count = len(api_games.get('results', []))
|
||||
|
||||
|
|
Loading…
Reference in a new issue