From d16d0e62e2a26f71b51ccf5566d7bf14af5d2525 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Fri, 19 Jan 2024 17:24:12 +0300 Subject: [PATCH] small refactoring --- app/ui/dialogs.py | 19 +++++++++++++++++++ app/ui/xml/dialogs.py | 19 ++++--------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/ui/dialogs.py b/app/ui/dialogs.py index 38d02013..5b84fdbc 100644 --- a/app/ui/dialogs.py +++ b/app/ui/dialogs.py @@ -38,6 +38,25 @@ from app.settings import SEP, IS_WIN, USE_HEADER_BAR from .uicommons import Gtk, UI_RESOURCES_PATH, TEXT_DOMAIN +class BaseDialog(Gtk.Dialog): + """ Base dialog class for editing DVB (-> *.xml) data. """ + DEFAULT_BUTTONS = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK) + + def __init__(self, parent, title, buttons=None, *args, **kwargs): + super().__init__(transient_for=parent, + title=translate(title), + modal=True, + resizable=False, + default_width=240, + skip_taskbar_hint=True, + skip_pager_hint=True, + destroy_with_parent=True, + use_header_bar=USE_HEADER_BAR, + window_position=Gtk.WindowPosition.CENTER_ON_PARENT, + buttons=buttons or self.DEFAULT_BUTTONS, + *args, **kwargs) + + class Dialog(Enum): MESSAGE = """ diff --git a/app/ui/xml/dialogs.py b/app/ui/xml/dialogs.py index 6177a1fd..46e23fd5 100644 --- a/app/ui/xml/dialogs.py +++ b/app/ui/xml/dialogs.py @@ -43,9 +43,9 @@ from app.eparser.ecommons import (PLS_MODE, get_key_by_value, POLARIZATION, FEC, HIERARCHY, Inversion, C_MODULATION, FEC_DEFAULT, TerTransponder, CableTransponder, Bouquet, BouquetService, BqServiceType, Bouquets, BqType) from app.eparser.satxml import get_pos_str -from app.settings import USE_HEADER_BAR, Settings, CONFIG_PATH +from app.settings import Settings, CONFIG_PATH from app.tools.satellites import SatellitesParser, SatelliteSource, ServicesParser -from ..dialogs import show_dialog, DialogType, translate, get_builder +from ..dialogs import show_dialog, BaseDialog, DialogType, translate, get_builder from ..main_helper import append_text_to_tview, get_base_model, on_popup_menu, get_services_type_groups from ..search import SearchProvider from ..uicommons import Gtk, Gdk, UI_RESOURCES_PATH, HeaderBar @@ -53,22 +53,11 @@ from ..uicommons import Gtk, Gdk, UI_RESOURCES_PATH, HeaderBar _DIALOGS_UI_PATH = f"{UI_RESOURCES_PATH}xml{os.sep}dialogs.glade" -class DVBDialog(Gtk.Dialog): +class DVBDialog(BaseDialog): """ Base dialog class for editing DVB (-> *.xml) data. """ def __init__(self, parent, title, data=None, *args, **kwargs): - super().__init__(transient_for=parent, - title=translate(title), - modal=True, - resizable=False, - default_width=240, - skip_taskbar_hint=True, - skip_pager_hint=True, - destroy_with_parent=True, - use_header_bar=USE_HEADER_BAR, - window_position=Gtk.WindowPosition.CENTER_ON_PARENT, - buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK), - *args, **kwargs) + super().__init__(parent=parent, title=title, *args, **kwargs) self._viewport = Gtk.Viewport(margin_top=2) self._viewport.get_style_context().add_class("view")