From 2c80d13170b62bcd848a4414e22eda38075625d5 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Wed, 4 Apr 2018 16:52:58 +0300 Subject: [PATCH] basic implementation of bouquets generation --- app/eparser/ecommons.py | 12 ++++++-- app/eparser/enigma/bouquets.py | 5 ++-- app/eparser/neutrino/bouquets.py | 9 +----- app/ui/main_app_window.py | 12 ++++---- app/ui/main_helper.py | 51 ++++++++++++++++++-------------- app/ui/main_window.glade | 31 +++++++++++++++++++ 6 files changed, 78 insertions(+), 42 deletions(-) diff --git a/app/eparser/ecommons.py b/app/eparser/ecommons.py index 0d9d8f49..12ad2b8c 100644 --- a/app/eparser/ecommons.py +++ b/app/eparser/ecommons.py @@ -27,13 +27,21 @@ Transponder = namedtuple("Transponder", ["frequency", "symbol_rate", "polarizati "system", "modulation", "pls_mode", "pls_code", "is_id"]) -class Type(Enum): - """ Types of DVB transponders """ +class TrType(Enum): + """ Transponders type """ Satellite = "s" Terestrial = "t" Cable = "c" +class BqType(Enum): + """ Bouquet type""" + BOUQUET = "bouquet" + TV = "tv" + RADIO = "radio" + WEBTV = "webtv" + + class Flag(Enum): """ Service flags diff --git a/app/eparser/enigma/bouquets.py b/app/eparser/enigma/bouquets.py index 70d39769..531eabf1 100644 --- a/app/eparser/enigma/bouquets.py +++ b/app/eparser/enigma/bouquets.py @@ -1,12 +1,13 @@ """ Module for parsing bouquets """ -from app.eparser.ecommons import BqServiceType, BouquetService, Bouquets, Bouquet +from app.eparser.ecommons import BqServiceType, BouquetService, Bouquets, Bouquet, BqType _TV_ROOT_FILE_NAME = "bouquets.tv" _RADIO_ROOT_FILE_NAME = "bouquets.radio" def get_bouquets(path): - return parse_bouquets(path, "bouquets.tv", "tv"), parse_bouquets(path, "bouquets.radio", "radio") + return parse_bouquets(path, "bouquets.tv", BqType.TV.value), parse_bouquets(path, "bouquets.radio", + BqType.RADIO.value) def write_bouquets(path, bouquets): diff --git a/app/eparser/neutrino/bouquets.py b/app/eparser/neutrino/bouquets.py index 2af40aab..020ced51 100644 --- a/app/eparser/neutrino/bouquets.py +++ b/app/eparser/neutrino/bouquets.py @@ -1,10 +1,9 @@ import os -from enum import Enum from xml.dom.minidom import parse, Document from app.eparser.iptv import NEUTRINO_FAV_ID_FORMAT from app.ui import LOCKED_ICON, HIDE_ICON -from ..ecommons import Bouquets, Bouquet, BouquetService, BqServiceType, PROVIDER +from ..ecommons import Bouquets, Bouquet, BouquetService, BqServiceType, PROVIDER, BqType _FILE = "bouquets.xml" _U_FILE = "ubouquets.xml" @@ -13,12 +12,6 @@ _W_FILE = "webtv.xml" _COMMENT = " File was created in DemonEditor. Enjoy watching! " -class BqType(Enum): - BOUQUET = "bouquet" - TV = "tv" - WEBTV = "webtv" - - def get_bouquets(path): return (parse_bouquets(path + _FILE, "Providers", BqType.BOUQUET.value), parse_bouquets(path + _U_FILE, "FAV", BqType.TV.value), diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 584ef01d..e435921f 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -4,7 +4,7 @@ from functools import lru_cache import shutil -from app.commons import run_idle, log +from app.commons import run_idle, log, run_task from app.eparser import get_blacklist, write_blacklist, parse_m3u from app.eparser import get_services, get_bouquets, write_bouquets, write_services, Bouquets, Bouquet, Service from app.eparser.ecommons import CAS, Flag @@ -18,7 +18,7 @@ from .dialogs import show_dialog, DialogType, get_chooser_dialog, WaitDialog, ge from .download_dialog import show_download_dialog from .main_helper import edit_marker, insert_marker, move_items, rename, ViewTarget, set_flags, locate_in_services, \ scroll_to, get_base_model, update_picons, copy_picon_reference, assign_picon, remove_picon, \ - is_only_one_item_selected, get_gen_bouquets, BqGenType + is_only_one_item_selected, gen_bouquets, BqGenType from .picons_dialog import PiconsDialog from .satellites_dialog import show_satellites_dialog from .settings_dialog import show_settings_dialog @@ -1011,12 +1011,10 @@ class MainAppWindow: def on_create_bouquet_for_each_package(self, item): self.create_bouquets(BqGenType.EACH_PACKAGE) + @run_task def create_bouquets(self, g_type): - bqs = get_gen_bouquets(self.__services_view, self.__bouquets_model, self.__main_window, g_type, self._TV_TYPES) - for bq in bqs: - self.append_bouquet(bq, self.__bouquets_model.get_iter(0)) - if bqs: - self.__bouquets_view.expand_row(Gtk.TreePath(0), 0) + gen_bouquets(self.__services_view, self.__bouquets_view, self.__main_window, g_type, self._TV_TYPES, + Profile(self.__profile), self.append_bouquet) def start_app(): diff --git a/app/ui/main_helper.py b/app/ui/main_helper.py index fcc9f83f..57b3b613 100644 --- a/app/ui/main_helper.py +++ b/app/ui/main_helper.py @@ -1,14 +1,13 @@ """ This is helper module for ui """ -from enum import Enum - import os - import shutil +from enum import Enum from gi.repository import GdkPixbuf from app.eparser import Service -from app.eparser.ecommons import Flag, BouquetService, Bouquet +from app.eparser.ecommons import Flag, BouquetService, Bouquet, BqType from app.eparser.enigma.bouquets import BqServiceType, to_bouquet_id +from app.properties import Profile from . import Gtk, Gdk, HIDE_ICON, LOCKED_ICON from .dialogs import show_dialog, DialogType, get_chooser_dialog @@ -421,31 +420,37 @@ def get_picon_pixbuf(path): # ***************** Bouquets *********************# -def get_gen_bouquets(view, bqs_model, transient, gen_type, tv_types): - """ Auto-generates and returns list of bouquets """ - bqs = [] +def gen_bouquets(view, bq_view, transient, gen_type, tv_types, profile, callback): + """ Auto-generate and append list of bouquets """ + fav_id_index = 18 + index = 6 if gen_type in (BqGenType.PACKAGE, BqGenType.EACH_PACKAGE) else 16 model, paths = view.get_selection().get_selected_rows() - if is_only_one_item_selected(paths, transient): - model = get_base_model(model) + model = get_base_model(model) + bq_type = BqType.BOUQUET.value if profile is Profile.NEUTRINO_MP else BqType.TV.value + if gen_type is BqGenType.SAT or gen_type is BqGenType.PACKAGE: + if not is_only_one_item_selected(paths, transient): + return service = Service(*model[paths][:]) - fav_id_index = service.index(service.fav_id) - name = service.package - index = service.index(service.package) - if gen_type is BqGenType.EACH_PACKAGE: - pass - elif gen_type is BqGenType.SAT: - name = service.pos - index = service.index(service.pos) - elif gen_type is BqGenType.EACH_SAT: - pass - bouquets_names = get_bouquets_names(bqs_model) + if service.service_type not in tv_types: + bq_type = BqType.RADIO.value + append_bouquets(bq_type, bq_view, callback, fav_id_index, index, model, + [service.package if gen_type is BqGenType.PACKAGE else service.pos]) + if gen_type is BqGenType.EACH_PACKAGE: + append_bouquets(bq_type, bq_view, callback, fav_id_index, index, model, {row[index] for row in model}) + elif gen_type is BqGenType.EACH_SAT: + append_bouquets(bq_type, bq_view, callback, fav_id_index, index, model, {row[index] for row in model}) + +def append_bouquets(bq_type, bq_view, callback, fav_id_index, index, model, names): + bq_view.expand_row(Gtk.TreePath(0), 0) + bqs_model = bq_view.get_model() + bouquets_names = get_bouquets_names(bqs_model) + for pos, name in enumerate(sorted(names)): if name not in bouquets_names: services = [BouquetService(None, BqServiceType.DEFAULT, row[fav_id_index], 0) for row in model if row[index] == name] - bqs.append(Bouquet(name=name, type="tv", services=services, locked=None, hidden=None)) - - return bqs + callback(Bouquet(name=name, type=bq_type, services=services, locked=None, hidden=None), + bqs_model.get_iter(0)) def get_bouquets_names(model): diff --git a/app/ui/main_window.glade b/app/ui/main_window.glade index 59f45362..1af8d47f 100644 --- a/app/ui/main_window.glade +++ b/app/ui/main_window.glade @@ -142,6 +142,16 @@ False gtk-select-all + + True + False + gtk-save + + + True + False + gtk-select-all + True False @@ -240,6 +250,27 @@ + + + False + + + + + For current type + False + image8 + False + + + + + For each type + False + image9 + False + +