Commit bd868258 authored by John Stowers's avatar John Stowers

add scaffolding for supporting log in/out on changes

parent 77497d76
......@@ -74,17 +74,17 @@ class Tweak:
def set_notify_cb(self, func):
self._notify_cb = func
def notify_action_required(self, desc, btn, func, error=False):
def notify_action_required(self, desc, btn, func, need_logout=False):
if self._notify_cb:
self._notify_cb(self, desc, error, btn, func)
self._notify_cb(self, desc, error=False, btn=btn, func=func, need_logout=need_logout)
def notify_error(self, desc):
def notify_error(self, desc, need_logout=False):
if self._notify_cb:
self._notify_cb(self, desc, True, None, None)
self._notify_cb(self, desc, error=True, btn=None, func=None, need_logout=need_logout)
def notify_info(self, desc):
def notify_info(self, desc, need_logout=False):
if self._notify_cb:
self._notify_cb(self, desc, False, None, None)
self._notify_cb(self, desc, error=False, btn=None, func=None, need_logout=need_logout)
class TweakGroup:
def __init__(self, name, *tweaks):
......
......@@ -28,9 +28,9 @@ class _TestInfoTweak(Tweak):
self.widget = build_label_beside_widget(
name,
Gtk.Button(options.get("test_button_name",name)),
info=options.get("tweak_info"),
warning=options.get("tweak_warning"))
Gtk.Button(options.get("_test_button_name",name)),
info=options.get("_tweak_info"),
warning=options.get("_tweak_warning"))
class _TestTweak(Tweak):
def __init__(self, name, description, **options):
......@@ -42,8 +42,9 @@ class _TestButtonTweak(Tweak):
Tweak.__init__(self, name, description, **options)
self.widget = Gtk.Button(name)
self.widget.connect("clicked", self._on_click)
self._need_action = options.get("need_action")
self._action_error = options.get("action_error")
self._need_action = options.get("_need_action")
self._action_error = options.get("_action_error")
self._need_logout = options.get("_need_logout")
def _on_click(self, sender):
if self._need_action:
......@@ -51,6 +52,13 @@ class _TestButtonTweak(Tweak):
self.name,
Gtk.STOCK_OK,
lambda : print("GOT CALLBACK"))
elif self._need_logout:
self.notify_action_required(
self.name,
Gtk.STOCK_OK,
func=None,
need_logout=True,
)
else:
if self._action_error:
self.notify_error(self.name)
......@@ -68,11 +76,12 @@ group_name = "Test Settings"
TWEAKS = (
_TestTweak("foo bar", "does foo bar", group_name=group_name),
_TestTweak("foo baz", "does foo baz", group_name=group_name),
_TestInfoTweak("long string "*10, "long description "*10, test_button_name="short",group_name=group_name),
_TestInfoTweak("foo info", "info widget", tweak_info="Information", group_name=group_name),
_TestInfoTweak("foo warning", "info widget", tweak_warning="Warning", group_name=group_name),
_TestButtonTweak("Need Action", "foo bar", need_action=True, group_name=group_name),
_TestButtonTweak("Report Error", "foo baz", action_error=True, group_name=group_name),
_TestButtonTweak("Report Info", "foo bob", action_error=False, group_name=group_name),
_TestInfoTweak("long string "*10, "long description "*10, _test_button_name="short",group_name=group_name),
_TestInfoTweak("foo info", "info widget", _tweak_info="Information", group_name=group_name),
_TestInfoTweak("foo warning", "info widget", _tweak_warning="Warning", group_name=group_name),
_TestButtonTweak("Need Action", "foo bar", _need_action=True, group_name=group_name),
_TestButtonTweak("Report Error", "foo baz", _action_error=True, group_name=group_name),
_TestButtonTweak("Report Info", "foo bob", _action_error=False, group_name=group_name),
_TestButtonTweak("Need Log Out", "foo bar log", _need_logout=True, group_name=group_name),
)
......@@ -106,7 +106,10 @@ class TweakView:
except KeyError:
logging.warning("Could not remove notification function")
def _on_tweak_notify(self, tweak, desc, error, btn, func):
def _on_tweak_notify(self, tweak, desc, error, btn, func, need_logout):
#if need to log out, do this as a notification area thing, not a note inside
#the main window
info = Gtk.InfoBar()
info.get_content_area().add(Gtk.Label(desc))
......
......@@ -168,6 +168,17 @@ class _GSettingsTweak(Tweak):
self.loaded = False
logging.info("GSettings missing key %s (key %s)" % (schema_name, key_name))
if options.get("logout_required") and self.loaded:
self.settings.connect("changed::%s" % key_name, self._on_changed_notify_logout)
def _on_changed_notify_logout(self, settings, key_name):
self.notify_action_required(
"Configuration changes require restart",
btn="Restart Session",
func=None,
need_logout=True,
)
class GSettingsSwitchTweak(_GSettingsTweak):
def __init__(self, schema_name, key_name, **options):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment