From f6b7e0f9c5211b1ffe605659f67083cb9b49ce61 Mon Sep 17 00:00:00 2001 From: Dmitriy Yefremov Date: Sat, 14 Oct 2017 13:23:34 +0300 Subject: [PATCH] decoupling for settings --- main/__init__.py | 2 +- main/ui/__init__.py | 1 + main/ui/main.py | 53 +-- main/ui/{main.glade => main_window.glade} | 385 --------------------- main/ui/satellites_dialog.glade | 24 -- main/ui/satellites_dialog.py | 47 ++- main/ui/settings_dialog.glade | 388 ++++++++++++++++++++++ main/ui/settings_dialog.py | 57 ++++ 8 files changed, 476 insertions(+), 481 deletions(-) rename main/ui/{main.glade => main_window.glade} (74%) create mode 100644 main/ui/settings_dialog.glade create mode 100644 main/ui/settings_dialog.py diff --git a/main/__init__.py b/main/__init__.py index dcd028d5..bb62fe32 100644 --- a/main/__init__.py +++ b/main/__init__.py @@ -1,4 +1,4 @@ -from main.ui.main import start_app as start +from main.ui import start_app as start if __name__ == "__main__": start() diff --git a/main/ui/__init__.py b/main/ui/__init__.py index e69de29b..3bba5d47 100644 --- a/main/ui/__init__.py +++ b/main/ui/__init__.py @@ -0,0 +1 @@ +from main.ui.main import start_app diff --git a/main/ui/main.py b/main/ui/main.py index 91ea1be5..bb9e8ba3 100644 --- a/main/ui/main.py +++ b/main/ui/main.py @@ -4,7 +4,8 @@ from main.eparser import get_channels, get_bouquets, get_bouquet from main.eparser.__constants import SERVICE_TYPE from main.properties import get_config, write_config from main.ftp import download_data, upload_data -from .satellites_dialog import SatellitesDialog +from .satellites_dialog import show_satellites_dialog +from .settings_dialog import show_settings_dialog gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk @@ -23,7 +24,7 @@ __channels = {} def on_about_app(item): builder = Gtk.Builder() - builder.add_from_file("ui/main.glade") + builder.add_from_file("ui/main_window.glade") dialog = builder.get_object("about_dialog") dialog.run() dialog.destroy() @@ -36,7 +37,6 @@ def get_handlers(): "on_preferences": on_preferences, "on_download": on_download, "on_upload": on_upload, - "on_data_dir_field_icon_press": on_path_open, "on_data_open": on_data_open, "on_tree_view_key_release": on_tree_view_key_release, "on_bouquets_selection": on_bouquets_selection, @@ -86,7 +86,7 @@ def on_delete(item): def on_satellite_editor_show(model): """ Shows satellites editor dialog """ - SatellitesDialog(__main_window, __options["data_dir_path"]).show() + show_satellites_dialog(__main_window, __options["data_dir_path"]) def data_open(model): @@ -143,49 +143,8 @@ def delete_selection(view, *args): v.get_selection().unselect_all() -def on_path_open(*args): - builder = Gtk.Builder() - builder.add_from_file("ui/main.glade") - dialog = builder.get_object("path_chooser_dialog") - response = dialog.run() - if response == -12: # for fix assertion 'gtk_widget_get_can_default (widget)' failed - args[0].set_text(dialog.get_filename()) - dialog.destroy() - - def on_preferences(item): - builder = Gtk.Builder() - builder.add_from_file("main.glade") - builder.connect_signals(get_handlers()) - dialog = builder.get_object("settings_dialog") - host_field = builder.get_object("host_field") - host_field.set_text(__options["host"]) - port_field = builder.get_object("port_field") - port_field.set_text(__options["port"]) - login_field = builder.get_object("login_field") - login_field.set_text(__options["user"]) - password_field = builder.get_object("password_field") - password_field.set_text(__options["password"]) - services_field = builder.get_object("services_field") - services_field.set_text(__options["services_path"]) - user_bouquet_field = builder.get_object("user_bouquet_field") - user_bouquet_field.set_text(__options["user_bouquet_path"]) - satellites_xml_field = builder.get_object("satellites_xml_field") - satellites_xml_field.set_text(__options["satellites_xml_path"]) - data_dir_field = builder.get_object("data_dir_field") - data_dir_field.set_text(__options["data_dir_path"]) - - if dialog.run() == Gtk.ResponseType.OK: - __options["host"] = host_field.get_text() - __options["port"] = port_field.get_text() - __options["user"] = login_field.get_text() - __options["password"] = password_field.get_text() - __options["services_path"] = services_field.get_text() - __options["user_bouquet_path"] = user_bouquet_field.get_text() - __options["satellites_xml_path"] = satellites_xml_field.get_text() - __options["data_dir_path"] = data_dir_field.get_text() - write_config(__options) - dialog.destroy() + show_settings_dialog(__main_window, __options) def on_tree_view_key_release(widget, event): @@ -224,7 +183,7 @@ def connect(properties, download=True): def init_ui(): builder = Gtk.Builder() - builder.add_from_file("ui/main.glade") + builder.add_from_file("ui/main_window.glade") global __main_window __main_window = builder.get_object("main_window") global __services_view diff --git a/main/ui/main.glade b/main/ui/main_window.glade similarity index 74% rename from main/ui/main.glade rename to main/ui/main_window.glade index 134413a3..58f6718b 100644 --- a/main/ui/main.glade +++ b/main/ui/main_window.glade @@ -967,389 +967,4 @@ - - False - - dialog - main_window - save - - - False - vertical - 2 - - - False - end - - - gtk-undo - True - True - True - True - - - True - True - 0 - - - - - gtk-ok - True - True - True - True - 0.55000001192092896 - - - True - True - 1 - - - - - False - False - 0 - - - - - - - - - button2 - button1 - - - - False - Options - False - True - preferences-desktop - dialog - main_window - - - False - 5 - 5 - 5 - vertical - 2 - - - False - end - end - - - gtk-undo - True - True - True - True - - - True - True - 2 - - - - - gtk-ok - True - True - True - True - - - True - True - 3 - - - - - False - False - 0 - - - - - True - False - True - - - True - False - Host: - - - 0 - 0 - - - - - True - True - 127.0.0.1 - - - 0 - 1 - - - - - True - False - Login: - - - 0 - 2 - - - - - True - False - Password: - - - 1 - 2 - - - - - True - True - 21 - - - 1 - 1 - - - - - True - False - Port: - - - 1 - 0 - - - - - True - True - root - emblem-personal - False - - - 0 - 3 - - - - - True - True - False - - root - emblem-nowrite - False - password - - - 1 - 3 - - - - - False - True - 0 - - - - - True - False - 2 - 2 - - - False - True - 1 - - - - - True - False - True - - - True - False - Services and Bouquets files: - - - 0 - 0 - - - - - True - True - /etc/enigma2/ - - - 0 - 1 - - - - - True - False - User bouquet files: - - - 0 - 2 - - - - - True - True - /etc/enigma2/ - - - 0 - 3 - - - - - True - False - Satellites.xml file: - - - 0 - 4 - - - - - True - True - /etc/tuxbox/ - - - 0 - 5 - - - - - False - True - 2 - - - - - True - False - 2 - - - False - True - 3 - - - - - True - False - True - - - True - False - Data directory: - 0 - - - 0 - 0 - - - - - True - True - /data - gtk-open - False - Select - - - - 0 - 1 - - - - - False - True - 5 - - - - - True - False - - - False - True - 2 - 6 - - - - - - cancel_button - ok_button - - diff --git a/main/ui/satellites_dialog.glade b/main/ui/satellites_dialog.glade index 62817e06..45001f8e 100644 --- a/main/ui/satellites_dialog.glade +++ b/main/ui/satellites_dialog.glade @@ -439,28 +439,4 @@ sat_ed_cancel_button - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/main/ui/satellites_dialog.py b/main/ui/satellites_dialog.py index b35ee916..5bb54da9 100644 --- a/main/ui/satellites_dialog.py +++ b/main/ui/satellites_dialog.py @@ -3,34 +3,33 @@ import gi from main.eparser import get_satellites gi.require_version('Gtk', '3.0') -from gi.repository import Gtk, Gdk +from gi.repository import Gtk + +__data_path = None -class SatellitesDialog: - def __init__(self, transient, data_path): - handlers = { - "on_satellites_list_load": self.on_satellites_list_load - } - builder = Gtk.Builder() - builder.add_from_file("./ui/satellites_dialog.glade") - builder.connect_signals(handlers) - self._dialog = builder.get_object("satellites_editor_dialog") - self._data_path = data_path - self._dialog.set_transient_for(transient) +def show_satellites_dialog(transient, data_path): + global __data_path + __data_path = data_path + handlers = {"on_satellites_list_load": on_satellites_list_load} + builder = Gtk.Builder() + builder.add_from_file("./ui/satellites_dialog.glade") + builder.connect_signals(handlers) + dialog = builder.get_object("satellites_editor_dialog") + dialog.set_transient_for(transient) + dialog.run() + dialog.destroy() - def show(self): - self._dialog.run() - self._dialog.destroy() - def on_satellites_list_load(self, model): - """ Load satellites data into model """ - satellites = get_satellites(self._data_path) - model.clear() - aggr = [None for x in range(9)] - for name, flags, pos, transponders in satellites: - parent = model.append(None, [name, *aggr]) - for transponder in transponders: - model.append(parent, ["Transponder:", *transponder]) +def on_satellites_list_load(model): + """ Load satellites data into model """ + satellites = get_satellites(__data_path) + model.clear() + aggr = [None for x in range(9)] + for name, flags, pos, transponders in satellites: + parent = model.append(None, [name, *aggr]) + for transponder in transponders: + model.append(parent, ["Transponder:", *transponder]) if __name__ == "__main__": diff --git a/main/ui/settings_dialog.glade b/main/ui/settings_dialog.glade new file mode 100644 index 00000000..16e4bb79 --- /dev/null +++ b/main/ui/settings_dialog.glade @@ -0,0 +1,388 @@ + + + + + + False + Options + False + True + preferences-desktop + dialog + + + False + 5 + vertical + 2 + + + False + end + end + + + gtk-undo + True + True + True + True + + + True + True + 2 + + + + + gtk-ok + True + True + True + True + + + True + True + 3 + + + + + False + False + 0 + + + + + True + False + True + + + True + False + Host: + + + 0 + 0 + + + + + True + True + 127.0.0.1 + + + 0 + 1 + + + + + True + False + Login: + + + 0 + 2 + + + + + True + False + Password: + + + 1 + 2 + + + + + True + True + 21 + + + 1 + 1 + + + + + True + False + Port: + + + 1 + 0 + + + + + True + True + root + emblem-personal + False + + + 0 + 3 + + + + + True + True + False + + root + emblem-nowrite + False + password + + + 1 + 3 + + + + + False + True + 0 + + + + + True + False + 2 + 2 + + + False + True + 1 + + + + + True + False + True + + + True + False + Services and Bouquets files: + + + 0 + 0 + + + + + True + True + /etc/enigma2/ + + + 0 + 1 + + + + + True + False + User bouquet files: + + + 0 + 2 + + + + + True + True + /etc/enigma2/ + + + 0 + 3 + + + + + True + False + Satellites.xml file: + + + 0 + 4 + + + + + True + True + /etc/tuxbox/ + + + 0 + 5 + + + + + False + True + 2 + + + + + True + False + 2 + + + False + True + 3 + + + + + True + False + True + + + True + False + Data directory: + 0 + + + 0 + 0 + + + + + True + True + /data + gtk-open + False + Select + Select + + + + 0 + 1 + + + + + False + True + 5 + + + + + True + False + + + False + True + 2 + 6 + + + + + + cancel_button + ok_button + + + + False + + dialog + settings_dialog + save + + + False + vertical + 2 + + + False + end + + + gtk-undo + True + True + True + True + + + True + True + 0 + + + + + gtk-ok + True + True + True + True + 0.55000001192092896 + + + True + True + 1 + + + + + False + False + 0 + + + + + + + + + button2 + button1 + + + diff --git a/main/ui/settings_dialog.py b/main/ui/settings_dialog.py new file mode 100644 index 00000000..1041ec14 --- /dev/null +++ b/main/ui/settings_dialog.py @@ -0,0 +1,57 @@ +import gi + +from main.properties import write_config + +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + + +def show_settings_dialog(transient, options): + handlers = {"on_data_dir_field_icon_press": on_data_dir_field_icon_press} + builder = Gtk.Builder() + builder.add_from_file("ui/settings_dialog.glade") + builder.connect_signals(handlers) + dialog = builder.get_object("settings_dialog") + dialog.set_transient_for(transient) + host_field = builder.get_object("host_field") + host_field.set_text(options["host"]) + port_field = builder.get_object("port_field") + port_field.set_text(options["port"]) + login_field = builder.get_object("login_field") + login_field.set_text(options["user"]) + password_field = builder.get_object("password_field") + password_field.set_text(options["password"]) + services_field = builder.get_object("services_field") + services_field.set_text(options["services_path"]) + user_bouquet_field = builder.get_object("user_bouquet_field") + user_bouquet_field.set_text(options["user_bouquet_path"]) + satellites_xml_field = builder.get_object("satellites_xml_field") + satellites_xml_field.set_text(options["satellites_xml_path"]) + data_dir_field = builder.get_object("data_dir_field") + data_dir_field.set_text(options["data_dir_path"]) + + if dialog.run() == Gtk.ResponseType.OK: + options["host"] = host_field.get_text() + options["port"] = port_field.get_text() + options["user"] = login_field.get_text() + options["password"] = password_field.get_text() + options["services_path"] = services_field.get_text() + options["user_bouquet_path"] = user_bouquet_field.get_text() + options["satellites_xml_path"] = satellites_xml_field.get_text() + options["data_dir_path"] = data_dir_field.get_text() + write_config(options) + dialog.destroy() + + +def on_data_dir_field_icon_press(*args): + builder = Gtk.Builder() + builder.add_from_file("ui/settings_dialog.glade") + dialog = builder.get_object("path_chooser_dialog") + response = dialog.run() + if response == -12: # for fix assertion 'gtk_widget_get_can_default (widget)' failed + args[0].set_text(dialog.get_filename()) + dialog.destroy() + + +if __name__ == "__main__": + pass