Some work on the donut...
This commit is contained in:
parent
7990bc0d31
commit
e5ed8275a1
@ -2,6 +2,15 @@ import gtk
|
||||
import goocanvas
|
||||
|
||||
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):
|
||||
def __init__(self, activity):
|
||||
@ -57,6 +66,10 @@ class Model(goocanvas.CanvasModelSimple):
|
||||
activity_bar.translate(50, 860)
|
||||
root.add_child(activity_bar)
|
||||
|
||||
tasks = TasksItem()
|
||||
tasks.translate(600, 450)
|
||||
root.add_child(tasks)
|
||||
|
||||
class HomeWindow(gtk.Window):
|
||||
def __init__(self, shell):
|
||||
gtk.Window.__init__(self)
|
||||
|
49
sugar/canvas/DonutItem.py
Normal file
49
sugar/canvas/DonutItem.py
Normal 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
|
Loading…
Reference in New Issue
Block a user