Handle activity closed by removing his piece from the donut.

This commit is contained in:
Marco Pesenti Gritti 2006-08-17 14:42:29 +02:00
parent f65d23c440
commit 640fff5619
2 changed files with 22 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import wnck
from sugar.canvas.IconItem import IconItem from sugar.canvas.IconItem import IconItem
from sugar.canvas.DonutItem import DonutItem from sugar.canvas.DonutItem import DonutItem
from sugar.canvas.DonutItem import PieceItem from sugar.canvas.DonutItem import PieceItem
from sugar.canvas.DonutItem import PieceIcon
class TasksItem(DonutItem): class TasksItem(DonutItem):
def __init__(self, shell): def __init__(self, shell):
@ -23,13 +24,17 @@ class TasksItem(DonutItem):
def _remove(self, activity): def _remove(self, activity):
item = self._items[activity.get_id()] item = self._items[activity.get_id()]
self.remove_child(item) self.remove_piece(item)
del self._items[activity.get_id()] del self._items[activity.get_id()]
def _add(self, activity): def _add(self, activity):
icon_name = activity.get_icon_name() icon_name = activity.get_icon_name()
item = self.add_piece(100 / 8, icon_name, 'blue') item = self.add_piece(100 / 8, icon_name, 'blue')
# FIXME This really sucks. Fix goocanvas event handling.
item.set_data('activity', activity) item.set_data('activity', activity)
item.get_icon().set_data('activity', activity)
self._items[activity.get_id()] = item self._items[activity.get_id()] = item
class ActivityItem(IconItem): class ActivityItem(IconItem):
@ -117,7 +122,8 @@ class HomeWindow(gtk.Window):
item_view.connect("button_press_event", item_view.connect("button_press_event",
self.__activity_button_press_cb, self.__activity_button_press_cb,
item.get_activity_id()) item.get_activity_id())
elif isinstance(item, PieceItem): elif isinstance(item, PieceItem) or \
isinstance(item, PieceIcon):
item_view.connect("button_press_event", item_view.connect("button_press_event",
self.__task_button_press_cb) self.__task_button_press_cb)

View File

@ -35,6 +35,14 @@ class PieceItem(goocanvas.Path):
self.set_property('stroke-color', '#d8d8d8') self.set_property('stroke-color', '#d8d8d8')
self.set_property('line-width', 4) self.set_property('line-width', 4)
def get_icon(self):
return self._icon
def set_icon(self, icon_name, color):
self._icon = PieceIcon(self, icon_name, color)
self.get_parent().add_child(self._icon)
self._icon.construct()
def get_angle_start(self): def get_angle_start(self):
return self._angle_start return self._angle_start
@ -87,15 +95,16 @@ class DonutItem(goocanvas.Group):
self.add_child(piece_item, 1) self.add_child(piece_item, 1)
piece_item.construct() piece_item.construct()
piece_item.set_icon(icon_name, color)
icon = PieceIcon(piece_item, icon_name, color)
self.add_child(icon)
icon.construct()
return piece_item return piece_item
def remove_piece(self, piece_item): def remove_piece(self, piece_item):
index = self.find(piece_item) index = self.find_child(piece_item)
self.remove_child(index)
icon = piece_item.get_icon()
index = self.find_child(icon)
self.remove_child(index) self.remove_child(index)
def get_radius(self): def get_radius(self):