From f7f230f40efdec3cf46e992c1e9155d84d1d9a62 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Sat, 10 Mar 2018 17:49:53 +0300 Subject: [PATCH] Separation of service creation and editing --- app/ui/main_app_window.py | 19 ++++++++++++++++--- app/ui/main_window.glade | 16 ++++++++++++++++ app/ui/service_details_dialog.glade | 3 +-- app/ui/service_details_dialog.py | 21 ++++++++++++++++++--- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index dd94a2d9..875b9ad2 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -21,7 +21,7 @@ from .main_helper import edit_marker, insert_marker, move_items, rename, ViewTar from .picons_dialog import PiconsDialog from .satellites_dialog import show_satellites_dialog from .settings_dialog import show_settings_dialog -from .service_details_dialog import ServiceDetailsDialog +from .service_details_dialog import ServiceDetailsDialog, Action class MainAppWindow: @@ -63,7 +63,8 @@ class MainAppWindow: "bouquets_remove_popup_item", "fav_remove_popup_item", "hide_tool_button", "import_m3u_tool_button", "fav_import_m3u_popup_item", "fav_insert_marker_popup_item", "fav_edit_marker_popup_item", "fav_edit_popup_item", "fav_locate_popup_item", - "services_copy_popup_item", "services_picon_popup_item", "fav_picon_popup_item") + "services_copy_popup_item", "services_picon_popup_item", "fav_picon_popup_item", + "services_add_new_popup_item") def __init__(self): handlers = {"on_close_main_window": self.on_quit, @@ -112,7 +113,8 @@ class MainAppWindow: "on_search_down": self.on_search_down, "on_search_up": self.on_search_up, "on_search": self.on_search, - "on_service_edit": self.on_service_edit} + "on_service_edit": self.on_service_edit, + "on_services_add_new": self.on_services_add_new} self.__options = get_config() self.__profile = self.__options.get("profile") @@ -785,6 +787,8 @@ class MainAppWindow: for elem in self._COMMONS_ELEMENTS: self.__tool_elements[elem].set_sensitive(not_empty) + self.__tool_elements["services_add_new_popup_item"].set_sensitive(len(self.__bouquets_model)) + def on_hide(self, item): self.set_service_flags(Flag.HIDE) @@ -932,6 +936,15 @@ class MainAppWindow: self.__bouquets) dialog.show() + def on_services_add_new(self, item): + dialog = ServiceDetailsDialog(self.__main_window, + self.__options, + self.__services_view, + self.__services, + self.__bouquets, + action=Action.ADD) + dialog.show() + @run_idle def update_picons(self): update_picons(self.__options.get(self.__profile).get("picons_dir_path"), self.__picons, self.__services_model) diff --git a/app/ui/main_window.glade b/app/ui/main_window.glade index a9f6e865..fb43dba6 100644 --- a/app/ui/main_window.glade +++ b/app/ui/main_window.glade @@ -355,6 +355,12 @@ + + + True + False + + gtk-edit @@ -367,6 +373,16 @@ + + + gtk-new + True + False + True + True + + + True diff --git a/app/ui/service_details_dialog.glade b/app/ui/service_details_dialog.glade index b87b1c3f..63e9ec36 100644 --- a/app/ui/service_details_dialog.glade +++ b/app/ui/service_details_dialog.glade @@ -261,9 +261,8 @@ - + gtk-new - True True True Create and save as new service diff --git a/app/ui/service_details_dialog.py b/app/ui/service_details_dialog.py index 9d660599..387c5649 100644 --- a/app/ui/service_details_dialog.py +++ b/app/ui/service_details_dialog.py @@ -1,4 +1,5 @@ import re +from enum import Enum from functools import lru_cache from app.commons import run_idle @@ -11,6 +12,11 @@ from app.ui.main_helper import get_base_model from . import Gtk, Gdk, UI_RESOURCES_PATH, HIDE_ICON, TEXT_DOMAIN +class Action(Enum): + EDIT = 0 + ADD = 1 + + class ServiceDetailsDialog: _DATA_ID = "{:04x}:{:08x}:{:04x}:{:04x}:{}:{}" @@ -24,7 +30,7 @@ class ServiceDetailsDialog: "rate_entry", "pls_code_entry", "stream_id_entry", "tr_flag_entry", "namespace_entry", "srv_type_entry") - def __init__(self, transient, options, view, services, bouquets): + def __init__(self, transient, options, view, services, bouquets, action=Action.EDIT): handlers = {"on_system_changed": self.on_system_changed, "on_save": self.on_save, "on_create_new": self.on_create_new, @@ -41,6 +47,7 @@ class ServiceDetailsDialog: self._profile = Profile(options["profile"]) self._satellites_xml_path = options.get(self._profile.value)["data_dir_path"] + "satellites.xml" self._services_view = view + self._action = action self._old_service = None self._services = services self._bouquets = bouquets @@ -48,6 +55,8 @@ class ServiceDetailsDialog: self._current_model = None self._current_itr = None self._pattern = re.compile("\D") + self._apply_button = builder.get_object("apply_button") + self._create_button = builder.get_object("create_button") # style self._style_provider = Gtk.CssProvider() self._style_provider.load_from_path(UI_RESOURCES_PATH + "style.css") @@ -106,7 +115,13 @@ class ServiceDetailsDialog: self._network_id_entry, self._namespace_entry, self._fec_combo_box, self._rate_entry) - self.update_data_elements() + if self._action is Action.EDIT: + self.update_data_elements() + elif self._action is Action.ADD: + self._apply_button.set_visible(False) + self._create_button.set_visible(True) + self._tr_edit_switch.set_sensitive(False) + self.on_tr_edit_toggled(self._tr_edit_switch.set_active(True), True) def show(self): response = self._dialog.run() @@ -453,7 +468,7 @@ class ServiceDetailsDialog: @run_idle def on_tr_edit_toggled(self, switch: Gtk.Switch, active): - if active: + if active and self._action is Action.EDIT: self._transponder_services_iters = [] response = TransponderServicesDialog(self._dialog, self._current_model,