[gnome-tweak-tool] add scaffolding for supporting log in/out on changes
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tweak-tool] add scaffolding for supporting log in/out on changes
- Date: Wed, 17 Jul 2013 20:38:43 +0000 (UTC)
commit bd868258e305764f7abfaeba433f24407026e636
Author: John Stowers <john stowers gmail com>
Date: Wed Jul 17 22:36:42 2013 +0200
add scaffolding for supporting log in/out on changes
gtweak/tweakmodel.py | 12 ++++++------
gtweak/tweaks/tweak_test.py | 31 ++++++++++++++++++++-----------
gtweak/tweakview.py | 5 ++++-
gtweak/widgets.py | 11 +++++++++++
4 files changed, 41 insertions(+), 18 deletions(-)
---
diff --git a/gtweak/tweakmodel.py b/gtweak/tweakmodel.py
index 2e52db7..86016d1 100644
--- a/gtweak/tweakmodel.py
+++ b/gtweak/tweakmodel.py
@@ -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):
diff --git a/gtweak/tweaks/tweak_test.py b/gtweak/tweaks/tweak_test.py
index 33b778f..df6075b 100644
--- a/gtweak/tweaks/tweak_test.py
+++ b/gtweak/tweaks/tweak_test.py
@@ -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),
)
diff --git a/gtweak/tweakview.py b/gtweak/tweakview.py
index ac8ae45..f17b192 100644
--- a/gtweak/tweakview.py
+++ b/gtweak/tweakview.py
@@ -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))
diff --git a/gtweak/widgets.py b/gtweak/widgets.py
index afd0fae..10cb189 100644
--- a/gtweak/widgets.py
+++ b/gtweak/widgets.py
@@ -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):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]