From 743914e33765f244b3dd29067c46b94af04ec5bf Mon Sep 17 00:00:00 2001 From: Runkai Zhang Date: Sun, 15 May 2022 19:36:54 -0400 Subject: [PATCH 1/3] Hide button when default is detected --- GTG/gtk/backends/configurepanel.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/GTG/gtk/backends/configurepanel.py b/GTG/gtk/backends/configurepanel.py index e6a67b5939..15a32e2dec 100644 --- a/GTG/gtk/backends/configurepanel.py +++ b/GTG/gtk/backends/configurepanel.py @@ -139,7 +139,8 @@ def refresh_sync_button(self): """ Refreshes the state of the button that enables the backend """ - self.sync_button.set_sensitive(not self.backend.is_default()) + if self.backend.is_default(): + self.sync_button.hide() if self.backend.is_enabled(): label = _("Disable syncing") else: @@ -179,6 +180,8 @@ def on_sync_button_clicked(self, sender): self.req.set_backend_enabled(self.backend.get_id(), not self.backend.is_enabled()) + print(self.backend.get_id()) + def on_sync_started(self, sender, backend_id): """ If the backend has started syncing tasks, update the state of the From 9b18fff177f768bcc662dc89f86741a4bd19b72c Mon Sep 17 00:00:00 2001 From: Runkai Zhang Date: Mon, 16 May 2022 13:43:02 -0400 Subject: [PATCH 2/3] Default file storage back-end now allows users to open the XML data file directly from the description. Button hiding is now a one liner. Description for file storage updated to be more accurate since it is not a sync service. Remove extraneous print statement from previous commit. --- GTG/gtk/backends/configurepanel.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/GTG/gtk/backends/configurepanel.py b/GTG/gtk/backends/configurepanel.py index 15a32e2dec..4173534de5 100644 --- a/GTG/gtk/backends/configurepanel.py +++ b/GTG/gtk/backends/configurepanel.py @@ -16,7 +16,7 @@ # this program. If not, see . # ----------------------------------------------------------------------------- -from gi.repository import Gtk +from gi.repository import Gtk, GLib from gettext import gettext as _ from GTG.gtk.backends.parameters_ui import ParametersUI @@ -139,8 +139,7 @@ def refresh_sync_button(self): """ Refreshes the state of the button that enables the backend """ - if self.backend.is_default(): - self.sync_button.hide() + self.sync_button.set_visible(not self.backend.is_default()) if self.backend.is_enabled(): label = _("Disable syncing") else: @@ -152,7 +151,9 @@ def refresh_sync_status_label(self): Refreshes the Gtk.Label that shows the current state of this backend """ if self.backend.is_default(): - label = _("This is the default synchronization service") + xml_folder = GLib.filename_to_uri("/home/" + GLib.get_user_name() + "/.var/app/org.gnome.GTG/data/gtg/gtg_data.xml") + + label = "This is the default file storage backend. {}.".format(xml_folder, _("Open the XML data file")) else: if self.backend.is_enabled(): label = _("Syncing is enabled.") @@ -180,8 +181,6 @@ def on_sync_button_clicked(self, sender): self.req.set_backend_enabled(self.backend.get_id(), not self.backend.is_enabled()) - print(self.backend.get_id()) - def on_sync_started(self, sender, backend_id): """ If the backend has started syncing tasks, update the state of the From 3e7dc1f3b59432494cf7fb3fc54029c0028b4998 Mon Sep 17 00:00:00 2001 From: Runkai Zhang Date: Mon, 16 May 2022 14:34:59 -0400 Subject: [PATCH 3/3] Improve Sync UI when missing packages The add panel now has the ability to detect which back-ends failed to initialize on start, and the developer can add corresponding error messages to help the user resolve dependency problems. --- GTG/backends/__init__.py | 4 +++- GTG/gtk/backends/addpanel.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/GTG/backends/__init__.py b/GTG/backends/__init__.py index d7b740e78f..ee797f19ac 100644 --- a/GTG/backends/__init__.py +++ b/GTG/backends/__init__.py @@ -32,7 +32,7 @@ from GTG.backends.generic_backend import GenericBackend log = logging.getLogger(__name__) - +inactive_modules = set() class BackendFactory(Borg): """ @@ -67,10 +67,12 @@ def __init__(self): # Something is wrong with this backend, skipping log.warning("Backend %s could not be loaded: %r", module_name, exception) + inactive_modules.append(module_name) continue except Exception: # Other exception log as errors log.exception("Malformated backend %s:", module_name) + inactive_modules.append(module_name) continue def browse_subclasses(cls): diff --git a/GTG/gtk/backends/addpanel.py b/GTG/gtk/backends/addpanel.py index b6b27320ff..7c6028af21 100644 --- a/GTG/gtk/backends/addpanel.py +++ b/GTG/gtk/backends/addpanel.py @@ -24,6 +24,8 @@ from GTG.backends import BackendFactory from gettext import gettext as _, ngettext +from GTG.backends import inactive_modules + class AddPanel(Gtk.Box): """ @@ -170,7 +172,16 @@ def on_combo_changed(self, widget=None): """ backend_name = self.combo_types.get_selected() if backend_name is None: + if 'backend_caldav' in inactive_modules: + markup = 'Error: Python package \'caldev\' not installed.' + self.label_name.set_markup(markup) + return + + + markup = 'Error: An unknown backend could not be loaded.' + self.label_name.set_markup(markup) return + backend = BackendFactory().get_backend(backend_name) self.label_description.set_markup(backend.Backend.get_description())