From d7a214b4455e713de7046cf627e0bbc111c907e4 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Thu, 9 May 2019 14:48:29 +0300 Subject: [PATCH] iptv dialogs refactoring --- app/ui/dialogs.py | 16 ++++--- app/ui/iptv.glade | 110 +++++++++++++++++++++++++++----------------- app/ui/iptv.py | 15 +++--- app/ui/uicommons.py | 2 + 4 files changed, 87 insertions(+), 56 deletions(-) diff --git a/app/ui/dialogs.py b/app/ui/dialogs.py index a36b4a3b..c971ec77 100644 --- a/app/ui/dialogs.py +++ b/app/ui/dialogs.py @@ -1,12 +1,10 @@ """ Common module for showing dialogs """ import locale -import os from enum import Enum +from functools import lru_cache from app.commons import run_idle -from .uicommons import Gtk, UI_RESOURCES_PATH, TEXT_DOMAIN - -_IS_GNOME_SESSION = int(bool(os.environ.get("GNOME_DESKTOP_SESSION_ID"))) +from .uicommons import Gtk, UI_RESOURCES_PATH, TEXT_DOMAIN, IS_GNOME_SESSION class Button(Enum): @@ -187,7 +185,7 @@ def get_file_chooser_dialog(transient, text, options, action_type, file_filter): dialog = Gtk.FileChooserDialog(get_message(text) if text else "", transient, action_type if action_type is not None else Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK), - use_header_bar=_IS_GNOME_SESSION) + use_header_bar=IS_GNOME_SESSION) if file_filter is not None: dialog.add_filter(file_filter) @@ -207,7 +205,7 @@ def get_file_chooser_dialog(transient, text, options, action_type, file_filter): def get_input_dialog(transient, text): builder = Gtk.Builder() - builder.add_from_string(Dialog.INPUT.value.format(use_header=_IS_GNOME_SESSION, title="", + builder.add_from_string(Dialog.INPUT.value.format(use_header=IS_GNOME_SESSION, title="", ok_button=Button.OK, cancel_button=Button.CANCEL, cancel_action=ButtonAction.CANCEL, ok_action=ButtonAction.OK)) dialog = builder.get_object("input_dialog") @@ -261,5 +259,11 @@ def get_message(message): return locale.dgettext(TEXT_DOMAIN, message) +@lru_cache(maxsize=5) +def get_dialogs_string(path): + with open(path, "r") as f: + return "".join(f) + + if __name__ == "__main__": pass diff --git a/app/ui/iptv.glade b/app/ui/iptv.glade index f27c997f..ce75aa03 100644 --- a/app/ui/iptv.glade +++ b/app/ui/iptv.glade @@ -45,18 +45,9 @@ Author: Dmitriy Yefremov dialog True True + False center - - - gtk-cancel - True - True - True - True - True - - @@ -65,6 +56,16 @@ Author: Dmitriy Yefremov False vertical 1 + + + False + + + False + False + 0 + + True @@ -74,42 +75,17 @@ Author: Dmitriy Yefremov 5 5 0 + 1 in - + True False 5 5 5 5 - vertical - 2 - - - True - False - Please wait, streams testing in progress... - - - False - True - 0 - - - - - 10 - True - False - True - - - False - True - 1 - - + 10 True @@ -157,11 +133,59 @@ Author: Dmitriy Yefremov - False - True - 2 + 0 + 2 + + + 10 + True + False + center + True + + + 0 + 1 + + + + + True + True + True + Cancel + + + True + False + gtk-cancel + + + + + 1 + 1 + + + + + True + False + Please wait, streams testing in progress... + + + 0 + 0 + + + + + + + + @@ -201,7 +225,7 @@ Author: Dmitriy Yefremov - 1 + {use_header} 480 False Stream data @@ -612,7 +636,7 @@ Author: Dmitriy Yefremov - 1 + {use_header} 400 False IPTV streams list configuration diff --git a/app/ui/iptv.py b/app/ui/iptv.py index b981ebd5..4e0c36f1 100644 --- a/app/ui/iptv.py +++ b/app/ui/iptv.py @@ -1,7 +1,6 @@ import re import urllib from urllib.error import HTTPError - from urllib.parse import urlparse from urllib.request import Request, urlopen @@ -9,13 +8,14 @@ from app.commons import run_idle, run_task from app.eparser.ecommons import BqServiceType, Service from app.eparser.iptv import NEUTRINO_FAV_ID_FORMAT, StreamType, ENIGMA2_FAV_ID_FORMAT from app.properties import Profile -from .uicommons import Gtk, Gdk, TEXT_DOMAIN, UI_RESOURCES_PATH, IPTV_ICON, Column -from .dialogs import Action, show_dialog, DialogType +from .dialogs import Action, show_dialog, DialogType, get_dialogs_string from .main_helper import get_base_model, get_iptv_url +from .uicommons import Gtk, Gdk, TEXT_DOMAIN, UI_RESOURCES_PATH, IPTV_ICON, Column, IS_GNOME_SESSION _DIGIT_ENTRY_NAME = "digit-entry" _ENIGMA2_REFERENCE = "{}:0:{}:{:X}:{:X}:{:X}:{:X}:0:0:0" -_PATTERN = re.compile("(?:^[\s]*$|\D)") +_PATTERN = re.compile("(?:^[\\s]*$|\\D)") +_UI_PATH = UI_RESOURCES_PATH + "iptv.glade" def is_data_correct(elems): @@ -47,7 +47,8 @@ class IptvDialog: builder = Gtk.Builder() builder.set_translation_domain(TEXT_DOMAIN) - builder.add_objects_from_file(UI_RESOURCES_PATH + "iptv.glade", ("iptv_dialog", "stream_type_liststore")) + builder.add_objects_from_string(get_dialogs_string(_UI_PATH).format(use_header=IS_GNOME_SESSION), + ("iptv_dialog", "stream_type_liststore")) builder.connect_signals(handlers) self._dialog = builder.get_object("iptv_dialog") @@ -322,8 +323,8 @@ class IptvListConfigurationDialog: builder = Gtk.Builder() builder.set_translation_domain(TEXT_DOMAIN) - builder.add_objects_from_file(UI_RESOURCES_PATH + "iptv.glade", - ("iptv_list_configuration_dialog", "stream_type_liststore")) + builder.add_objects_from_string(get_dialogs_string(_UI_PATH).format(use_header=IS_GNOME_SESSION), + ("iptv_list_configuration_dialog", "stream_type_liststore")) builder.connect_signals(handlers) self._rows = iptv_rows diff --git a/app/ui/uicommons.py b/app/ui/uicommons.py index faac3f18..63c1f942 100644 --- a/app/ui/uicommons.py +++ b/app/ui/uicommons.py @@ -10,6 +10,8 @@ from gi.repository import Gtk, Gdk # path to *.glade files UI_RESOURCES_PATH = "app/ui/" if os.path.exists("app/ui/") else "/usr/share/demoneditor/app/ui/" +IS_GNOME_SESSION = int(bool(os.environ.get("GNOME_DESKTOP_SESSION_ID"))) + # translation TEXT_DOMAIN = "demon-editor" if UI_RESOURCES_PATH == "app/ui/":