[Sugar-devel] [PATCH] Add 'cache-palette' property to Invoker #1742

Tomeu Vizoso tomeu.vizoso at collabora.co.uk
Thu Oct 14 12:50:49 EDT 2010


Meaning that the palette will be cached after it's created.
---
 src/sugar/graphics/palette.py       |    1 +
 src/sugar/graphics/palettewindow.py |   23 ++++++++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/sugar/graphics/palette.py b/src/sugar/graphics/palette.py
index d4632eb..d4f844c 100644
--- a/src/sugar/graphics/palette.py
+++ b/src/sugar/graphics/palette.py
@@ -158,6 +158,7 @@ class Palette(PaletteWindow):
         self.popdown(immediate=True)
         # Break the reference cycle. It looks like the gc is not able to free
         # it, possibly because gtk.Menu memory handling is very special.
+        self.menu.disconnect_by_func(self.__menu_item_inserted_cb)
         self.menu = None
 
     def __show_cb(self, widget):
diff --git a/src/sugar/graphics/palettewindow.py b/src/sugar/graphics/palettewindow.py
index 22131c2..f51c938 100644
--- a/src/sugar/graphics/palettewindow.py
+++ b/src/sugar/graphics/palettewindow.py
@@ -179,6 +179,7 @@ class PaletteWindow(gtk.Window):
 
     def __destroy_cb(self, palette):
         self.set_group_id(None)
+        self._mouse_detector.disconnect_by_func(self._mouse_slow_cb)
 
     def set_invoker(self, invoker):
         for hid in self._invoker_hids[:]:
@@ -457,6 +458,7 @@ class Invoker(gobject.GObject):
         self._cursor_x = -1
         self._cursor_y = -1
         self._palette = None
+        self._cache_palette = True
 
     def attach(self, parent):
         self.parent = parent
@@ -639,18 +641,33 @@ class Invoker(gobject.GObject):
     def set_palette(self, palette):
         if self._palette is not None:
             self._palette.popdown(immediate=True)
-
-        if self._palette:
             self._palette.props.invoker = None
+            self._palette.destroy()
 
         self._palette = palette
 
-        if self._palette:
+        if self._palette is not None:
             self._palette.props.invoker = self
+            self._palette.connect('popdown', self.__palette_popdown_cb)
 
     palette = gobject.property(
         type=object, setter=set_palette, getter=get_palette)
 
+    def get_cache_palette(self):
+        return self._cache_palette
+
+    def set_cache_palette(self, cache_palette):
+        self._cache_palette = cache_palette
+
+    cache_palette = gobject.property(type=object, setter=set_cache_palette,
+                                     getter=get_cache_palette)
+    """Whether the invoker will cache the palette after its creation. Defaults
+    to True.
+    """
+
+    def __palette_popdown_cb(self, palette):
+        if not self.props.cache_palette:
+            self.set_palette(None)
 
 class WidgetInvoker(Invoker):
 
-- 
1.7.2.3



More information about the Sugar-devel mailing list