From a49d6490c5ec041224a0853d02937fee90a4dac8 Mon Sep 17 00:00:00 2001 From: Dmitriy Yefremov Date: Tue, 3 Apr 2018 22:47:29 +0300 Subject: [PATCH] bouquets gen skeleton --- app/ui/main_app_window.py | 29 ++++++++--------- app/ui/main_helper.py | 65 ++++++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 30 deletions(-) diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index f5e7ccd7..584ef01d 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -7,7 +7,7 @@ import shutil from app.commons import run_idle, log 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, BouquetService +from app.eparser.ecommons import CAS, Flag from app.eparser.enigma.bouquets import BqServiceType from app.eparser.neutrino.bouquets import BqType from app.properties import get_config, write_config, Profile @@ -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_bouquets_names + is_only_one_item_selected, get_gen_bouquets, BqGenType from .picons_dialog import PiconsDialog from .satellites_dialog import show_satellites_dialog from .settings_dialog import show_settings_dialog @@ -1000,26 +1000,23 @@ class MainAppWindow: return ViewTarget.SERVICES if Gtk.Buildable.get_name(view) == "services_tree_view" else ViewTarget.FAV def on_create_bouquet_for_current_satellite(self, item): - model, paths = self.__services_view.get_selection().get_selected_rows() - if is_only_one_item_selected(paths, self.__main_window): - name = model[paths][16] - bouquets_names = get_bouquets_names(self.__bouquets_model) - - if name not in bouquets_names: - services = [BouquetService(None, BqServiceType.DEFAULT, row[18], 0) - for row in self.__services_model if row[16] == name] - bq = Bouquet(name=name, type="tv", services=services, locked=None, hidden=None) - self.append_bouquet(bq, self.__bouquets_model.get_iter(0)) - self.__bouquets_view.expand_row(Gtk.TreePath(0), 0) + self.create_bouquets(BqGenType.SAT) def on_create_bouquet_for_each_satellite(self, item): - pass + self.create_bouquets(BqGenType.EACH_SAT) def on_create_bouquet_for_current_package(self, item): - pass + self.create_bouquets(BqGenType.PACKAGE) def on_create_bouquet_for_each_package(self, item): - pass + self.create_bouquets(BqGenType.EACH_PACKAGE) + + 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) def start_app(): diff --git a/app/ui/main_helper.py b/app/ui/main_helper.py index b94e6eb7..fcc9f83f 100644 --- a/app/ui/main_helper.py +++ b/app/ui/main_helper.py @@ -7,7 +7,7 @@ import shutil from gi.repository import GdkPixbuf from app.eparser import Service -from app.eparser.ecommons import Flag +from app.eparser.ecommons import Flag, BouquetService, Bouquet from app.eparser.enigma.bouquets import BqServiceType, to_bouquet_id from . import Gtk, Gdk, HIDE_ICON, LOCKED_ICON from .dialogs import show_dialog, DialogType, get_chooser_dialog @@ -20,6 +20,14 @@ class ViewTarget(Enum): SERVICES = 2 +class BqGenType(Enum): + """ Bouquet generation type """ + SAT = 0 + EACH_SAT = 1 + PACKAGE = 2 + EACH_PACKAGE = 3 + + # ***************** Markers *******************# def insert_marker(view, bouquets, selected_bouquet, channels, parent_window): @@ -411,6 +419,48 @@ def get_picon_pixbuf(path): return GdkPixbuf.Pixbuf.new_from_file_at_scale(filename=path, width=32, height=32, preserve_aspect_ratio=True) +# ***************** Bouquets *********************# + +def get_gen_bouquets(view, bqs_model, transient, gen_type, tv_types): + """ Auto-generates and returns list of bouquets """ + bqs = [] + model, paths = view.get_selection().get_selected_rows() + if is_only_one_item_selected(paths, transient): + model = get_base_model(model) + 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 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 + + +def get_bouquets_names(model): + """ Returns all current bouquets names """ + bouquets_names = [] + for row in model: + itr = row.iter + if model.iter_has_child(itr): + num_of_children = model.iter_n_children(itr) + for num in range(num_of_children): + child_itr = model.iter_nth_child(itr, num) + bouquets_names.append(model[child_itr][0]) + return bouquets_names + + # ***************** Others *********************# def update_entry_data(entry, dialog, options): @@ -429,18 +479,5 @@ def get_base_model(model): return model -def get_bouquets_names(model): - """ Returns all current bouquets names """ - bouquets_names = [] - for row in model: - itr = row.iter - if model.iter_has_child(itr): - num_of_children = model.iter_n_children(itr) - for num in range(num_of_children): - child_itr = model.iter_nth_child(itr, num) - bouquets_names.append(model[child_itr][0]) - return bouquets_names - - if __name__ == "__main__": pass