Added tooltips to CanvasIcon and implement popup positioning in the Frame.
This commit is contained in:
@@ -25,10 +25,11 @@ from sugar.activity import bundleregistry
|
||||
from sugar import profile
|
||||
|
||||
class ActivityButton(IconButton):
|
||||
def __init__(self, activity):
|
||||
IconButton.__init__(self, icon_name=activity.get_icon())
|
||||
|
||||
def __init__(self, activity, popup_context):
|
||||
IconButton.__init__(self, icon_name=activity.get_icon(),
|
||||
tooltip=activity.get_name())
|
||||
self._activity = activity
|
||||
self._popup_context = popup_context
|
||||
|
||||
def _mouse_motion_event_cb(self, item, event):
|
||||
if event.detail == hippo.MOTION_DETAIL_ENTER:
|
||||
@@ -38,6 +39,9 @@ class ActivityButton(IconButton):
|
||||
|
||||
def get_bundle_id(self):
|
||||
return self._activity.get_service_name()
|
||||
|
||||
def get_popup_context(self):
|
||||
return self._popup_context
|
||||
|
||||
class InviteButton(IconButton):
|
||||
def __init__(self, activity, invite):
|
||||
@@ -56,13 +60,14 @@ class InviteButton(IconButton):
|
||||
return self._invite
|
||||
|
||||
class ActivitiesBox(hippo.CanvasBox):
|
||||
def __init__(self, shell):
|
||||
def __init__(self, shell, popup_context):
|
||||
hippo.CanvasBox.__init__(self, orientation=hippo.ORIENTATION_HORIZONTAL)
|
||||
|
||||
self._shell = shell
|
||||
self._shell_model = self._shell.get_model()
|
||||
self._invite_to_item = {}
|
||||
self._invites = self._shell_model.get_invites()
|
||||
self._popup_context = popup_context
|
||||
|
||||
bundle_registry = bundleregistry.get_registry()
|
||||
for bundle in bundle_registry:
|
||||
@@ -94,7 +99,7 @@ class ActivitiesBox(hippo.CanvasBox):
|
||||
self.add_activity(bundle)
|
||||
|
||||
def add_activity(self, activity):
|
||||
item = ActivityButton(activity)
|
||||
item = ActivityButton(activity, self._popup_context)
|
||||
item.connect('activated', self._activity_clicked_cb)
|
||||
self.append(item, 0)
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ class Frame:
|
||||
panel = self._create_panel(hippo.ORIENTATION_HORIZONTAL)
|
||||
root = panel.get_root()
|
||||
|
||||
box = ActivitiesBox(self._shell)
|
||||
box = ActivitiesBox(self._shell, self._popup_context)
|
||||
root.append(box)
|
||||
|
||||
return panel
|
||||
|
||||
@@ -14,13 +14,52 @@
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
import logging
|
||||
|
||||
import gobject
|
||||
import gtk
|
||||
import hippo
|
||||
|
||||
from sugar.graphics.popupcontext import PopupContext
|
||||
from sugar.graphics import units
|
||||
|
||||
class FramePopupContext(PopupContext):
|
||||
__gtype_name__ = 'SugarFramePopupContext'
|
||||
|
||||
def __init__(self):
|
||||
PopupContext.__init__(self)
|
||||
|
||||
def get_position(self, control, popup):
|
||||
[item_x, item_y] = control.get_context().translate_to_screen(control)
|
||||
[item_w, item_h] = control.get_allocation()
|
||||
[popup_w, popup_h] = popup.get_request()
|
||||
|
||||
left_x = item_x + item_w
|
||||
left_y = item_y
|
||||
right_x = item_x + item_w
|
||||
right_y = item_y
|
||||
top_x = item_x
|
||||
top_y = item_y + item_h
|
||||
bottom_x = item_x
|
||||
bottom_y = item_y - popup_h
|
||||
|
||||
grid_size = units.grid_to_pixels(1)
|
||||
if item_x < grid_size:
|
||||
[x, y] = [left_x, left_y]
|
||||
elif item_x >= (gtk.gdk.screen_width() - grid_size):
|
||||
[x, y] = [right_x, right_y]
|
||||
elif item_y < grid_size:
|
||||
[x, y] = [top_x, top_y]
|
||||
elif item_y >= (gtk.gdk.screen_height() - grid_size):
|
||||
[x, y] = [bottom_x, bottom_y]
|
||||
else:
|
||||
logging.error('Item not in the frame!')
|
||||
return [None, None]
|
||||
|
||||
x = min(x, gtk.gdk.screen_width() - popup_w)
|
||||
x = max(0, x)
|
||||
|
||||
y = min(y, gtk.gdk.screen_height() - popup_h)
|
||||
y = max(0, y)
|
||||
|
||||
return [x, y]
|
||||
|
||||
Reference in New Issue
Block a user