[gnome-tweak-tool] Dont offer multiple actions if they result in the same callback



commit 2d93b4656911f9d956e75a39852766908f82c141
Author: John Stowers <john stowers gmail com>
Date:   Fri May 27 16:47:48 2011 +1200

    Dont offer multiple actions if they result in the same callback
    
    This has the effect of preventing multiple infobars offering to
    restart the shell after enabling/disabling extensions.

 gtweak/tweaks/tweak_shell_extensions.py |    8 ++++----
 gtweak/tweakview.py                     |   15 ++++++++++++++-
 2 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/gtweak/tweaks/tweak_shell_extensions.py b/gtweak/tweaks/tweak_shell_extensions.py
index b527b51..f942dcc 100644
--- a/gtweak/tweaks/tweak_shell_extensions.py
+++ b/gtweak/tweaks/tweak_shell_extensions.py
@@ -47,7 +47,7 @@ class _ShellExtensionTweak(Tweak):
         self.notify_action_required(
             "The shell must be restarted for changes to take effect",
             "Restart",
-            lambda: self._shell.restart())
+            self._shell.restart)
 
 class _ShellExtensionInstallerTweak(Tweak):
 
@@ -113,7 +113,7 @@ class _ShellExtensionInstallerTweak(Tweak):
                     self.notify_action_required(
                         verb,
                         "Restart",
-                        lambda: self._shell.restart())
+                        self._shell.restart)
 
                 else:
                     self.notify_error("Error installing extension")
@@ -137,8 +137,8 @@ class ShellExtensionTweakGroup(TweakGroup):
             shell = GnomeShell()
 
             #add the extension installer
-            #extension_tweaks.append(
-            #    _ShellExtensionInstallerTweak(shell, size_group=sg))
+            extension_tweaks.append(
+                _ShellExtensionInstallerTweak(shell, size_group=sg))
 
             try:
                 settings = GSettingsSetting("org.gnome.shell")
diff --git a/gtweak/tweakview.py b/gtweak/tweakview.py
index ab80908..7c46361 100644
--- a/gtweak/tweakview.py
+++ b/gtweak/tweakview.py
@@ -15,6 +15,8 @@
 # You should have received a copy of the GNU General Public License
 # along with gnome-tweak-tool.  If not, see <http://www.gnu.org/licenses/>.
 
+import logging
+
 from gi.repository import Gtk, Gdk, GObject
 
 import gtweak
@@ -63,6 +65,9 @@ class TweakView:
             tweak_box.pack_start(t.widget, False, False, 0)
             t.set_notify_cb(self._on_tweak_notify)
 
+        #dict of pending notifications, the key is the function to be called
+        self._notification_functions = {}
+
     def run(self):
         self._main_window.show_all()
         self.hide_tweaks(self._model.tweaks)
@@ -87,11 +92,14 @@ class TweakView:
     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):
         info = Gtk.InfoBar()
         info.get_content_area().add(Gtk.Label(desc))
-        self._detail_vbox.pack_end(info, False, False, 0)
 
         if error:
             info.props.message_type = Gtk.MessageType.ERROR
@@ -99,11 +107,16 @@ class TweakView:
             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()
 
     def _on_search(self, txt):



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