Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar3/graphics/icon.py
diff options
context:
space:
mode:
authorDaniel Drake <dsd@laptop.org>2011-12-14 23:47:11 (GMT)
committer Simon Schampijer <simon@schampijer.de>2011-12-20 17:35:25 (GMT)
commit827ab7218a588f684ad2a0e346399b401b45b716 (patch)
tree831d9e85c54d0042c64771196bad38b6ae61f924 /src/sugar3/graphics/icon.py
parent5ad2fc7d6be7e499f55ae3c413f06003136c86f3 (diff)
Add EventIcon/CursorInvoker similar to CanvasIcon/CanvasInvoker
CanvasIcon and CanvasInvoker were removed in a previous GTK3-porting commit as they were based on hippocanvas. However, this leaves the toolkit with some missing functionality: there is no longer a trivial way to show an icon which can receive mouse events and pop up a palette. Such functionality is used in various places throughout the shell and activities. Reimplement this functionality as EventIcon and CursorInvoker. Instead of reimplementing much of the Icon class (like CanvasIcon did), EventIcon opts for a more simplistic encapsulation of an Icon object. This means trivial API changes for CanvasIcon users who must now use the 'icon' property with the Icon API. Signed-off-by: Daniel Drake <dsd@laptop.org> Acked-by: Simon Schampijer <simon@laptop.org>
Diffstat (limited to 'src/sugar3/graphics/icon.py')
-rw-r--r--src/sugar3/graphics/icon.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/sugar3/graphics/icon.py b/src/sugar3/graphics/icon.py
index f6c9374..2d98f8a 100644
--- a/src/sugar3/graphics/icon.py
+++ b/src/sugar3/graphics/icon.py
@@ -29,6 +29,7 @@ from gi.repository import GObject
from gi.repository import Gtk
import cairo
+from sugar3.graphics import style
from sugar3.graphics.xocolor import XoColor
from sugar3.util import LRU
@@ -545,6 +546,75 @@ class Icon(Gtk.Image):
type=float, setter=set_scale)
+class EventIcon(Gtk.EventBox):
+ """
+ An Icon class that provides access to mouse events and that can act as a
+ cursor-positioned palette invoker.
+ """
+
+ __gtype_name__ = 'EventIcon'
+ __gsignals__ = {
+ 'activated': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, []),
+ }
+
+ def __init__(self, **kwargs):
+ Gtk.EventBox.__init__(self)
+
+ self._icon = Icon()
+ for key, value in kwargs.iteritems():
+ self._icon.set_property(key, value)
+ self.add(self._icon)
+ self._icon.show()
+
+ from sugar3.graphics.palette import CursorInvoker
+ self._palette_invoker = CursorInvoker()
+ self._palette_invoker.attach(self)
+
+ self.modify_bg(Gtk.StateType.NORMAL, style.COLOR_WHITE.get_gdk_color())
+ self.connect('destroy', self.__destroy_cb)
+
+ def __destroy_cb(self, icon):
+ if self._palette_invoker is not None:
+ self._palette_invoker.detach()
+
+ def do_button_press_event(self, event):
+ if event.button == 1:
+ self.emit('activated')
+ return True
+ else:
+ return False
+
+ def get_icon(self):
+ return self._icon
+
+ icon = GObject.property(
+ type=object, getter=get_icon)
+
+ def get_palette(self):
+ return self._palette_invoker.palette
+
+ def set_palette(self, palette):
+ self._palette_invoker.palette = palette
+
+ palette = GObject.property(
+ type=object, setter=set_palette, getter=get_palette)
+
+ def get_palette_invoker(self):
+ return self._palette_invoker
+
+ def set_palette_invoker(self, palette_invoker):
+ self._palette_invoker.detach()
+ self._palette_invoker = palette_invoker
+
+ palette_invoker = GObject.property(
+ type=object, setter=set_palette_invoker, getter=get_palette_invoker)
+
+ def set_tooltip(self, text):
+ from sugar3.graphics.palette import Palette
+
+ self.set_palette(Palette(text))
+
+
class CellRendererIcon(Gtk.CellRenderer):
__gtype_name__ = 'SugarCellRendererIcon'