From 2686e00a8d4c76e0ec6c5e251a74f5564647d47a Mon Sep 17 00:00:00 2001 From: Dmitriy Yefremov Date: Wed, 11 Oct 2017 23:22:30 +0300 Subject: [PATCH] adding favorites --- main/data/lamedb | 6 ++--- main/editor_ui.glade | 35 +++++++++++++------------ main/eparser/__init__.py | 2 +- main/eparser/bouquets.py | 10 ++++--- main/eparser/lamedb.py | 7 +++-- main/ui.py | 56 ++++++++++++++++++++++++++++++---------- 6 files changed, 75 insertions(+), 41 deletions(-) diff --git a/main/data/lamedb b/main/data/lamedb index b817548d..600168fd 100644 --- a/main/data/lamedb +++ b/main/data/lamedb @@ -1576,7 +1576,7 @@ Discovery Channel p:HTB+,C:0500 0523:01680000:000d:0070:22:0 НТВ -p:HTB+,C:0500 +p:HTB+,c:0000d7,c:01013b,c:020203,c:0300d7,c:050001,C:0500 0324:0168affb:0008:0070:22:0 НСТ p:HTB+,C:0500 @@ -1924,7 +1924,7 @@ p:HTB+,C:0500 p:HTB+,C:0500 007a:01680000:0001:0070:22:0 Hustler TV -p:HTB+,C:0500 +p:HTB+,c:0000de,c:010142,c:0300de,c:050001,C:0500 007b:01680000:0001:0070:22:0 ЖАРА p:HTB+,C:0500 @@ -2308,7 +2308,7 @@ Bollywood HD p:HTB+,C:0500 0899:01680000:0016:0070:25:0 HTB HD -p:HTB+,C:0500 +p:HTB+,c:0000c9,c:01012d,c:0300c9,c:050001,C:0500 089a:01680000:0016:0070:25:0 Animal Planet HD p:HTB+,C:0500 diff --git a/main/editor_ui.glade b/main/editor_ui.glade index ba1b0a69..44821f94 100644 --- a/main/editor_ui.glade +++ b/main/editor_ui.glade @@ -2,22 +2,22 @@ - + - + - + - + - + - + @@ -304,7 +304,7 @@ autosize Service - + @@ -364,8 +364,8 @@ False True True - - + + @@ -547,8 +547,8 @@ Open True gtk-open - - + + False @@ -802,9 +802,9 @@ True True - services_liststore + services_list_store both - + multiple @@ -984,9 +984,9 @@ True True - fav_liststore + fav_list_store both - + multiple @@ -1057,7 +1057,10 @@ True True - bouquets_treestore + bouquets_tree_store + False + True + diff --git a/main/eparser/__init__.py b/main/eparser/__init__.py index 5d9e60ab..63a8596e 100644 --- a/main/eparser/__init__.py +++ b/main/eparser/__init__.py @@ -1,5 +1,5 @@ from .lamedb import get_channels -from .bouquets import get_bouquets +from .bouquets import get_bouquets, get_bouquet from .satxml import get_transponders diff --git a/main/eparser/bouquets.py b/main/eparser/bouquets.py index 536a94d5..ea4500f0 100644 --- a/main/eparser/bouquets.py +++ b/main/eparser/bouquets.py @@ -14,8 +14,13 @@ def get_bouquets(path): def get_bouquet(path, name, type): - with open(path + "userbouquet.{}.{}".format(name, type)) as file: - print(file.read()) + with open(path + "userbouquet.{}.{}".format(name, str(type))) as file: + chs_list = file.read() + ids = [] + for ch in chs_list.split("#SERVICE")[1:]: + ch_data = ch.strip().split(":") + ids.append("{}:{}:{}:{}".format(ch_data[3], ch_data[4], ch_data[5], ch_data[6])) + return ids def parse_bouquets(path, name): @@ -33,5 +38,4 @@ def parse_bouquets(path, name): if __name__ == "__main__": - # print(get_bouquet(__BOUQUETS_PATH, "TV", "tv")) pass diff --git a/main/eparser/lamedb.py b/main/eparser/lamedb.py index 71df4595..87b749ae 100644 --- a/main/eparser/lamedb.py +++ b/main/eparser/lamedb.py @@ -46,7 +46,7 @@ def parse_channels(*args): for ch in srv: data = str(ch[0]).split(_SEP) sp = "0" - # For comparison in bouquets + # For comparison in bouquets. Needed in upper case!!! fav_id = "{}:{}:{}:{}".format(str(data[0]).lstrip(sp), str(data[2]).lstrip(sp), str(data[3]).lstrip(sp), str(data[1]).lstrip(sp)) pack = str(ch[2]) @@ -56,7 +56,7 @@ def parse_channels(*args): pack = pack[2:] if pack.find(",") < 0 else pack[2:pack.find(",")] channels.append(Channel(ch[1], pack, SERVICE_TYPE.get(int(data[4]), SERVICE_TYPE[-2]), data[0], tr[0], tr[1], Polarization(int(tr[2])).name, FEC[int(tr[3])], SYSTEM[int(tr[6])], - "{}{}.{}".format(*list(tr[4])), ch[0], fav_id)) + "{}{}.{}".format(*list(tr[4])), ch[0], fav_id.upper())) return channels @@ -73,5 +73,4 @@ def split(itr, size): if __name__ == "__main__": - for ch in get_channels(_FILE_PATH): - print(ch) + pass diff --git a/main/ui.py b/main/ui.py index 796485c5..df8f88bd 100644 --- a/main/ui.py +++ b/main/ui.py @@ -1,8 +1,11 @@ import gi import os from ftplib import FTP + +from threading import Thread +from main.eparser.__constants import SERVICE_TYPE from main.properties import get_config, write_config -from main.eparser import get_channels, get_transponders, get_bouquets +from main.eparser import get_channels, get_transponders, get_bouquets, get_bouquet gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk @@ -11,7 +14,9 @@ __status_bar = None __options = get_config() __services_model = None __bouquets_model = None +__fav_model = None __DATA_FILES_LIST = ("tv", "radio", "lamedb") +__channels = {} def on_about_app(item): @@ -30,28 +35,49 @@ def get_handlers(): "on_download": on_download, "on_upload": on_upload, "on_data_dir_field_icon_press": on_path_open, - "on_data_open_services": on_data_open_services, - "on_data_open_bouquets": on_data_open_bouquets, - "on_tree_view_key_release": on_tree_view_key_release + "on_data_open": on_data_open, + "on_tree_view_key_release": on_tree_view_key_release, + "on_bouquets_selection": on_bouquets_selection } -def on_data_open_services(items): +def data_open(model): try: + model.clear() + __fav_model.clear() + model_id = model.get_name() data_path = get_config()["data_dir_path"] - for ch in get_channels(data_path + "lamedb"): - items.append(ch) + if model_id == "services_list_store": + for ch in get_channels(data_path + "lamedb"): + # adding channels to dict with fav_id as keys + __channels[ch.fav_id] = ch + model.append(ch) + if model_id == "bouquets_tree_store": + data = get_bouquets(data_path) + for name, bouquets in data: + parent = model.append(None, [name]) + for bouquet in bouquets: + model.append(parent, [bouquet]) except Exception as e: __status_bar.push(1, getattr(e, "message", repr(e))) -def on_data_open_bouquets(item): - data_path = get_config()["data_dir_path"] - data = get_bouquets(data_path) - for name, bouquets in data: - parent = item.append(None, [name]) - for bouquet in bouquets: - item.append(parent, [bouquet]) +def on_data_open(model): + # Maybe is not necessary? Need testing. + task = Thread(target=data_open(model)) + task.start() + + +def on_bouquets_selection(model, path, column): + if len(path) > 1: + tree_iter = model.get_iter(path) + name = model.get_value(tree_iter, 0) + # 'tv' Temporary! It is necessary to implement a row type attribute. + bq = get_bouquet(__options["data_dir_path"], name, SERVICE_TYPE[1].lower()) + __fav_model.clear() + for num, ch_id in enumerate(bq): + channel = __channels.get(ch_id, None) + __fav_model.append((num + 1, channel[0], channel[2], channel[9])) def on_path_open(*args): @@ -171,6 +197,8 @@ def init_ui(): builder = Gtk.Builder() builder.add_from_file("editor_ui.glade") main_window = builder.get_object("main_window") + global __fav_model + __fav_model = builder.get_object("fav_list_store") global __status_bar __status_bar = builder.get_object("status_bar") builder.connect_signals(get_handlers())