diff options
author | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2007-02-22 21:51:24 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2007-02-22 21:51:24 (GMT) |
commit | 6756c00917fec4892444fa8dfd70dee99c99f291 (patch) | |
tree | 5c2b077f3064bf4e27bc8d250b5e067f64121d56 /sugar/graphics | |
parent | 7ef6283ac4b7833982d864a92992efa188546238 (diff) |
Added tooltips to CanvasIcon and implement popup positioning in the Frame.
Diffstat (limited to 'sugar/graphics')
-rw-r--r-- | sugar/graphics/canvasicon.py | 27 | ||||
-rw-r--r-- | sugar/graphics/iconbutton.py | 16 | ||||
-rw-r--r-- | sugar/graphics/popup.py | 15 |
3 files changed, 41 insertions, 17 deletions
diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index fb4974a..67c35aa 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -26,6 +26,10 @@ import time from sugar.graphics.iconcolor import IconColor from sugar.graphics.timeline import Timeline +from sugar.graphics.popup import Popup +from sugar.graphics import color +from sugar.graphics import font +from sugar.graphics import units class _IconCacheIcon: def __init__(self, name, color, now): @@ -140,6 +144,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): 0.0, 1024.0, 1.0, gobject.PARAM_READWRITE), 'cache' : (bool, None, None, False, + gobject.PARAM_READWRITE), + 'tooltip' : (str, None, None, None, gobject.PARAM_READWRITE) } @@ -155,7 +161,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): self._handle = None self._popup = None self._hover_popup = False - + self._tooltip = False + self._timeline = Timeline(self) self._timeline.add_tag('popup', 6, 6) self._timeline.add_tag('before_popdown', 7, 7) @@ -193,6 +200,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): self.emit_request_changed() elif pspec.name == 'cache': self._cache = value + elif pspec.name == 'tooltip': + self._tooltip = value def _get_handle(self): if not self._handle: @@ -212,6 +221,8 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): return self._color elif pspec.name == 'cache': return self._cache + elif pspec.name == 'tooltip': + return self._tooltip def _get_icon_size(self): handle = self._get_handle() @@ -272,7 +283,19 @@ class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem): item.emit_activated() def get_popup(self): - return self._popup + if self._tooltip: + tooltip_popup = Popup() + canvas_text = hippo.CanvasText(text=self._tooltip) + canvas_text.props.background_color = color.MENU_BACKGROUND.get_int() + canvas_text.props.border_color = color.MENU_BORDER.get_int() + canvas_text.props.border = units.points_to_pixels(1) + canvas_text.props.color = color.LABEL_TEXT.get_int() + canvas_text.props.font_desc = font.DEFAULT.get_pango_desc() + tooltip_popup.append(canvas_text) + + return tooltip_popup + else: + return None def get_popup_context(self): return None diff --git a/sugar/graphics/iconbutton.py b/sugar/graphics/iconbutton.py index c2a1046..b1992a6 100644 --- a/sugar/graphics/iconbutton.py +++ b/sugar/graphics/iconbutton.py @@ -39,19 +39,19 @@ class IconButton(CanvasIcon): gobject.PARAM_READWRITE) } - def __init__(self, icon_name, color=None): - if color: - self._normal_color = color + def __init__(self, **kwargs): + self._active = True + + CanvasIcon.__init__(self, cache=True, **kwargs) + + if self.props.color: + self._normal_color = self.props.color else: self._normal_color = IconColor('white') + self.props.color = self._normal_color self._prelight_color = profile.get_color() self._inactive_color = IconColor('#808080,#424242') - self._active = True - - CanvasIcon.__init__(self, icon_name=icon_name, cache=True, - color=self._normal_color) - self._set_size(STANDARD_SIZE) self.connect('button-press-event', self._button_press_event_cb) diff --git a/sugar/graphics/popup.py b/sugar/graphics/popup.py index 09a1fe2..5c63b6e 100644 --- a/sugar/graphics/popup.py +++ b/sugar/graphics/popup.py @@ -30,20 +30,21 @@ class Popup(hippo.CanvasBox, hippo.CanvasItem): def __init__(self): hippo.CanvasBox.__init__(self) - self._window = None + self._visible = False + self._window = hippo.CanvasWindow(gtk.WINDOW_POPUP) + self._window.set_root(self) self.connect('button-press-event', self._button_press_event_cb) def popup(self, x, y): - if not self._window: - self._window = hippo.CanvasWindow(gtk.WINDOW_POPUP) + if not self._visible: self._window.move(x, y) - self._window.set_root(self) self._window.show() + self._visible = True def popdown(self): - if self._window: - self._window.destroy() - self._window = None + if self._visible: + self._window.hide() + self._visible = False def _button_press_event_cb(self, menu, event): self.emit('action-completed') |