Added Rollover control.
This commit is contained in:
@@ -21,6 +21,7 @@ import wnck
|
||||
|
||||
from view.home.HomeWindow import HomeWindow
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.graphics.rollovercontext import RolloverContext
|
||||
from view.ActivityHost import ActivityHost
|
||||
from sugar.activity import ActivityFactory
|
||||
from view.frame.frame import Frame
|
||||
@@ -54,6 +55,8 @@ class Shell(gobject.GObject):
|
||||
home_model.connect('active-activity-changed',
|
||||
self._active_activity_changed_cb)
|
||||
|
||||
self._rollover_context = RolloverContext()
|
||||
|
||||
self._frame = Frame(self)
|
||||
self._frame.show_and_hide(3)
|
||||
|
||||
@@ -99,6 +102,9 @@ class Shell(gobject.GObject):
|
||||
def get_frame(self):
|
||||
return self._frame
|
||||
|
||||
def get_rollover_context(self):
|
||||
return self._rollover_context
|
||||
|
||||
def _join_success_cb(self, handler, activity, activity_ps, activity_id, activity_type):
|
||||
logging.debug("Joining activity %s (%s)" % (activity_id, activity_type))
|
||||
activity.join(activity_ps.object_path())
|
||||
|
||||
@@ -19,24 +19,16 @@ import logging
|
||||
|
||||
from sugar.graphics import units
|
||||
from sugar.graphics.iconcolor import IconColor
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
from sugar.graphics.button import Button
|
||||
from sugar.presence import PresenceService
|
||||
from sugar import profile
|
||||
|
||||
class ActivityItem(CanvasIcon):
|
||||
class ActivityButton(Button):
|
||||
def __init__(self, activity):
|
||||
icon_name = activity.get_icon()
|
||||
CanvasIcon.__init__(self, icon_name=icon_name,
|
||||
box_width=units.grid_to_pixels(1),
|
||||
box_height=units.grid_to_pixels(1),
|
||||
color=IconColor('white'))
|
||||
Button.__init__(self, icon_name=activity.get_icon())
|
||||
|
||||
self._activity = activity
|
||||
self._normal_color = self.get_property('color')
|
||||
self._prelight_color = profile.get_color()
|
||||
|
||||
self.connect('motion-notify-event', self._mouse_motion_event_cb)
|
||||
|
||||
def _mouse_motion_event_cb(self, item, event):
|
||||
if event.detail == hippo.MOTION_DETAIL_ENTER:
|
||||
self.set_property('color', self._prelight_color)
|
||||
@@ -46,14 +38,11 @@ class ActivityItem(CanvasIcon):
|
||||
def get_bundle_id(self):
|
||||
return self._activity.get_service_name()
|
||||
|
||||
class InviteItem(CanvasIcon):
|
||||
class InviteButton(Button):
|
||||
def __init__(self, activity, invite):
|
||||
CanvasIcon.__init__(self, icon_name=activity.get_icon(),
|
||||
box_width=units.grid_to_pixels(1),
|
||||
box_height=units.grid_to_pixels(1))
|
||||
Button.__init__(self, icon_name=activity.get_icon())
|
||||
|
||||
self.props.color = activity.get_color()
|
||||
|
||||
self._invite = invite
|
||||
|
||||
def get_activity_id(self):
|
||||
@@ -104,7 +93,7 @@ class ActivitiesBox(hippo.CanvasBox):
|
||||
self.add_activity(bundle)
|
||||
|
||||
def add_activity(self, activity):
|
||||
item = ActivityItem(activity)
|
||||
item = ActivityButton(activity)
|
||||
item.connect('activated', self._activity_clicked_cb)
|
||||
self.append(item, 0)
|
||||
|
||||
@@ -112,7 +101,7 @@ class ActivitiesBox(hippo.CanvasBox):
|
||||
mesh = self._shell_model.get_mesh()
|
||||
activity = mesh.get_activity(invite.get_activity_id())
|
||||
if activity:
|
||||
item = InviteItem(activity, invite)
|
||||
item = InviteButton(activity, invite)
|
||||
item.connect('activated', self._invite_clicked_cb)
|
||||
self.append(item, 0)
|
||||
|
||||
|
||||
+26
-29
@@ -15,65 +15,62 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import logging
|
||||
from gettext import gettext as _
|
||||
|
||||
import hippo
|
||||
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
from sugar.graphics.rollover import Rollover
|
||||
from sugar.graphics.menuicon import MenuIcon
|
||||
from sugar.graphics.menu import Menu
|
||||
from sugar.graphics.iconcolor import IconColor
|
||||
from sugar.graphics.button import Button
|
||||
import sugar
|
||||
|
||||
class ActivityMenu(Menu):
|
||||
class ActivityRollover(Rollover):
|
||||
ACTION_SHARE = 1
|
||||
ACTION_CLOSE = 2
|
||||
|
||||
def __init__(self, activity_model):
|
||||
Menu.__init__(self, activity_model.get_title())
|
||||
Rollover.__init__(self, activity_model.get_title())
|
||||
|
||||
if not activity_model.get_shared():
|
||||
self._add_mesh_action()
|
||||
self.add_item(ActivityRollover.ACTION_SHARE, _('Share'),
|
||||
'theme:stock-share-mesh')
|
||||
|
||||
self._add_close_action()
|
||||
self.add_item(ActivityRollover.ACTION_CLOSE, _('Close'),
|
||||
'theme:stock-close')
|
||||
|
||||
def _add_mesh_action(self):
|
||||
icon = CanvasIcon(icon_name='theme:stock-share-mesh',
|
||||
color=IconColor('#ffffff,#000000'))
|
||||
self.add_action(icon, ActivityMenu.ACTION_SHARE)
|
||||
|
||||
def _add_close_action(self):
|
||||
icon = CanvasIcon(icon_name='theme:stock-close',
|
||||
color=IconColor('#ffffff,#000000'))
|
||||
self.add_action(icon, ActivityMenu.ACTION_CLOSE)
|
||||
|
||||
class ActivityIcon(MenuIcon):
|
||||
def __init__(self, shell, menu_shell, activity_model):
|
||||
class ActivityButton(Button):
|
||||
def __init__(self, shell, activity_model):
|
||||
self._shell = shell
|
||||
self._activity_model = activity_model
|
||||
|
||||
icon_name = self._activity_model.get_icon_name()
|
||||
icon_color = self._activity_model.get_icon_color()
|
||||
|
||||
MenuIcon.__init__(self, menu_shell, icon_name=icon_name,
|
||||
color=icon_color)
|
||||
Button.__init__(self, icon_name=icon_name, color=icon_color)
|
||||
|
||||
def create_menu(self):
|
||||
menu = ActivityMenu(self._activity_model)
|
||||
menu.connect('action', self._action_cb)
|
||||
return menu
|
||||
|
||||
def _action_cb(self, menu, action):
|
||||
self.popdown()
|
||||
def get_rollover(self):
|
||||
rollover = ActivityRollover(self._activity_model)
|
||||
#rollover.connect('action', self._action_cb)
|
||||
return rollover
|
||||
|
||||
def get_rollover_context(self):
|
||||
return self._shell.get_rollover_context()
|
||||
|
||||
def _action_cb(self, menu, data):
|
||||
[action_id, label] = data
|
||||
|
||||
# TODO: Wouldn't be better to share/close the activity associated with
|
||||
# this button instead of asking for the current activity?
|
||||
activity = self._shell.get_current_activity()
|
||||
if activity == None:
|
||||
logging.error('No active activity.')
|
||||
return
|
||||
|
||||
if action == ActivityMenu.ACTION_SHARE:
|
||||
if action_id == ActivityRollover.ACTION_SHARE:
|
||||
activity.share()
|
||||
if action == ActivityMenu.ACTION_CLOSE:
|
||||
elif action_id == ActivityRollover.ACTION_CLOSE:
|
||||
activity.close()
|
||||
|
||||
class ZoomBox(hippo.CanvasBox):
|
||||
@@ -110,7 +107,7 @@ class ZoomBox(hippo.CanvasBox):
|
||||
self.remove(self._activity_icon)
|
||||
|
||||
if home_activity:
|
||||
icon = ActivityIcon(self._shell, self._menu_shell, home_activity)
|
||||
icon = ActivityButton(self._shell, home_activity)
|
||||
self.append(icon)
|
||||
self._activity_icon = icon
|
||||
else:
|
||||
|
||||
@@ -70,6 +70,12 @@ class Frame:
|
||||
shell.get_model().connect('notify::state',
|
||||
self._shell_state_changed_cb)
|
||||
|
||||
rollover_context = shell.get_rollover_context()
|
||||
rollover_context.connect('activated',
|
||||
self._rollover_context_activated_cb)
|
||||
rollover_context.connect('deactivated',
|
||||
self._rollover_context_deactivated_cb)
|
||||
|
||||
def _create_top_panel(self):
|
||||
panel = self._create_panel(hippo.ORIENTATION_HORIZONTAL)
|
||||
menu_shell = panel.get_menu_shell()
|
||||
@@ -165,6 +171,13 @@ class Frame:
|
||||
if self._mode != Frame.STICKY and not self._hover_frame:
|
||||
self._timeline.play('before_slide_out', 'slide_out')
|
||||
|
||||
def _rollover_context_activated_cb(self, rollover_context):
|
||||
self._timeline.goto('slide_in', True)
|
||||
|
||||
def _rollover_context_deactivated_cb(self, rollover_context):
|
||||
if self._mode != Frame.STICKY and not self._hover_frame:
|
||||
self._timeline.play('before_slide_out', 'slide_out')
|
||||
|
||||
def _enter_notify_cb(self, window, event):
|
||||
self._enter_notify()
|
||||
logging.debug('Frame._enter_notify_cb ' + str(self._mode))
|
||||
@@ -193,6 +206,7 @@ class Frame:
|
||||
def _leave_notify(self, panel):
|
||||
self._hover_frame = False
|
||||
if not panel.get_menu_shell().is_active() and \
|
||||
not self._shell.get_rollover_context().is_active() and \
|
||||
(self._mode == Frame.HIDE_ON_LEAVE or \
|
||||
self._mode == Frame.AUTOMATIC):
|
||||
self._timeline.play('before_slide_out', 'slide_out')
|
||||
|
||||
Reference in New Issue
Block a user