Verified Commit 7b86bb5f authored by Todd Weaver's avatar Todd Weaver
Browse files

Combining status icon and spinner icon into one stack slot

Adding ability to backspace (or clear) search and return to default state (no results)
parent 0bdf2fe4
......@@ -26,7 +26,7 @@ class Search:
def __init__(self, **kwargs):
# for internal plugins only
self.app_window = kwargs.get('app_window', None)
self.spinner = kwargs.get('spinner', None)
self.toggle_status_spinner = kwargs.get('toggle_status_spinner', None)
self.scroller = kwargs.get('scroller', None)
self.si_index = 0
......@@ -38,7 +38,7 @@ class Search:
self.add_result_meta = kwargs.get('add_result_meta', None)
def do_search(self, query, page):
self.spinner.set_visible(True)
self.toggle_status_spinner(True)
self.query = query
esc_query = GLib.uri_escape_string(self.query, None, None)
uri = f"{self.this_instance}/api/v1/search?q={esc_query};page={page};fields=title,videoId,author,lengthSeconds,videoThumbnails"
......@@ -141,7 +141,7 @@ class Search:
# appending known playable videos to filter duplicates
self.search_video_ids.append(video_meta['videoId'])
self.spinner.set_visible(False)
self.toggle_status_spinner(False)
self.scroller.set_visible(True)
def get_download_uris(self, video_meta):
......
......@@ -51,10 +51,8 @@
<child>
<object class="GtkVolumeButton" id="volume">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="focus-on-click">False</property>
<property name="receives-default">True</property>
<property name="relief">none</property>
<property name="can-focus">True</property>
<property name="tooltip-text" translatable="yes">Volume</property>
<property name="adjustment">volume_adjustment</property>
<property name="value">0.90</property>
<property name="icons">audio-volume-muted-symbolic
......@@ -62,26 +60,41 @@ audio-volume-high-symbolic
audio-volume-low-symbolic
audio-volume-medium-symbolic</property>
<signal name="value-changed" handler="volume_change" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImage" id="status_icon">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">content-loading-symbolic</property>
<property name="icon_size">1</property>
<style>
<class name="status-icon"/>
<class name="image-button"/>
</style>
</object>
</child>
<child>
<object class="GtkSpinner" id="spinner">
<property name="visible">False</property>
<property name="can-focus">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="active">True</property>
<object class="GtkStack" id="status_staack">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkImage" id="status_icon">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">content-loading-symbolic</property>
<property name="icon_size">1</property>
<style>
<class name="status-icon"/>
</style>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkSpinner" id="status_spinner">
<property name="visible">False</property>
<property name="can-focus">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="active">True</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="pack-type">end</property>
......@@ -133,6 +146,7 @@ audio-volume-medium-symbolic</property>
<property name="primary-icon-activatable">False</property>
<property name="primary-icon-sensitive">False</property>
<signal name="activate" handler="search_entry" swapped="no"/>
<signal name="delete-text" handler="clear_results" swapped="no"/>
</object>
</child>
</object>
......
......@@ -44,7 +44,7 @@ class StreamWindow(Handy.ApplicationWindow):
menu_button = Gtk.Template.Child()
status_page = Gtk.Template.Child()
spinner = Gtk.Template.Child()
status_spinner = Gtk.Template.Child()
error_box = Gtk.Template.Child()
error_heading = Gtk.Template.Child()
error_text = Gtk.Template.Child()
......@@ -79,14 +79,22 @@ 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_results(self):
self.video_results_meta = []
children = self.results_list.get_children()
for child in children:
child.destroy()
@Gtk.Template.Callback()
def clear_results(self, start_pos, end_pos, data):
# only clear results on cleared search bar (or called directly)
if end_pos == 0:
self.video_results_meta = []
children = self.results_list.get_children()
for child in children:
child.destroy()
self.hide_error_box()
self.scroller.set_visible(False)
self.status_page.set_visible(True)
@Gtk.Template.Callback()
def search_entry(self, search_box):
self.clear_results(0, 0, None)
self.status_page.set_visible(False)
self.hide_error_box()
......@@ -94,7 +102,6 @@ class StreamWindow(Handy.ApplicationWindow):
self.search_query = search_box.get_text()
self.clear_results()
self.page_results = 1
# determine app window size at time of search
......@@ -107,11 +114,15 @@ class StreamWindow(Handy.ApplicationWindow):
"No strong video server instances found yet. Try again shortly.")
else:
self.search = DefaultSearch(app_window = self,
spinner = self.spinner,
toggle_status_spinner = self.toggle_status_spinner,
scroller = self.scroller,
add_result_meta = self.add_result_meta)
self.search.do_search(query = self.search_query, page = self.page_results)
def toggle_status_spinner(self, toggle):
self.status_spinner.set_visible(toggle)
self.status_icon.set_visible(not toggle)
def add_result_meta(self, video_meta):
self.video_results_meta.append(video_meta)
index_meta = len(self.video_results_meta) - 1
......@@ -200,7 +211,7 @@ class StreamWindow(Handy.ApplicationWindow):
self.error_text.set_label("...")
def show_error_box(self, heading, text):
self.spinner.set_visible(False)
self.toggle_status_spinner(False)
self.error_box.set_visible(True)
self.error_heading.set_label(heading)
self.error_text.set_label(text)
......
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