Changed all tabs to 4 spaces for python style
This commit is contained in:
@@ -23,67 +23,67 @@ from sugar.graphics import style
|
||||
from sugar.presence import PresenceService
|
||||
|
||||
class FriendView(hippo.CanvasBox):
|
||||
def __init__(self, shell, menu_shell, buddy, **kwargs):
|
||||
hippo.CanvasBox.__init__(self, **kwargs)
|
||||
def __init__(self, shell, menu_shell, buddy, **kwargs):
|
||||
hippo.CanvasBox.__init__(self, **kwargs)
|
||||
|
||||
self._pservice = PresenceService.get_instance()
|
||||
self._pservice = PresenceService.get_instance()
|
||||
|
||||
self._buddy = buddy
|
||||
self._buddy_icon = BuddyIcon(shell, menu_shell, buddy)
|
||||
style.apply_stylesheet(self._buddy_icon, 'friends.FriendIcon')
|
||||
self.append(self._buddy_icon)
|
||||
self._buddy = buddy
|
||||
self._buddy_icon = BuddyIcon(shell, menu_shell, buddy)
|
||||
style.apply_stylesheet(self._buddy_icon, 'friends.FriendIcon')
|
||||
self.append(self._buddy_icon)
|
||||
|
||||
self._activity_icon = CanvasIcon()
|
||||
style.apply_stylesheet(self._activity_icon, 'friends.ActivityIcon')
|
||||
self._activity_icon_visible = False
|
||||
self._activity_icon = CanvasIcon()
|
||||
style.apply_stylesheet(self._activity_icon, 'friends.ActivityIcon')
|
||||
self._activity_icon_visible = False
|
||||
|
||||
if self._buddy.is_present():
|
||||
self._buddy_appeared_cb(buddy)
|
||||
if self._buddy.is_present():
|
||||
self._buddy_appeared_cb(buddy)
|
||||
|
||||
self._buddy.connect('current-activity-changed', self._buddy_activity_changed_cb)
|
||||
self._buddy.connect('appeared', self._buddy_appeared_cb)
|
||||
self._buddy.connect('disappeared', self._buddy_disappeared_cb)
|
||||
self._buddy.connect('color-changed', self._buddy_color_changed_cb)
|
||||
self._buddy.connect('current-activity-changed', self._buddy_activity_changed_cb)
|
||||
self._buddy.connect('appeared', self._buddy_appeared_cb)
|
||||
self._buddy.connect('disappeared', self._buddy_disappeared_cb)
|
||||
self._buddy.connect('color-changed', self._buddy_color_changed_cb)
|
||||
|
||||
def _get_new_icon_name(self, activity):
|
||||
# FIXME: do something better here; we probably need to use "flagship"
|
||||
# services like mDNS where activities default services are marked
|
||||
# somehow.
|
||||
activity_registry = shell.get_model().get_bundle_registry()
|
||||
for serv in activity.get_services():
|
||||
bundle = activity_registry.get_bundle(serv.get_type())
|
||||
if bundle:
|
||||
return bundle.get_icon()
|
||||
return None
|
||||
def _get_new_icon_name(self, activity):
|
||||
# FIXME: do something better here; we probably need to use "flagship"
|
||||
# services like mDNS where activities default services are marked
|
||||
# somehow.
|
||||
activity_registry = shell.get_model().get_bundle_registry()
|
||||
for serv in activity.get_services():
|
||||
bundle = activity_registry.get_bundle(serv.get_type())
|
||||
if bundle:
|
||||
return bundle.get_icon()
|
||||
return None
|
||||
|
||||
def _remove_activity_icon(self):
|
||||
if self._activity_icon_visible:
|
||||
self.remove(self._activity_icon)
|
||||
self._activity_icon_visible = False
|
||||
def _remove_activity_icon(self):
|
||||
if self._activity_icon_visible:
|
||||
self.remove(self._activity_icon)
|
||||
self._activity_icon_visible = False
|
||||
|
||||
def _buddy_activity_changed_cb(self, buddy, activity=None):
|
||||
if not activity:
|
||||
self._remove_activity_icon()
|
||||
return
|
||||
def _buddy_activity_changed_cb(self, buddy, activity=None):
|
||||
if not activity:
|
||||
self._remove_activity_icon()
|
||||
return
|
||||
|
||||
# FIXME: use some sort of "unknown activity" icon rather
|
||||
# than hiding the icon?
|
||||
name = self._get_new_icon_name(activity)
|
||||
if name:
|
||||
self._activity_icon.props.icon_name = name
|
||||
self._activity_icon.props.color = buddy.get_color()
|
||||
if not self._activity_icon_visible:
|
||||
self.append(self._activity_icon, hippo.PACK_EXPAND)
|
||||
self._activity_icon_visible = True
|
||||
else:
|
||||
self._remove_activity_icon()
|
||||
# FIXME: use some sort of "unknown activity" icon rather
|
||||
# than hiding the icon?
|
||||
name = self._get_new_icon_name(activity)
|
||||
if name:
|
||||
self._activity_icon.props.icon_name = name
|
||||
self._activity_icon.props.color = buddy.get_color()
|
||||
if not self._activity_icon_visible:
|
||||
self.append(self._activity_icon, hippo.PACK_EXPAND)
|
||||
self._activity_icon_visible = True
|
||||
else:
|
||||
self._remove_activity_icon()
|
||||
|
||||
def _buddy_appeared_cb(self, buddy):
|
||||
activity = self._buddy.get_current_activity()
|
||||
self._buddy_activity_changed_cb(buddy, activity)
|
||||
def _buddy_appeared_cb(self, buddy):
|
||||
activity = self._buddy.get_current_activity()
|
||||
self._buddy_activity_changed_cb(buddy, activity)
|
||||
|
||||
def _buddy_disappeared_cb(self, buddy):
|
||||
self._buddy_activity_changed_cb(buddy, None)
|
||||
def _buddy_disappeared_cb(self, buddy):
|
||||
self._buddy_activity_changed_cb(buddy, None)
|
||||
|
||||
def _buddy_color_changed_cb(self, buddy, color):
|
||||
self._activity_icon.props.color = buddy.get_color()
|
||||
def _buddy_color_changed_cb(self, buddy, color):
|
||||
self._activity_icon.props.color = buddy.get_color()
|
||||
|
||||
@@ -25,42 +25,42 @@ from view.home.MyIcon import MyIcon
|
||||
from view.home.FriendView import FriendView
|
||||
|
||||
class FriendsBox(SpreadBox, hippo.CanvasItem):
|
||||
__gtype_name__ = 'SugarFriendsBox'
|
||||
def __init__(self, shell, menu_shell):
|
||||
SpreadBox.__init__(self, background_color=0xe2e2e2ff)
|
||||
__gtype_name__ = 'SugarFriendsBox'
|
||||
def __init__(self, shell, menu_shell):
|
||||
SpreadBox.__init__(self, background_color=0xe2e2e2ff)
|
||||
|
||||
self._shell = shell
|
||||
self._menu_shell = menu_shell
|
||||
self._friends = {}
|
||||
self._shell = shell
|
||||
self._menu_shell = menu_shell
|
||||
self._friends = {}
|
||||
|
||||
self._my_icon = MyIcon()
|
||||
style.apply_stylesheet(self._my_icon, 'friends.MyIcon')
|
||||
self.append(self._my_icon, hippo.PACK_FIXED)
|
||||
self._my_icon = MyIcon()
|
||||
style.apply_stylesheet(self._my_icon, 'friends.MyIcon')
|
||||
self.append(self._my_icon, hippo.PACK_FIXED)
|
||||
|
||||
friends = self._shell.get_model().get_friends()
|
||||
friends = self._shell.get_model().get_friends()
|
||||
|
||||
for friend in friends:
|
||||
self.add_friend(friend)
|
||||
for friend in friends:
|
||||
self.add_friend(friend)
|
||||
|
||||
friends.connect('friend-added', self._friend_added_cb)
|
||||
friends.connect('friend-removed', self._friend_removed_cb)
|
||||
friends.connect('friend-added', self._friend_added_cb)
|
||||
friends.connect('friend-removed', self._friend_removed_cb)
|
||||
|
||||
def add_friend(self, buddy_info):
|
||||
icon = FriendView(self._shell, self._menu_shell, buddy_info)
|
||||
self.add_item(icon)
|
||||
def add_friend(self, buddy_info):
|
||||
icon = FriendView(self._shell, self._menu_shell, buddy_info)
|
||||
self.add_item(icon)
|
||||
|
||||
self._friends[buddy_info.get_name()] = icon
|
||||
self._friends[buddy_info.get_name()] = icon
|
||||
|
||||
def _friend_added_cb(self, data_model, buddy_info):
|
||||
self.add_friend(buddy_info)
|
||||
def _friend_added_cb(self, data_model, buddy_info):
|
||||
self.add_friend(buddy_info)
|
||||
|
||||
def _friend_removed_cb(self, data_model, name):
|
||||
self.remove_item(self._friends[name])
|
||||
del self._friends[name]
|
||||
def _friend_removed_cb(self, data_model, name):
|
||||
self.remove_item(self._friends[name])
|
||||
del self._friends[name]
|
||||
|
||||
def do_allocate(self, width, height):
|
||||
SpreadBox.do_allocate(self, width, height)
|
||||
def do_allocate(self, width, height):
|
||||
SpreadBox.do_allocate(self, width, height)
|
||||
|
||||
[icon_width, icon_height] = self._my_icon.get_allocation()
|
||||
self.move(self._my_icon, (width - icon_width) / 2,
|
||||
(height - icon_height) / 2)
|
||||
[icon_width, icon_height] = self._my_icon.get_allocation()
|
||||
self.move(self._my_icon, (width - icon_width) / 2,
|
||||
(height - icon_height) / 2)
|
||||
|
||||
+16
-16
@@ -22,24 +22,24 @@ from sugar.graphics.grid import Grid
|
||||
from sugar.graphics import style
|
||||
|
||||
class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
|
||||
__gtype_name__ = 'SugarHomeBox'
|
||||
__gtype_name__ = 'SugarHomeBox'
|
||||
|
||||
def __init__(self, shell):
|
||||
hippo.CanvasBox.__init__(self, background_color=0xe2e2e2ff,
|
||||
yalign=2)
|
||||
def __init__(self, shell):
|
||||
hippo.CanvasBox.__init__(self, background_color=0xe2e2e2ff,
|
||||
yalign=2)
|
||||
|
||||
grid = Grid()
|
||||
donut = ActivitiesDonut(shell, box_width=grid.dimension(7),
|
||||
box_height=grid.dimension(7))
|
||||
self.append(donut)
|
||||
grid = Grid()
|
||||
donut = ActivitiesDonut(shell, box_width=grid.dimension(7),
|
||||
box_height=grid.dimension(7))
|
||||
self.append(donut)
|
||||
|
||||
self._my_icon = MyIcon()
|
||||
style.apply_stylesheet(self._my_icon, 'home.MyIcon')
|
||||
self.append(self._my_icon, hippo.PACK_FIXED)
|
||||
self._my_icon = MyIcon()
|
||||
style.apply_stylesheet(self._my_icon, 'home.MyIcon')
|
||||
self.append(self._my_icon, hippo.PACK_FIXED)
|
||||
|
||||
def do_allocate(self, width, height):
|
||||
hippo.CanvasBox.do_allocate(self, width, height)
|
||||
def do_allocate(self, width, height):
|
||||
hippo.CanvasBox.do_allocate(self, width, height)
|
||||
|
||||
[icon_width, icon_height] = self._my_icon.get_allocation()
|
||||
self.move(self._my_icon, (width - icon_width) / 2,
|
||||
(height - icon_height) / 2)
|
||||
[icon_width, icon_height] = self._my_icon.get_allocation()
|
||||
self.move(self._my_icon, (width - icon_width) / 2,
|
||||
(height - icon_height) / 2)
|
||||
|
||||
@@ -25,45 +25,45 @@ from view.home.HomeBox import HomeBox
|
||||
from view.home.FriendsBox import FriendsBox
|
||||
|
||||
class HomeWindow(gtk.Window):
|
||||
def __init__(self, shell):
|
||||
gtk.Window.__init__(self)
|
||||
self._shell = shell
|
||||
def __init__(self, shell):
|
||||
gtk.Window.__init__(self)
|
||||
self._shell = shell
|
||||
|
||||
self.set_default_size(gtk.gdk.screen_width(),
|
||||
gtk.gdk.screen_height())
|
||||
self.set_default_size(gtk.gdk.screen_width(),
|
||||
gtk.gdk.screen_height())
|
||||
|
||||
self.realize()
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
||||
self.realize()
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
||||
|
||||
self._nb = gtk.Notebook()
|
||||
self._nb.set_show_border(False)
|
||||
self._nb.set_show_tabs(False)
|
||||
self._nb = gtk.Notebook()
|
||||
self._nb.set_show_border(False)
|
||||
self._nb.set_show_tabs(False)
|
||||
|
||||
self.add(self._nb)
|
||||
self._nb.show()
|
||||
self.add(self._nb)
|
||||
self._nb.show()
|
||||
|
||||
canvas = hippo.Canvas()
|
||||
box = HomeBox(shell)
|
||||
canvas.set_root(box)
|
||||
self._nb.append_page(canvas)
|
||||
canvas.show()
|
||||
canvas = hippo.Canvas()
|
||||
box = HomeBox(shell)
|
||||
canvas.set_root(box)
|
||||
self._nb.append_page(canvas)
|
||||
canvas.show()
|
||||
|
||||
canvas = hippo.Canvas()
|
||||
box = FriendsBox(shell, MenuShell(canvas))
|
||||
canvas.set_root(box)
|
||||
self._nb.append_page(canvas)
|
||||
canvas.show()
|
||||
canvas = hippo.Canvas()
|
||||
box = FriendsBox(shell, MenuShell(canvas))
|
||||
canvas.set_root(box)
|
||||
self._nb.append_page(canvas)
|
||||
canvas.show()
|
||||
|
||||
canvas = hippo.Canvas()
|
||||
box = MeshBox(shell, MenuShell(canvas))
|
||||
canvas.set_root(box)
|
||||
self._nb.append_page(canvas)
|
||||
canvas.show()
|
||||
canvas = hippo.Canvas()
|
||||
box = MeshBox(shell, MenuShell(canvas))
|
||||
canvas.set_root(box)
|
||||
self._nb.append_page(canvas)
|
||||
canvas.show()
|
||||
|
||||
def set_zoom_level(self, level):
|
||||
if level == sugar.ZOOM_HOME:
|
||||
self._nb.set_current_page(0)
|
||||
elif level == sugar.ZOOM_FRIENDS:
|
||||
self._nb.set_current_page(1)
|
||||
elif level == sugar.ZOOM_MESH:
|
||||
self._nb.set_current_page(2)
|
||||
def set_zoom_level(self, level):
|
||||
if level == sugar.ZOOM_HOME:
|
||||
self._nb.set_current_page(0)
|
||||
elif level == sugar.ZOOM_FRIENDS:
|
||||
self._nb.set_current_page(1)
|
||||
elif level == sugar.ZOOM_MESH:
|
||||
self._nb.set_current_page(2)
|
||||
|
||||
+84
-84
@@ -25,116 +25,116 @@ from sugar.graphics.canvasicon import CanvasIcon
|
||||
from view.BuddyIcon import BuddyIcon
|
||||
|
||||
class ActivityView(SnowflakeBox):
|
||||
def __init__(self, shell, menu_shell, model):
|
||||
SnowflakeBox.__init__(self)
|
||||
def __init__(self, shell, menu_shell, model):
|
||||
SnowflakeBox.__init__(self)
|
||||
|
||||
self._shell = shell
|
||||
self._model = model
|
||||
self._icons = {}
|
||||
self._shell = shell
|
||||
self._model = model
|
||||
self._icons = {}
|
||||
|
||||
icon = CanvasIcon(icon_name=model.get_icon_name(),
|
||||
color=model.get_color(), size=80)
|
||||
icon.connect('activated', self._clicked_cb)
|
||||
self.append(icon, hippo.PACK_FIXED)
|
||||
self.set_root(icon)
|
||||
icon = CanvasIcon(icon_name=model.get_icon_name(),
|
||||
color=model.get_color(), size=80)
|
||||
icon.connect('activated', self._clicked_cb)
|
||||
self.append(icon, hippo.PACK_FIXED)
|
||||
self.set_root(icon)
|
||||
|
||||
def has_buddy_icon(self, name):
|
||||
return self._icons.has_key(name)
|
||||
def has_buddy_icon(self, name):
|
||||
return self._icons.has_key(name)
|
||||
|
||||
def add_buddy_icon(self, name, icon):
|
||||
self._icons[name] = icon
|
||||
self.append(icon, hippo.PACK_FIXED)
|
||||
def add_buddy_icon(self, name, icon):
|
||||
self._icons[name] = icon
|
||||
self.append(icon, hippo.PACK_FIXED)
|
||||
|
||||
def remove_buddy_icon(self, name):
|
||||
icon = self._icons[name]
|
||||
self.remove(icon)
|
||||
del self._icons[name]
|
||||
def remove_buddy_icon(self, name):
|
||||
icon = self._icons[name]
|
||||
self.remove(icon)
|
||||
del self._icons[name]
|
||||
|
||||
def _clicked_cb(self, item):
|
||||
bundle_id = self._model.get_service().get_type()
|
||||
self._shell.join_activity(bundle_id, self._model.get_id())
|
||||
def _clicked_cb(self, item):
|
||||
bundle_id = self._model.get_service().get_type()
|
||||
self._shell.join_activity(bundle_id, self._model.get_id())
|
||||
|
||||
class MeshBox(SpreadBox):
|
||||
def __init__(self, shell, menu_shell):
|
||||
SpreadBox.__init__(self, background_color=0xe2e2e2ff)
|
||||
def __init__(self, shell, menu_shell):
|
||||
SpreadBox.__init__(self, background_color=0xe2e2e2ff)
|
||||
|
||||
self._shell = shell
|
||||
self._menu_shell = menu_shell
|
||||
self._model = shell.get_model().get_mesh()
|
||||
self._buddies = {}
|
||||
self._activities = {}
|
||||
self._buddy_to_activity = {}
|
||||
self._shell = shell
|
||||
self._menu_shell = menu_shell
|
||||
self._model = shell.get_model().get_mesh()
|
||||
self._buddies = {}
|
||||
self._activities = {}
|
||||
self._buddy_to_activity = {}
|
||||
|
||||
for buddy_model in self._model.get_buddies():
|
||||
self._add_alone_buddy(buddy_model)
|
||||
for buddy_model in self._model.get_buddies():
|
||||
self._add_alone_buddy(buddy_model)
|
||||
|
||||
self._model.connect('buddy-added', self._buddy_added_cb)
|
||||
self._model.connect('buddy-removed', self._buddy_removed_cb)
|
||||
self._model.connect('buddy-moved', self._buddy_moved_cb)
|
||||
self._model.connect('buddy-added', self._buddy_added_cb)
|
||||
self._model.connect('buddy-removed', self._buddy_removed_cb)
|
||||
self._model.connect('buddy-moved', self._buddy_moved_cb)
|
||||
|
||||
for activity_model in self._model.get_activities():
|
||||
self._add_activity(activity_model)
|
||||
for activity_model in self._model.get_activities():
|
||||
self._add_activity(activity_model)
|
||||
|
||||
self._model.connect('activity-added', self._activity_added_cb)
|
||||
self._model.connect('activity-removed', self._activity_removed_cb)
|
||||
self._model.connect('activity-added', self._activity_added_cb)
|
||||
self._model.connect('activity-removed', self._activity_removed_cb)
|
||||
|
||||
def _buddy_added_cb(self, model, buddy_model):
|
||||
self._add_alone_buddy(buddy_model)
|
||||
def _buddy_added_cb(self, model, buddy_model):
|
||||
self._add_alone_buddy(buddy_model)
|
||||
|
||||
def _buddy_removed_cb(self, model, buddy_model):
|
||||
self._remove_buddy(buddy_model)
|
||||
def _buddy_removed_cb(self, model, buddy_model):
|
||||
self._remove_buddy(buddy_model)
|
||||
|
||||
def _buddy_moved_cb(self, model, buddy_model, activity_model):
|
||||
self._move_buddy(buddy_model, activity_model)
|
||||
def _buddy_moved_cb(self, model, buddy_model, activity_model):
|
||||
self._move_buddy(buddy_model, activity_model)
|
||||
|
||||
def _activity_added_cb(self, model, activity_model):
|
||||
self._add_activity(activity_model)
|
||||
def _activity_added_cb(self, model, activity_model):
|
||||
self._add_activity(activity_model)
|
||||
|
||||
def _activity_removed_cb(self, model, activity_model):
|
||||
self._remove_activity(activity_model)
|
||||
def _activity_removed_cb(self, model, activity_model):
|
||||
self._remove_activity(activity_model)
|
||||
|
||||
def _add_alone_buddy(self, buddy_model):
|
||||
icon = BuddyIcon(self._shell, self._menu_shell, buddy_model)
|
||||
icon.props.size = 80
|
||||
self.add_item(icon)
|
||||
def _add_alone_buddy(self, buddy_model):
|
||||
icon = BuddyIcon(self._shell, self._menu_shell, buddy_model)
|
||||
icon.props.size = 80
|
||||
self.add_item(icon)
|
||||
|
||||
self._buddies[buddy_model.get_name()] = icon
|
||||
self._buddies[buddy_model.get_name()] = icon
|
||||
|
||||
def _remove_alone_buddy(self, buddy_model):
|
||||
icon = self._buddies[buddy_model.get_name()]
|
||||
self.remove_item(icon)
|
||||
del self._buddies[buddy_model.get_name()]
|
||||
def _remove_alone_buddy(self, buddy_model):
|
||||
icon = self._buddies[buddy_model.get_name()]
|
||||
self.remove_item(icon)
|
||||
del self._buddies[buddy_model.get_name()]
|
||||
|
||||
def _remove_buddy(self, buddy_model):
|
||||
name = buddy_model.get_name()
|
||||
if self._buddies.has_key(name):
|
||||
self._remove_alone_buddy(buddy_model)
|
||||
else:
|
||||
for activity in self._activities.values():
|
||||
if activity.has_buddy_icon(name):
|
||||
activity.remove_buddy_icon(name)
|
||||
def _remove_buddy(self, buddy_model):
|
||||
name = buddy_model.get_name()
|
||||
if self._buddies.has_key(name):
|
||||
self._remove_alone_buddy(buddy_model)
|
||||
else:
|
||||
for activity in self._activities.values():
|
||||
if activity.has_buddy_icon(name):
|
||||
activity.remove_buddy_icon(name)
|
||||
|
||||
def _move_buddy(self, buddy_model, activity_model):
|
||||
name = buddy_model.get_name()
|
||||
def _move_buddy(self, buddy_model, activity_model):
|
||||
name = buddy_model.get_name()
|
||||
|
||||
self._remove_buddy(buddy_model)
|
||||
self._remove_buddy(buddy_model)
|
||||
|
||||
if activity_model == None:
|
||||
self._add_alone_buddy(buddy_model)
|
||||
else:
|
||||
activity = self._activities[activity_model.get_id()]
|
||||
if activity_model == None:
|
||||
self._add_alone_buddy(buddy_model)
|
||||
else:
|
||||
activity = self._activities[activity_model.get_id()]
|
||||
|
||||
icon = BuddyIcon(self._shell, self._menu_shell, buddy_model)
|
||||
icon.props.size = 60
|
||||
activity.add_buddy_icon(buddy_model.get_name(), icon)
|
||||
icon = BuddyIcon(self._shell, self._menu_shell, buddy_model)
|
||||
icon.props.size = 60
|
||||
activity.add_buddy_icon(buddy_model.get_name(), icon)
|
||||
|
||||
def _add_activity(self, activity_model):
|
||||
icon = ActivityView(self._shell, self._menu_shell, activity_model)
|
||||
self.add_item(icon)
|
||||
def _add_activity(self, activity_model):
|
||||
icon = ActivityView(self._shell, self._menu_shell, activity_model)
|
||||
self.add_item(icon)
|
||||
|
||||
self._activities[activity_model.get_id()] = icon
|
||||
self._activities[activity_model.get_id()] = icon
|
||||
|
||||
def _remove_activity(self, activity_model):
|
||||
icon = self._activities[activity_model.get_id()]
|
||||
self.remove_item(icon)
|
||||
del self._activities[activity_model.get_id()]
|
||||
def _remove_activity(self, activity_model):
|
||||
icon = self._activities[activity_model.get_id()]
|
||||
self.remove_item(icon)
|
||||
del self._activities[activity_model.get_id()]
|
||||
|
||||
@@ -18,6 +18,6 @@ from sugar.graphics.canvasicon import CanvasIcon
|
||||
from sugar import profile
|
||||
|
||||
class MyIcon(CanvasIcon):
|
||||
def __init__(self):
|
||||
CanvasIcon.__init__(self, icon_name='stock-buddy',
|
||||
color=profile.get_color())
|
||||
def __init__(self):
|
||||
CanvasIcon.__init__(self, icon_name='stock-buddy',
|
||||
color=profile.get_color())
|
||||
|
||||
@@ -21,100 +21,100 @@ from sugar.graphics.canvasicon import CanvasIcon
|
||||
from sugar.graphics import style
|
||||
|
||||
class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
|
||||
__gtype_name__ = 'SugarActivitiesDonut'
|
||||
def __init__(self, shell, **kwargs):
|
||||
hippo.CanvasBox.__init__(self, **kwargs)
|
||||
__gtype_name__ = 'SugarActivitiesDonut'
|
||||
def __init__(self, shell, **kwargs):
|
||||
hippo.CanvasBox.__init__(self, **kwargs)
|
||||
|
||||
self._activities = {}
|
||||
self._activities = {}
|
||||
|
||||
shell.connect('activity_opened', self.__activity_opened_cb)
|
||||
shell.connect('activity_closed', self.__activity_closed_cb)
|
||||
shell.connect('activity_opened', self.__activity_opened_cb)
|
||||
shell.connect('activity_closed', self.__activity_closed_cb)
|
||||
|
||||
def __activity_opened_cb(self, model, activity):
|
||||
self._add_activity(activity)
|
||||
def __activity_opened_cb(self, model, activity):
|
||||
self._add_activity(activity)
|
||||
|
||||
def __activity_closed_cb(self, model, activity):
|
||||
self._remove_activity(activity)
|
||||
|
||||
def _remove_activity(self, activity):
|
||||
icon = self._activities[activity.get_id()]
|
||||
self.remove(icon)
|
||||
del self._activities[activity.get_id()]
|
||||
def __activity_closed_cb(self, model, activity):
|
||||
self._remove_activity(activity)
|
||||
|
||||
def _remove_activity(self, activity):
|
||||
icon = self._activities[activity.get_id()]
|
||||
self.remove(icon)
|
||||
del self._activities[activity.get_id()]
|
||||
|
||||
def _add_activity(self, activity):
|
||||
icon_name = activity.get_icon_name()
|
||||
icon_color = activity.get_icon_color()
|
||||
def _add_activity(self, activity):
|
||||
icon_name = activity.get_icon_name()
|
||||
icon_color = activity.get_icon_color()
|
||||
|
||||
icon = CanvasIcon(icon_name=icon_name, color=icon_color)
|
||||
style.apply_stylesheet(icon, 'ring.ActivityIcon')
|
||||
icon.connect('activated', self.__activity_icon_clicked_cb, activity)
|
||||
self.append(icon, hippo.PACK_FIXED)
|
||||
icon = CanvasIcon(icon_name=icon_name, color=icon_color)
|
||||
style.apply_stylesheet(icon, 'ring.ActivityIcon')
|
||||
icon.connect('activated', self.__activity_icon_clicked_cb, activity)
|
||||
self.append(icon, hippo.PACK_FIXED)
|
||||
|
||||
self._activities[activity.get_id()] = icon
|
||||
self._activities[activity.get_id()] = icon
|
||||
|
||||
self.emit_paint_needed(0, 0, -1, -1)
|
||||
self.emit_paint_needed(0, 0, -1, -1)
|
||||
|
||||
def __activity_icon_clicked_cb(self, item, activity):
|
||||
activity.present()
|
||||
def __activity_icon_clicked_cb(self, item, activity):
|
||||
activity.present()
|
||||
|
||||
def _get_angles(self, index):
|
||||
angle = 2 * math.pi / 8
|
||||
return [index * angle, (index + 1) * angle]
|
||||
def _get_angles(self, index):
|
||||
angle = 2 * math.pi / 8
|
||||
return [index * angle, (index + 1) * angle]
|
||||
|
||||
def _get_radius(self):
|
||||
[width, height] = self.get_allocation()
|
||||
return min(width, height) / 2
|
||||
def _get_radius(self):
|
||||
[width, height] = self.get_allocation()
|
||||
return min(width, height) / 2
|
||||
|
||||
def _get_inner_radius(self):
|
||||
return self._get_radius() * 0.5
|
||||
def _get_inner_radius(self):
|
||||
return self._get_radius() * 0.5
|
||||
|
||||
def do_paint_below_children(self, cr, damaged_box):
|
||||
[width, height] = self.get_allocation()
|
||||
def do_paint_below_children(self, cr, damaged_box):
|
||||
[width, height] = self.get_allocation()
|
||||
|
||||
cr.translate(width / 2, height / 2)
|
||||
cr.translate(width / 2, height / 2)
|
||||
|
||||
radius = self._get_radius()
|
||||
radius = self._get_radius()
|
||||
|
||||
cr.set_source_rgb(0xf1 / 255.0, 0xf1 / 255.0, 0xf1 / 255.0)
|
||||
cr.arc(0, 0, radius, 0, 2 * math.pi)
|
||||
cr.fill()
|
||||
cr.set_source_rgb(0xf1 / 255.0, 0xf1 / 255.0, 0xf1 / 255.0)
|
||||
cr.arc(0, 0, radius, 0, 2 * math.pi)
|
||||
cr.fill()
|
||||
|
||||
angle_end = 0
|
||||
for i in range(0, len(self._activities)):
|
||||
[angle_start, angle_end] = self._get_angles(i)
|
||||
angle_end = 0
|
||||
for i in range(0, len(self._activities)):
|
||||
[angle_start, angle_end] = self._get_angles(i)
|
||||
|
||||
cr.new_path()
|
||||
cr.move_to(0, 0)
|
||||
cr.line_to(radius * math.cos(angle_start),
|
||||
radius * math.sin(angle_start))
|
||||
cr.arc(0, 0, radius, angle_start, angle_end)
|
||||
cr.line_to(0, 0)
|
||||
cr.new_path()
|
||||
cr.move_to(0, 0)
|
||||
cr.line_to(radius * math.cos(angle_start),
|
||||
radius * math.sin(angle_start))
|
||||
cr.arc(0, 0, radius, angle_start, angle_end)
|
||||
cr.line_to(0, 0)
|
||||
|
||||
cr.set_source_rgb(0xe2 / 255.0, 0xe2 / 255.0, 0xe2 / 255.0)
|
||||
cr.set_line_width(4)
|
||||
cr.stroke_preserve()
|
||||
cr.set_source_rgb(0xe2 / 255.0, 0xe2 / 255.0, 0xe2 / 255.0)
|
||||
cr.set_line_width(4)
|
||||
cr.stroke_preserve()
|
||||
|
||||
cr.set_source_rgb(1, 1, 1)
|
||||
cr.fill()
|
||||
cr.set_source_rgb(1, 1, 1)
|
||||
cr.fill()
|
||||
|
||||
cr.set_source_rgb(0xe2 / 255.0, 0xe2 / 255.0, 0xe2 / 255.0)
|
||||
cr.arc(0, 0, self._get_inner_radius(), 0, 2 * math.pi)
|
||||
cr.fill()
|
||||
cr.set_source_rgb(0xe2 / 255.0, 0xe2 / 255.0, 0xe2 / 255.0)
|
||||
cr.arc(0, 0, self._get_inner_radius(), 0, 2 * math.pi)
|
||||
cr.fill()
|
||||
|
||||
def do_allocate(self, width, height):
|
||||
hippo.CanvasBox.do_allocate(self, width, height)
|
||||
def do_allocate(self, width, height):
|
||||
hippo.CanvasBox.do_allocate(self, width, height)
|
||||
|
||||
radius = (self._get_inner_radius() + self._get_radius()) / 2
|
||||
radius = (self._get_inner_radius() + self._get_radius()) / 2
|
||||
|
||||
i = 0
|
||||
for icon in self._activities.values():
|
||||
[angle_start, angle_end] = self._get_angles(i)
|
||||
angle = angle_start + (angle_end - angle_start) / 2
|
||||
i = 0
|
||||
for icon in self._activities.values():
|
||||
[angle_start, angle_end] = self._get_angles(i)
|
||||
angle = angle_start + (angle_end - angle_start) / 2
|
||||
|
||||
[icon_width, icon_height] = icon.get_allocation()
|
||||
[icon_width, icon_height] = icon.get_allocation()
|
||||
|
||||
x = int(radius * math.cos(angle)) - icon_width / 2
|
||||
y = int(radius * math.sin(angle)) - icon_height / 2
|
||||
self.move(icon, x + width / 2, y + height / 2)
|
||||
x = int(radius * math.cos(angle)) - icon_width / 2
|
||||
y = int(radius * math.sin(angle)) - icon_height / 2
|
||||
self.move(icon, x + width / 2, y + height / 2)
|
||||
|
||||
i += 1
|
||||
i += 1
|
||||
|
||||
Reference in New Issue
Block a user