From ef97cd365cac20bb7d355f7d4a18b29896303641 Mon Sep 17 00:00:00 2001 From: DYefremov Date: Mon, 11 Oct 2021 00:31:29 +0300 Subject: [PATCH] support of adding custom path to picons --- app/settings.py | 12 +++++- app/ui/settings_dialog.glade | 80 ++++++++++++++++++++++++++++++++---- app/ui/settings_dialog.py | 39 +++++++++++++++++- app/ui/uicommons.py | 17 ++++---- 4 files changed, 129 insertions(+), 19 deletions(-) diff --git a/app/settings.py b/app/settings.py index 69da0d6c..9037381d 100644 --- a/app/settings.py +++ b/app/settings.py @@ -369,8 +369,16 @@ class Settings: @property def picons_paths(self): if self.setting_type is SettingsType.NEUTRINO_MP: - return Defaults.NEUTRINO_BOX_PICON_PATHS.value - return Defaults.BOX_PICON_PATHS.value + return self._settings.get("neutrino_picon_paths", Defaults.NEUTRINO_BOX_PICON_PATHS.value) + else: + return self._settings.get("picon_paths", Defaults.BOX_PICON_PATHS.value) + + @picons_paths.setter + def picons_paths(self, value): + if self.setting_type is SettingsType.NEUTRINO_MP: + self._settings["neutrino_picon_paths"] = value + else: + self._settings["picon_paths"] = value # ***** Local paths ***** # diff --git a/app/ui/settings_dialog.glade b/app/ui/settings_dialog.glade index fb87cd21..4fb814f4 100644 --- a/app/ui/settings_dialog.glade +++ b/app/ui/settings_dialog.glade @@ -871,16 +871,82 @@ Author: Dmitriy Yefremov - + True False - start - 0 - True - - + 2 + + + True False + start + 0 + True + + + False + + + + False + True + 0 + + + + + True + False + expand + + + True + True + True + Remove + + + + True + False + list-remove-symbolic + + + + + False + True + 0 + + + + + True + True + True + Add + + + + True + False + list-add-symbolic + + + + + False + True + 1 + + + + + False + True + 3 + @@ -2029,7 +2095,7 @@ Author: Dmitriy Yefremov English Deutsch - Español + Español Italiano Nederlands Polski diff --git a/app/ui/settings_dialog.py b/app/ui/settings_dialog.py index 150d858e..5fb681d1 100644 --- a/app/ui/settings_dialog.py +++ b/app/ui/settings_dialog.py @@ -67,6 +67,8 @@ class SettingsDialog: "on_profile_edited": self.on_profile_edited, "on_profile_selected": self.on_profile_selected, "on_profile_set_default": self.on_profile_set_default, + "on_add_picon_path": self.on_add_picon_path, + "on_remove_picon_path": self.on_remove_picon_path, "on_lang_changed": self.on_lang_changed, "on_main_settings_visible": self.on_main_settings_visible, "on_http_use_ssl_toggled": self.on_http_use_ssl_toggled, @@ -115,6 +117,7 @@ class SettingsDialog: self._user_bouquet_field = builder.get_object("user_bouquet_field") self._satellites_xml_field = builder.get_object("satellites_xml_field") self._picons_paths_box = builder.get_object("picons_paths_box") + self._remove_picon_path_button = builder.get_object("remove_picon_path_button") # Paths. self._picons_path_field = builder.get_object("picons_path_field") self._data_path_field = builder.get_object("data_path_field") @@ -258,7 +261,10 @@ class SettingsDialog: model = self._picons_paths_box.get_model() model.clear() list(map(lambda p: model.append((p, p)), self._settings.picons_paths)) - self._picons_paths_box.set_active_id(self._settings.picons_path) + if self._settings.picons_path in self._settings.picons_paths: + self._picons_paths_box.set_active_id(self._settings.picons_path) + else: + self._picons_paths_box.set_active(0) def show(self): self._dialog.run() @@ -450,7 +456,7 @@ class SettingsDialog: host, port = self._host_field.get_text(), self._port_field.get_text() user, password = self._login_field.get_text(), self._password_field.get_text() try: - self.show_info_message("OK. {}".format(test_ftp(host, port, user, password)), Gtk.MessageType.INFO) + self.show_info_message(f"OK. {test_ftp(host, port, user, password)}", Gtk.MessageType.INFO) except TestException as e: self.show_info_message(str(e), Gtk.MessageType.ERROR) finally: @@ -572,6 +578,35 @@ class SettingsDialog: def on_profile_inserted(self, model, path, itr): self._profile_remove_button.set_sensitive(len(model) > 1) + def on_add_picon_path(self, button): + response = show_dialog(DialogType.INPUT, self._dialog, self._settings.picons_path) + if response is Gtk.ResponseType.CANCEL: + return + + if response in self._settings.picons_paths: + self.show_info_message("This path already exists!", Gtk.MessageType.ERROR) + return + + path = response if response.endswith(SEP) else response + SEP + model = self._picons_paths_box.get_model() + model.append((path, path)) + self._picons_paths_box.set_active_id(path) + self._ext_settings.picons_paths = tuple(r[0] for r in model) + + def on_remove_picon_path(self, button): + msg = f"{get_message('This may change the settings of other profiles!')}\n\n\t\t{'Are you sure?'}" + if show_dialog(DialogType.QUESTION, self._dialog, msg) != Gtk.ResponseType.OK: + return + + model = self._picons_paths_box.get_model() + active = self._picons_paths_box.get_active_iter() + if active: + model.remove(active) + + self._picons_paths_box.set_active(0) + self._remove_picon_path_button.set_sensitive(len(model) > 1) + self._ext_settings.picons_paths = tuple(r[0] for r in model) + def on_lang_changed(self, box): if box.get_active_id() != self._settings.language: self.show_info_message("Save and restart the program to apply the settings.", Gtk.MessageType.WARNING) diff --git a/app/ui/uicommons.py b/app/ui/uicommons.py index 5040b997..ef7d3422 100644 --- a/app/ui/uicommons.py +++ b/app/ui/uicommons.py @@ -13,17 +13,18 @@ from app.settings import Settings, SettingsException, IS_DARWIN, GTK_PATH, IS_LI # Setting mod mask for keyboard depending on platform MOD_MASK = Gdk.ModifierType.MOD2_MASK if IS_DARWIN else Gdk.ModifierType.CONTROL_MASK -# *.deb -DEB_PATH = "/usr/share/demoneditor/app/ui/" -# Path to *.glade files -UI_RESOURCES_PATH = "app/ui/" if os.path.exists("app/ui/") else "ui/" -UI_RESOURCES_PATH = DEB_PATH if os.path.exists(DEB_PATH) else UI_RESOURCES_PATH -LANG_PATH = UI_RESOURCES_PATH + "lang" -NOTIFY_IS_INIT = False -IS_GNOME_SESSION = int(bool(os.environ.get("GNOME_DESKTOP_SESSION_ID"))) +# Paths. +BASE_PATH = "app/ui/" +EX_PATH = "/usr/share/demoneditor/app/ui/" if IS_LINUX else "ui/" +# Path to *.glade files. +UI_RESOURCES_PATH = BASE_PATH if os.path.exists(BASE_PATH) else EX_PATH # Translation. +LANG_PATH = UI_RESOURCES_PATH + "lang" TEXT_DOMAIN = "demon-editor" + +NOTIFY_IS_INIT = False APP_FONT = None +IS_GNOME_SESSION = int(bool(os.environ.get("GNOME_DESKTOP_SESSION_ID"))) try: settings = Settings.get_instance()