Some work on the donut...

This commit is contained in:
Marco Pesenti Gritti 2006-08-17 11:47:41 +02:00
parent 7990bc0d31
commit e5ed8275a1
2 changed files with 62 additions and 0 deletions

View File

@ -2,6 +2,15 @@ import gtk
import goocanvas import goocanvas
from sugar.canvas.IconItem import IconItem from sugar.canvas.IconItem import IconItem
from sugar.canvas.DonutItem import DonutItem
class TasksItem(DonutItem):
def __init__(self):
DonutItem.__init__(self, 200)
self.add_piece(30)
self.add_piece(30)
self.add_piece(30)
self.add_piece(10)
class ActivityItem(IconItem): class ActivityItem(IconItem):
def __init__(self, activity): def __init__(self, activity):
@ -57,6 +66,10 @@ class Model(goocanvas.CanvasModelSimple):
activity_bar.translate(50, 860) activity_bar.translate(50, 860)
root.add_child(activity_bar) root.add_child(activity_bar)
tasks = TasksItem()
tasks.translate(600, 450)
root.add_child(tasks)
class HomeWindow(gtk.Window): class HomeWindow(gtk.Window):
def __init__(self, shell): def __init__(self, shell):
gtk.Window.__init__(self) gtk.Window.__init__(self)

49
sugar/canvas/DonutItem.py Normal file
View File

@ -0,0 +1,49 @@
import math
import goocanvas
class PieceItem(goocanvas.Path):
def __init__(self, angle_start, angle_end, **kwargs):
goocanvas.Path.__init__(self, **kwargs)
self._angle_start = angle_start
self._angle_end = angle_end
def construct(self):
r = self.get_parent().get_radius()
data = 'M0,0 '
dx = r * math.cos(self._angle_start)
dy = - r * math.sin(self._angle_start)
data += 'l%f,%f ' % (dx, dy)
dx = r * math.cos(self._angle_end)
dy = - r * math.sin(self._angle_end)
data += 'A%f,%f 0 0,0 %f,%f ' % (r, r, dx, dy)
data += 'z'
print data
self.set_property('data', data)
class DonutItem(goocanvas.Group):
def __init__(self, radius, **kwargs):
goocanvas.Group.__init__(self, **kwargs)
self._radius = radius
self._angle_start = 0
def add_piece(self, perc):
angle_end = self._angle_start + perc * 2 * math.pi / 100
piece_item = PieceItem(self._angle_start, angle_end)
self._angle_start = angle_end
# FIXME can't override set_parent on the
# PieceItem and there is no signal.
self.add_child(piece_item)
piece_item.construct()
def get_radius(self):
return self._radius