Added tooltips to CanvasIcon and implement popup positioning in the Frame.

This commit is contained in:
Tomeu Vizoso
2007-02-22 22:51:24 +01:00
parent 7ef6283ac4
commit 6756c00917
7 changed files with 95 additions and 23 deletions
+25 -2
View File
@@ -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
+8 -8
View File
@@ -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)
+8 -7
View File
@@ -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')