[gnome-tweak-tool] Remove mostly unused complex infobox based notifications



commit 1aa4b7db1272b2322e492812de60e072d5d7081a
Author: John Stowers <john stowers gmail com>
Date:   Tue Aug 6 12:03:23 2013 +0200

    Remove mostly unused complex infobox based notifications

 gtweak/tweakmodel.py |   22 +++++-----------------
 gtweak/tweakview.py  |   45 ---------------------------------------------
 gtweak/utils.py      |   34 +++++++++++++++++++++++-----------
 3 files changed, 28 insertions(+), 73 deletions(-)
---
diff --git a/gtweak/tweakmodel.py b/gtweak/tweakmodel.py
index d0608ee..6f91126 100644
--- a/gtweak/tweakmodel.py
+++ b/gtweak/tweakmodel.py
@@ -20,7 +20,7 @@ import glob
 import os.path
 
 import gtweak
-from gtweak.utils import SchemaList
+from gtweak.utils import SchemaList, LogoutNotification, Notification
 from gi.repository import Gtk
 
 def N_(x): return x
@@ -60,29 +60,17 @@ class Tweak(object):
         self._search_cache = None
         if options.get("sort"):
             self.widget_sort_hint = options.get("sort")
-        #FIXME: I would have rather done these as a GObject signal, but it
-        #would prohibit other tweaks from inheriting from GtkWidgets
-        self._notify_cb = None
 
     def search_matches(self, txt):
         if self._search_cache == None:
             self._search_cache = self.name.lower() + " " + self.description.lower()
         return  txt in self._search_cache
 
-    def set_notify_cb(self, func):
-        self._notify_cb = func
+    def notify_logout(self):
+        self._logoutnotification = LogoutNotification()
 
-    def notify_action_required(self, desc, btn, func, need_logout=False):
-        if self._notify_cb:
-            self._notify_cb(self, desc, error=False, btn=btn, func=func, need_logout=need_logout)
-
-    def notify_error(self, desc, need_logout=False):
-        if self._notify_cb:
-            self._notify_cb(self, desc, error=True, btn=None, func=None, need_logout=need_logout)
-
-    def notify_info(self, desc, need_logout=False):
-        if self._notify_cb:
-            self._notify_cb(self, desc, error=False, btn=None, func=None, need_logout=need_logout)
+    def notify_information(self, summary, desc=""):
+        self._notification = Notification(summary, desc)
 
 class TweakGroup(object):
     def __init__(self, name, *tweaks):
diff --git a/gtweak/tweakview.py b/gtweak/tweakview.py
index bee5603..c786bbf 100644
--- a/gtweak/tweakview.py
+++ b/gtweak/tweakview.py
@@ -23,7 +23,6 @@ from gi.repository import Gtk, Gdk, GObject
 
 import gtweak.tweakmodel
 from gtweak.tweakmodel import TweakModel
-from gtweak.utils import LogoutNotification
 from gtweak.widgets import Title
 
 DEFAULT_TWEAKGROUP = gtweak.tweakmodel.TWEAK_GROUP_APPEARANCE
@@ -113,11 +112,9 @@ class Window(Gtk.ApplicationWindow):
         #GRR why can I not put margin in the CSS?
         self.stack = Gtk.Stack(name="main-container",
                                margin=20)
-        self._detail_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
 
         right_box.pack_start(self.right_header, False, False, 0)
         right_box.pack_start(self.stack, True, True, 0)
-        right_box.pack_start(self._detail_vbox, False, False, 0)
         
         return right_box
 
@@ -154,7 +151,6 @@ class Window(Gtk.ApplicationWindow):
 
         widget = self.listbox.get_row_at_index(0)
         self.listbox.select_row (widget)
-        self._notification_functions = {}
 
     def _list_filter_func(self, row, user_data):
         lbl = row.get_child()
@@ -207,44 +203,3 @@ class Window(Gtk.ApplicationWindow):
                 t.show_all()
             else:
                 t.hide()
-
-    def _on_tweak_notify_response(self, info, response, func):
-        self._detail_vbox.remove(info)
-        func()
-        try:
-            del(self._notification_functions[func])
-        except KeyError:
-            logging.warning("Could not remove notification function")
-
-    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
-        
-        if need_logout:
-            try:
-                notification = LogoutNotification()
-                notification.show()
-                return
-            except:
-                pass
-        
-        info = Gtk.InfoBar()
-        info.get_content_area().add(Gtk.Label(desc))
-
-        if error:
-            info.props.message_type = Gtk.MessageType.ERROR
-        else:
-            info.props.message_type = Gtk.MessageType.INFO
-
-        if btn and func:
-            if func in self._notification_functions:
-                return
-            self._notification_functions[func] = True
-            info.add_button(btn, Gtk.ResponseType.OK)
-            info.connect("response", self._on_tweak_notify_response, func)
-        else:
-            GObject.timeout_add_seconds(2, lambda box, widget: box.remove(widget), self._detail_vbox, info)
-
-        self._detail_vbox.pack_end(info, False, False, 0)
-
-        info.show_all()
diff --git a/gtweak/utils.py b/gtweak/utils.py
index 7a46b23..130f9e9 100644
--- a/gtweak/utils.py
+++ b/gtweak/utils.py
@@ -312,29 +312,41 @@ class XSettingsOverrides:
     def get_enable_primary_paste(self):
         self._get_override('Gtk/EnablePrimaryPaste', True)
 
+class Notification:
+    def __init__(self, summary, body):
+        if Notify.is_initted() or Notify.init("GNOME Tweak Tool"):
+            self.notification = Notify.Notification.new(
+                                    summary,
+                                    body,
+                                    'gnome-tweak-tool'
+            )
+            self.notification.set_hint(
+                                "desktop-entry",
+                                GLib.Variant('s', 'gnome-tweak-tool'))
+            self.notification.show()
+        else:
+            raise Exception("Not Supported")
+
+ singleton
 class LogoutNotification:
     def __init__(self):
-        self.notification = None
         if Notify.is_initted() or Notify.init("GNOME Tweak Tool"):
-            self.notification = Notify.Notification.new("Configuration changes requiere restart","Your 
session needs to be restarted for settings to take effect", 'gnome-tweak-tool')
+            self.notification = Notify.Notification.new(
+                                "Configuration changes requiere restart",
+                                "Your session needs to be restarted for settings to take effect",
+                                'gnome-tweak-tool')
             self.notification.add_action(
                                 "restart",
                                 "Restart Session",
-                                self.logout,None,None)
-            self.notification.set_hint(
-                                "resident",
-                                GLib.Variant('b', True))
+                                self._logout, None, None)
             self.notification.set_hint(
                                 "desktop-entry",
                                 GLib.Variant('s', 'gnome-tweak-tool'))
+            self.notification.show()
         else:
             raise Exception("Not Supported")
 
-    def show(self):
-        if self.notification:
-            self.notification.show()
-
-    def logout(self, btn, action, unknown):
+    def _logout(self, btn, action, unknown):
         d = Gio.bus_get_sync(Gio.BusType.SESSION, None)
         proxy = Gio.DBusProxy.new_sync(
                        d,Gio.DBusProxyFlags.NONE, None,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]