added basic hints support

This commit is contained in:
DYefremov
2020-04-06 16:50:11 +03:00
parent 9f7c713712
commit c8a9d3f4a0
3 changed files with 46 additions and 6 deletions

View File

@@ -28,7 +28,7 @@ from .iptv import IptvDialog, SearchUnavailableDialog, IptvListConfigurationDial
from .main_helper import (insert_marker, move_items, rename, ViewTarget, set_flags, locate_in_services,
scroll_to, get_base_model, update_picons_data, copy_picon_reference, assign_picon,
remove_picon, is_only_one_item_selected, gen_bouquets, BqGenType, get_iptv_url, append_picons,
get_selection, get_model_data, remove_all_unused_picons)
get_selection, get_model_data, remove_all_unused_picons, get_picon_pixbuf)
from .picons_downloader import PiconsDialog
from .satellites_dialog import show_satellites_dialog
from .search import SearchProvider
@@ -98,6 +98,7 @@ class Application(Gtk.Application):
"on_edit": self.on_edit,
"on_to_fav_copy": self.on_to_fav_copy,
"on_to_fav_end_copy": self.on_to_fav_end_copy,
"on_fav_view_query_tooltip": self.on_fav_view_query_tooltip,
"on_view_drag_begin": self.on_view_drag_begin,
"on_view_drag_data_get": self.on_view_drag_data_get,
"on_services_view_drag_drop": self.on_services_view_drag_drop,
@@ -764,6 +765,43 @@ class Application(Gtk.Application):
for row in self._fav_model:
fav_bouquet.append(row[Column.FAV_ID])
# ********************* Hints *************************#
def on_fav_view_query_tooltip(self, view, x, y, keyboard_mode, tooltip: Gtk.Tooltip):
""" Sets detailed info about service in the tooltip. """
result = view.get_dest_row_at_pos(x, y)
if not result or not self._settings.show_bq_hints:
return False
path, pos = result
model = view.get_model()
srv = self._services.get(model[path][Column.FAV_ID], None)
if srv and srv.picon_id:
tooltip.set_icon(get_picon_pixbuf(self._settings.picons_local_path + srv.picon_id, size=96))
tooltip.set_text(self.get_hint_for_bq_list(srv))
view.set_tooltip_row(tooltip, path)
return True
return False
def get_hint_for_bq_list(self, srv: Service):
""" Returns detailed info about service as formatted string for using as hint. """
header = "{}: {}\n{}: {}\n".format(get_message("Name"), srv.service, get_message("Type"), srv.service_type)
ref = "{}: {}".format(get_message("Service reference"), srv.picon_id.rstrip(".png"))
if srv.service_type == "IPTV":
return "{}{}".format(header, ref)
pol = ", {}: {},".format(get_message("Pol"), srv.pol) if srv.pol else ","
fec = "{}: {}".format("FEC", srv.fec) if srv.fec else ","
ht = "{}{}: {}\n{}: {}\n{}: {}\n{}: {}{} {}, {}: {}\n{}"
return ht.format(header,
get_message("Package"), srv.package,
get_message("System"), srv.system,
get_message("Freq"), srv.freq,
get_message("Rate"), srv.rate, pol, fec, "SID", srv.ssid,
ref)
# ***************** Drag-and-drop *********************#
def on_view_drag_begin(self, view, context):
@@ -1274,14 +1312,14 @@ class Application(Gtk.Application):
if ex_services:
ex_srv_name = ex_services.get(srv_id)
if srv:
tooltip, background = None, self._EXTRA_COLOR if self._use_colors and ex_srv_name else None
background = self._EXTRA_COLOR if self._use_colors and ex_srv_name else None
self._fav_model.append((num + 1, srv.coded, ex_srv_name if ex_srv_name else srv.service, srv.locked,
srv.hide, srv.service_type, srv.pos, srv.fav_id,
self._picons.get(srv.picon_id, None), tooltip, background))
self._picons.get(srv.picon_id, None), None, background))
yield True
def check_bouquet_selection(self):
""" checks and returns bouquet if selected """
""" Checks and returns bouquet if selected """
if not self._bq_selected:
self.show_error_dialog("Error. No bouquet is selected!")
return

View File

@@ -500,9 +500,9 @@ def is_only_one_item_selected(paths, transient):
return True
def get_picon_pixbuf(path):
def get_picon_pixbuf(path, size=32):
try:
return GdkPixbuf.Pixbuf.new_from_file_at_scale(filename=path, width=32, height=32, preserve_aspect_ratio=True)
return GdkPixbuf.Pixbuf.new_from_file_at_scale(path, width=size, height=size, preserve_aspect_ratio=True)
except GLib.GError as e:
pass

View File

@@ -2347,6 +2347,7 @@ Author: Dmitriy Yefremov
<property name="search_column">2</property>
<property name="rubber_banding">True</property>
<property name="enable_grid_lines">both</property>
<property name="tooltip_column">9</property>
<property name="activate_on_single_click">True</property>
<signal name="button-press-event" handler="on_fav_press" object="fav_popup_menu" swapped="no"/>
<signal name="button-press-event" handler="on_view_press" swapped="yes"/>
@@ -2356,6 +2357,7 @@ Author: Dmitriy Yefremov
<signal name="focus-in-event" handler="on_view_focus" swapped="no"/>
<signal name="key-press-event" handler="on_tree_view_key_press" swapped="no"/>
<signal name="key-release-event" handler="on_tree_view_key_release" swapped="no"/>
<signal name="query-tooltip" handler="on_fav_view_query_tooltip" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection" id="fav_selection">
<property name="mode">multiple</property>