Verified Commit 643f3e28 authored by Todd Weaver's avatar Todd Weaver
Browse files

Adding simple Gio task threading for asynchronous web calling to unblock app

Adding spinner to show query running
Refactored Search to call results directly (vs in main loop) (helped with threading simplification)
parent c4faa904
......@@ -258,3 +258,7 @@ class ResultsBox(Gtk.Box):
if not self.controls_box.get_visible():
self.controls_box.set_visible(True)
GLib.timeout_add_seconds(3, self.poll_mouse)
@Gtk.Template.Callback()
def swallow_slider_scroll_event(self, event, data):
return True
......@@ -15,12 +15,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import gi
gi.require_version('Gio', '2.0')
from gi.repository import Gio, GLib
from socket import timeout
from urllib.parse import urlencode
from gi.repository import GLib
import urllib.request
import json
from .results import ResultsBox
class Search:
def __init__(self, **kwargs):
......@@ -34,13 +39,20 @@ class Search:
"/75.0.3770.100 Safari/537.36"
})
self.do_search()
search_task = Gio.Task.new(None, None, self.show_results, None)
search_task.run_in_thread(self.do_search)
def get_strong_instance(self):
# lookup instances, get a strong one, return it
# lookup instances, get a strong one, to be done (stubbed for now)
self.instance = "https://invidious.xyz"
def do_search(self):
def clear_entries(self):
children = self.app_window.results_list.get_children()
for child in children:
child.destroy()
def do_search(self, task, source_obj, task_data, cancellable):
self.json = {}
self.get_strong_instance()
enc_query = urlencode({'q': self.query})
......@@ -60,6 +72,18 @@ class Search:
self.get_poster_url()
def show_results(self, source_obj, task_data, cancellable):
self.clear_entries()
for video_meta in self.json:
results_box = ResultsBox(self.app_window)
self.app_window.results_list.add(results_box)
results_box.setup_stream(video_meta)
self.app_window.spinner.set_visible(False)
self.app_window.results_window.set_visible(True)
def get_poster_url(self):
# tweak json with local poster url
for video_meta in self.json:
......
......@@ -119,9 +119,18 @@
<property name="description" translatable="yes">Use the &lt;b&gt;Search&lt;/b&gt; button to find videos online.</property>
</object>
</child>
<child>
<object class="GtkSpinner" id="spinner">
<property name="visible">False</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="active">True</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow" id="results_window">
<property name="visible">True</property>
<property name="visible">False </property>
<property name="can-focus">False</property>
<property name="hexpand">False</property>
<property name="vexpand">False</property>
......
......@@ -17,14 +17,12 @@
import gi
gi.require_version('Gdk', '3.0')
gi.require_version('Gio', '2.0')
gi.require_version('Gtk', '3.0')
gi.require_version('Handy', '1')
from gi.repository import Gdk, Gio, Gtk, Handy
from gi.repository import Gdk, Gtk, Handy
Handy.init()
from .results import ResultsBox
from .search import Search
@Gtk.Template(resource_path='/sm/puri/Stream/ui/window.ui')
......@@ -37,6 +35,7 @@ class StreamWindow(Handy.ApplicationWindow):
search_bar = Gtk.Template.Child()
status_page = Gtk.Template.Child()
spinner = Gtk.Template.Child()
results_window = Gtk.Template.Child()
results_list = Gtk.Template.Child()
......@@ -45,38 +44,15 @@ class StreamWindow(Handy.ApplicationWindow):
# toggle the True/False from what is current
self.search_bar.set_visible(self.search_bar_toggle.get_active())
def clear_entries(self):
children = self.results_list.get_children()
for child in children:
child.destroy()
def do_search(self, task, source_obj, task_data, cancellable):
search_results = Search(app_window = self, query = self.search_query)
self.results_window.set_visible(True)
self.clear_entries()
for video_meta in search_results.json:
results_box = ResultsBox(self)
self.results_list.add(results_box)
results_box.setup_stream(video_meta)
@Gtk.Template.Callback()
def search_entry(self, search_box):
self.status_page.set_visible(False)
self.search_query = search_box.get_text()
self.results_window.set_visible(False)
self.spinner.set_visible(True)
# threading throws errors
#
# for api legibility
#stub_data = None
#stub_callback = None
#stub_cancellable = None
#search_task = Gio.Task.new(self, stub_cancellable, stub_callback, stub_data)
#
#search_task.run_in_thread(self.do_search)
self.do_search(None, None, None, None)
# insert spinner
search_query = search_box.get_text()
search = Search(app_window = self, query = search_query)
# @Gtk.Template.Callback()
# def keypress_listener(self, widget, ev):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment