better displaying of results
This commit is contained in:
parent
505b2c67a9
commit
5651c51bde
@ -1,6 +1,8 @@
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import datetime as dt
|
||||||
|
|
||||||
|
|
||||||
class MediathekViewWebAnswer(object):
|
class MediathekViewWebAnswer(object):
|
||||||
def __init__(self, answer_json: str):
|
def __init__(self, answer_json: str):
|
||||||
@ -69,6 +71,11 @@ class MediathekViewWebAnswer(object):
|
|||||||
def get_description(self):
|
def get_description(self):
|
||||||
return self._description
|
return self._description
|
||||||
|
|
||||||
|
def get_timestamp(self) -> dt.datetime:
|
||||||
|
if self._timestamp is None:
|
||||||
|
return None
|
||||||
|
return dt.datetime.utcfromtimestamp(int(self._timestamp))
|
||||||
|
|
||||||
|
|
||||||
class MediathekViewWebRequest(object):
|
class MediathekViewWebRequest(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
from gi.repository import Gtk, GLib
|
from . import mediathek_request as mr
|
||||||
|
from . import tools
|
||||||
|
from gi.repository import Gtk, GLib, Gdk
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
|
|
||||||
from . import tools
|
|
||||||
from . import mediathek_request as mr
|
|
||||||
|
|
||||||
class SearchWidget(Gtk.Box):
|
class SearchWidget(Gtk.Box):
|
||||||
def __init__(self, parent: 'main_window.MainApp') -> None:
|
def __init__(self, parent: 'main_window.MainApp') -> None:
|
||||||
Gtk.Box.__init__(self, orientation = Gtk.Orientation.VERTICAL)
|
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
|
||||||
|
|
||||||
self._search_bar = Gtk.SearchBar()
|
self._search_bar = Gtk.SearchBar()
|
||||||
self._search_entry = Gtk.SearchEntry()
|
self._search_entry = Gtk.SearchEntry()
|
||||||
@ -23,9 +23,30 @@ class SearchWidget(Gtk.Box):
|
|||||||
|
|
||||||
self._main_window = parent
|
self._main_window = parent
|
||||||
self._current_search_cards = []
|
self._current_search_cards = []
|
||||||
self._search_card_container = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
|
self._search_card_container = Gtk.FlowBox()
|
||||||
|
self._search_card_container.set_homogeneous(True)
|
||||||
|
self._search_card_container.set_vexpand(False)
|
||||||
|
self._search_card_container.set_valign(Gtk.Align.START)
|
||||||
|
|
||||||
self.pack_end(self._search_card_container, False, True, 10)
|
self._scrolled_window = Gtk.ScrolledWindow()
|
||||||
|
self._scrolled_window.add(self._search_card_container)
|
||||||
|
self._scrolled_window.set_vexpand(False)
|
||||||
|
|
||||||
|
self._card_bg_color = None
|
||||||
|
|
||||||
|
|
||||||
|
self.pack_start(self._scrolled_window, True, True, 10)
|
||||||
|
|
||||||
|
def get_card_bg_color(self):
|
||||||
|
if self._card_bg_color is None:
|
||||||
|
color = self._main_window.get_style_context().get_background_color(Gtk.StateType.NORMAL)
|
||||||
|
new_red = int(color.red * 0.95 * 2**16)
|
||||||
|
new_green = int(color.red * 0.95 * 2**16)
|
||||||
|
new_blue = int(color.red * 0.95 * 2**16)
|
||||||
|
|
||||||
|
self._card_bg_color = Gdk.Color(new_red, new_green, new_blue)
|
||||||
|
|
||||||
|
return self._card_bg_color
|
||||||
|
|
||||||
def dialog_response(self, widget, response_id):
|
def dialog_response(self, widget, response_id):
|
||||||
# if the button clicked gives response OK (-5)
|
# if the button clicked gives response OK (-5)
|
||||||
@ -48,18 +69,20 @@ class SearchWidget(Gtk.Box):
|
|||||||
# show the messagedialog
|
# show the messagedialog
|
||||||
messagedialog.show()
|
messagedialog.show()
|
||||||
|
|
||||||
def create_result_card(self, answer:mr.MediathekViewWebAnswer) -> Gtk.Box:
|
def create_result_card(self, answer: mr.MediathekViewWebAnswer) -> Gtk.Box:
|
||||||
|
|
||||||
url = answer.get_best_vid_url()
|
url = answer.get_best_vid_url()
|
||||||
title = answer.get_title()
|
title = answer.get_title()
|
||||||
description = answer.get_description()
|
description = answer.get_description()
|
||||||
|
time = answer.get_timestamp()
|
||||||
|
time_str = "" if time is None else time.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
if len(description) > 50:
|
if len(description) > 50:
|
||||||
description = description[:50] + "..."
|
description = description[:50] + "..."
|
||||||
|
|
||||||
play_button = tools.new_button_with_icon("media-playback-start")
|
play_button = tools.new_button_with_icon("media-playback-start")
|
||||||
|
|
||||||
def on_click(_ = None):
|
def on_click(_=None):
|
||||||
if url is not None:
|
if url is not None:
|
||||||
self._main_window.start_player(url)
|
self._main_window.start_player(url)
|
||||||
|
|
||||||
@ -73,33 +96,42 @@ class SearchWidget(Gtk.Box):
|
|||||||
description_label.set_markup(description)
|
description_label.set_markup(description)
|
||||||
description_label.set_justify(Gtk.Justification.LEFT)
|
description_label.set_justify(Gtk.Justification.LEFT)
|
||||||
description_label.set_xalign(0)
|
description_label.set_xalign(0)
|
||||||
|
time_label = Gtk.Label()
|
||||||
|
time_label.set_markup(time_str)
|
||||||
|
time_label.set_justify(Gtk.Justification.LEFT)
|
||||||
|
time_label.set_xalign(0)
|
||||||
|
|
||||||
text_box = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
|
text_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||||
|
|
||||||
text_box.pack_start(title_label, True, False, 0)
|
text_box.pack_start(title_label, False, False, 0)
|
||||||
text_box.pack_start(description_label, True, False, 0)
|
text_box.pack_start(description_label, False, False, 0)
|
||||||
|
text_box.pack_start(time_label, False, False, 0)
|
||||||
|
|
||||||
|
card_content = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||||
|
card_content.pack_start(play_button, False, False, 10)
|
||||||
card_content = Gtk.Box(orientation = Gtk.Orientation.HORIZONTAL)
|
|
||||||
card_content.pack_start(text_box, True, True, 0)
|
card_content.pack_start(text_box, True, True, 0)
|
||||||
card_content.pack_start(play_button, False, False, 0)
|
|
||||||
|
|
||||||
card = Gtk.Box(orientation = Gtk.Orientation.VERTICAL)
|
#card.pack_end(Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL), False, False, 10)
|
||||||
card.pack_start(card_content, True, True, 0)
|
|
||||||
card.pack_end(Gtk.Separator(orientation = Gtk.Orientation.HORIZONTAL), False, False, 10)
|
|
||||||
|
|
||||||
|
#card_event_box = Gtk.EventBox()
|
||||||
|
#card_event_box.add(card_content)
|
||||||
|
|
||||||
|
#card_event_box.modify_bg(Gtk.StateType.NORMAL, self.get_card_bg_color())
|
||||||
|
|
||||||
return card
|
card_content.set_vexpand(False)
|
||||||
|
|
||||||
|
return card_content
|
||||||
|
|
||||||
def clean_results(self):
|
def clean_results(self):
|
||||||
for result in self._current_search_cards:
|
for result in self._current_search_cards:
|
||||||
self._search_card_container.remove(result)
|
# result.destroy()
|
||||||
|
self._search_card_container.remove(result.get_parent())
|
||||||
|
|
||||||
self._current_search_cards = []
|
self._current_search_cards = []
|
||||||
|
|
||||||
def on_search(self, _) -> None:
|
def on_search(self, _) -> None:
|
||||||
|
self.clean_results()
|
||||||
|
|
||||||
search_text = self._search_entry.get_text()
|
search_text = self._search_entry.get_text()
|
||||||
|
|
||||||
req = mr.MediathekViewWebRequest(query=search_text)
|
req = mr.MediathekViewWebRequest(query=search_text)
|
||||||
@ -116,14 +148,10 @@ class SearchWidget(Gtk.Box):
|
|||||||
|
|
||||||
self.clean_results()
|
self.clean_results()
|
||||||
for answer in answers:
|
for answer in answers:
|
||||||
#print(answer)
|
# print(answer)
|
||||||
card = self.create_result_card(answer)
|
card = self.create_result_card(answer)
|
||||||
self._current_search_cards.append(card)
|
self._current_search_cards.append(card)
|
||||||
self._search_card_container.pack_start(card, False, False, 0)
|
self._search_card_container.insert(card, -1)
|
||||||
|
|
||||||
|
self._search_card_container.show_all()
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user