Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/graphics
diff options
context:
space:
mode:
authorJustin Gallardo <jirwin@suzy.(none)>2006-12-04 19:12:24 (GMT)
committer Justin Gallardo <jirwin@suzy.(none)>2006-12-04 19:12:24 (GMT)
commitb9f9ef0fe9e36cf6e5de59700154b16f2dae15cd (patch)
tree3d5403ec73e993a78c5e92f8b14a5b86e8b6ae60 /sugar/graphics
parentf5ae0662482de14f9d3812ddc4aba9be61024887 (diff)
Changed all tabs to 4 spaces for python style
Diffstat (limited to 'sugar/graphics')
-rw-r--r--sugar/graphics/ClipboardBubble.py210
-rw-r--r--sugar/graphics/bubble.py84
-rw-r--r--sugar/graphics/canvasicon.py240
-rw-r--r--sugar/graphics/grid.py24
-rw-r--r--sugar/graphics/iconcolor.py40
-rw-r--r--sugar/graphics/menu.py124
-rw-r--r--sugar/graphics/menuicon.py82
-rw-r--r--sugar/graphics/menushell.py160
-rw-r--r--sugar/graphics/snowflakebox.py100
-rw-r--r--sugar/graphics/spreadbox.py152
-rw-r--r--sugar/graphics/style.py24
-rw-r--r--sugar/graphics/stylesheet.py24
-rw-r--r--sugar/graphics/timeline.py182
13 files changed, 723 insertions, 723 deletions
diff --git a/sugar/graphics/ClipboardBubble.py b/sugar/graphics/ClipboardBubble.py
index b94fc26..1947fd5 100644
--- a/sugar/graphics/ClipboardBubble.py
+++ b/sugar/graphics/ClipboardBubble.py
@@ -24,108 +24,108 @@ import gtk
import hippo
class ClipboardBubble(hippo.CanvasBox, hippo.CanvasItem):
- __gtype_name__ = 'ClipboardBubble'
-
- __gproperties__ = {
- 'fill-color': (object, None, None,
- gobject.PARAM_READWRITE),
- 'stroke-color': (object, None, None,
- gobject.PARAM_READWRITE),
- 'progress-color': (object, None, None,
- gobject.PARAM_READWRITE),
- 'percent' : (object, None, None,
- gobject.PARAM_READWRITE),
- }
-
- def __init__(self, **kwargs):
- self._stroke_color = 0xFFFFFFFF
- self._fill_color = 0xFFFFFFFF
- self._progress_color = 0x000000FF
- self._percent = 0
- self._radius = 8
-
- hippo.CanvasBox.__init__(self, **kwargs)
-
- def do_set_property(self, pspec, value):
- if pspec.name == 'fill-color':
- self._fill_color = value
- self.emit_paint_needed(0, 0, -1, -1)
- elif pspec.name == 'stroke-color':
- self._stroke_color = value
- self.emit_paint_needed(0, 0, -1, -1)
- elif pspec.name == 'progress-color':
- self._progress_color = value
- self.emit_paint_needed(0, 0, -1, -1)
- elif pspec.name == 'percent':
- self._percent = value
- self.emit_paint_needed(0, 0, -1, -1)
-
- def do_get_property(self, pspec):
- if pspec.name == 'fill-color':
- return self._fill_color
- elif pspec.name == 'stroke-color':
- return self._stroke_color
- elif pspec.name == 'progress-color':
- return self._progress_color
- elif pspec.name == 'percent':
- return self._percent
-
- def _int_to_rgb(self, int_color):
- red = (int_color >> 24) & 0x000000FF
- green = (int_color >> 16) & 0x000000FF
- blue = (int_color >> 8) & 0x000000FF
- alpha = int_color & 0x000000FF
- return (red / 255.0, green / 255.0, blue / 255.0)
-
- def do_paint_below_children(self, cr, damaged_box):
- [width, height] = self.get_allocation()
-
- line_width = 3.0
- x = line_width
- y = line_width
- width -= line_width * 2
- height -= line_width * 2
-
- self._paint_ellipse(cr, x, y, width, height, self._fill_color)
-
- color = self._int_to_rgb(self._stroke_color)
- cr.set_source_rgb(*color)
- cr.set_line_width(line_width)
- cr.stroke();
-
- self._paint_progress_bar(cr, x, y, width, height, line_width)
-
- def _paint_progress_bar(self, cr, x, y, width, height, line_width):
- prog_x = x + line_width
- prog_y = y + line_width
- prog_width = (width - (line_width * 2)) * (self._percent / 100.0)
- prog_height = (height - (line_width * 2))
-
- self._paint_ellipse(cr, prog_x, prog_y, width, height, self._progress_color)
-
- def _paint_ellipse(self, cr, x, y, width, height, fill_color):
- cr.move_to(x + self._radius, y)
- cr.arc(x + width - self._radius,
- y + self._radius,
- self._radius,
- math.pi * 1.5,
- math.pi * 2)
- cr.arc(x + width - self._radius,
- x + height - self._radius,
- self._radius,
- 0,
- math.pi * 0.5)
- cr.arc(x + self._radius,
- y + height - self._radius,
- self._radius,
- math.pi * 0.5,
- math.pi)
- cr.arc(x + self._radius,
- y + self._radius,
- self._radius,
- math.pi,
- math.pi * 1.5);
-
- color = self._int_to_rgb(fill_color)
- cr.set_source_rgb(*color)
- cr.fill_preserve();
+ __gtype_name__ = 'ClipboardBubble'
+
+ __gproperties__ = {
+ 'fill-color': (object, None, None,
+ gobject.PARAM_READWRITE),
+ 'stroke-color': (object, None, None,
+ gobject.PARAM_READWRITE),
+ 'progress-color': (object, None, None,
+ gobject.PARAM_READWRITE),
+ 'percent' : (object, None, None,
+ gobject.PARAM_READWRITE),
+ }
+
+ def __init__(self, **kwargs):
+ self._stroke_color = 0xFFFFFFFF
+ self._fill_color = 0xFFFFFFFF
+ self._progress_color = 0x000000FF
+ self._percent = 0
+ self._radius = 8
+
+ hippo.CanvasBox.__init__(self, **kwargs)
+
+ def do_set_property(self, pspec, value):
+ if pspec.name == 'fill-color':
+ self._fill_color = value
+ self.emit_paint_needed(0, 0, -1, -1)
+ elif pspec.name == 'stroke-color':
+ self._stroke_color = value
+ self.emit_paint_needed(0, 0, -1, -1)
+ elif pspec.name == 'progress-color':
+ self._progress_color = value
+ self.emit_paint_needed(0, 0, -1, -1)
+ elif pspec.name == 'percent':
+ self._percent = value
+ self.emit_paint_needed(0, 0, -1, -1)
+
+ def do_get_property(self, pspec):
+ if pspec.name == 'fill-color':
+ return self._fill_color
+ elif pspec.name == 'stroke-color':
+ return self._stroke_color
+ elif pspec.name == 'progress-color':
+ return self._progress_color
+ elif pspec.name == 'percent':
+ return self._percent
+
+ def _int_to_rgb(self, int_color):
+ red = (int_color >> 24) & 0x000000FF
+ green = (int_color >> 16) & 0x000000FF
+ blue = (int_color >> 8) & 0x000000FF
+ alpha = int_color & 0x000000FF
+ return (red / 255.0, green / 255.0, blue / 255.0)
+
+ def do_paint_below_children(self, cr, damaged_box):
+ [width, height] = self.get_allocation()
+
+ line_width = 3.0
+ x = line_width
+ y = line_width
+ width -= line_width * 2
+ height -= line_width * 2
+
+ self._paint_ellipse(cr, x, y, width, height, self._fill_color)
+
+ color = self._int_to_rgb(self._stroke_color)
+ cr.set_source_rgb(*color)
+ cr.set_line_width(line_width)
+ cr.stroke();
+
+ self._paint_progress_bar(cr, x, y, width, height, line_width)
+
+ def _paint_progress_bar(self, cr, x, y, width, height, line_width):
+ prog_x = x + line_width
+ prog_y = y + line_width
+ prog_width = (width - (line_width * 2)) * (self._percent / 100.0)
+ prog_height = (height - (line_width * 2))
+
+ self._paint_ellipse(cr, prog_x, prog_y, width, height, self._progress_color)
+
+ def _paint_ellipse(self, cr, x, y, width, height, fill_color):
+ cr.move_to(x + self._radius, y)
+ cr.arc(x + width - self._radius,
+ y + self._radius,
+ self._radius,
+ math.pi * 1.5,
+ math.pi * 2)
+ cr.arc(x + width - self._radius,
+ x + height - self._radius,
+ self._radius,
+ 0,
+ math.pi * 0.5)
+ cr.arc(x + self._radius,
+ y + height - self._radius,
+ self._radius,
+ math.pi * 0.5,
+ math.pi)
+ cr.arc(x + self._radius,
+ y + self._radius,
+ self._radius,
+ math.pi,
+ math.pi * 1.5);
+
+ color = self._int_to_rgb(fill_color)
+ cr.set_source_rgb(*color)
+ cr.fill_preserve();
diff --git a/sugar/graphics/bubble.py b/sugar/graphics/bubble.py
index f5903a0..5bfe87a 100644
--- a/sugar/graphics/bubble.py
+++ b/sugar/graphics/bubble.py
@@ -22,56 +22,56 @@ import gtk
import hippo
class Bubble(hippo.CanvasBox, hippo.CanvasItem):
- __gtype_name__ = 'SugarBubble'
+ __gtype_name__ = 'SugarBubble'
- __gproperties__ = {
- 'color' : (object, None, None,
- gobject.PARAM_READWRITE),
- }
+ __gproperties__ = {
+ 'color' : (object, None, None,
+ gobject.PARAM_READWRITE),
+ }
- def __init__(self, **kwargs):
- self._color = None
- self._radius = 8
+ def __init__(self, **kwargs):
+ self._color = None
+ self._radius = 8
- hippo.CanvasBox.__init__(self, **kwargs)
+ hippo.CanvasBox.__init__(self, **kwargs)
- def do_set_property(self, pspec, value):
- if pspec.name == 'color':
- self._color = value
- self.emit_paint_needed(0, 0, -1, -1)
+ def do_set_property(self, pspec, value):
+ if pspec.name == 'color':
+ self._color = value
+ self.emit_paint_needed(0, 0, -1, -1)
- def do_get_property(self, pspec):
- if pspec.name == 'color':
- return self._color
+ def do_get_property(self, pspec):
+ if pspec.name == 'color':
+ return self._color
- def _string_to_rgb(self, color_string):
- col = gtk.gdk.color_parse(color_string)
- return (col.red / 65535.0, col.green / 65535.0, col.blue / 65535.0)
+ def _string_to_rgb(self, color_string):
+ col = gtk.gdk.color_parse(color_string)
+ return (col.red / 65535.0, col.green / 65535.0, col.blue / 65535.0)
- 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()
- line_width = 3.0
- x = line_width
- y = line_width
- width -= line_width * 2
- height -= line_width * 2
+ line_width = 3.0
+ x = line_width
+ y = line_width
+ width -= line_width * 2
+ height -= line_width * 2
- cr.move_to(x + self._radius, y);
- cr.arc(x + width - self._radius, y + self._radius,
- self._radius, math.pi * 1.5, math.pi * 2);
- cr.arc(x + width - self._radius, x + height - self._radius,
- self._radius, 0, math.pi * 0.5);
- cr.arc(x + self._radius, y + height - self._radius,
- self._radius, math.pi * 0.5, math.pi);
- cr.arc(x + self._radius, y + self._radius, self._radius,
- math.pi, math.pi * 1.5);
+ cr.move_to(x + self._radius, y);
+ cr.arc(x + width - self._radius, y + self._radius,
+ self._radius, math.pi * 1.5, math.pi * 2);
+ cr.arc(x + width - self._radius, x + height - self._radius,
+ self._radius, 0, math.pi * 0.5);
+ cr.arc(x + self._radius, y + height - self._radius,
+ self._radius, math.pi * 0.5, math.pi);
+ cr.arc(x + self._radius, y + self._radius, self._radius,
+ math.pi, math.pi * 1.5);
- color = self._string_to_rgb(self._color.get_fill_color())
- cr.set_source_rgb(*color)
- cr.fill_preserve();
+ color = self._string_to_rgb(self._color.get_fill_color())
+ cr.set_source_rgb(*color)
+ cr.fill_preserve();
- color = self._string_to_rgb(self._color.get_stroke_color())
- cr.set_source_rgb(*color)
- cr.set_line_width(line_width)
- cr.stroke();
+ color = self._string_to_rgb(self._color.get_stroke_color())
+ cr.set_source_rgb(*color)
+ cr.set_line_width(line_width)
+ cr.stroke();
diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py
index da3d8ca..06aff7b 100644
--- a/sugar/graphics/canvasicon.py
+++ b/sugar/graphics/canvasicon.py
@@ -26,133 +26,133 @@ import cairo
from sugar.graphics.iconcolor import IconColor
class _IconCache:
- def __init__(self):
- self._icons = {}
- self._theme = gtk.icon_theme_get_default()
+ def __init__(self):
+ self._icons = {}
+ self._theme = gtk.icon_theme_get_default()
- def _read_icon(self, filename, color):
- icon_file = open(filename, 'r')
+ def _read_icon(self, filename, color):
+ icon_file = open(filename, 'r')
- if color == None:
- return rsvg.Handle(file=filename)
- else:
- data = icon_file.read()
- icon_file.close()
+ if color == None:
+ return rsvg.Handle(file=filename)
+ else:
+ data = icon_file.read()
+ icon_file.close()
- fill = color.get_fill_color()
- stroke = color.get_stroke_color()
-
- entity = '<!ENTITY fill_color "%s">' % fill
- data = re.sub('<!ENTITY fill_color .*>', entity, data)
+ fill = color.get_fill_color()
+ stroke = color.get_stroke_color()
+
+ entity = '<!ENTITY fill_color "%s">' % fill
+ data = re.sub('<!ENTITY fill_color .*>', entity, data)
- entity = '<!ENTITY stroke_color "%s">' % stroke
- data = re.sub('<!ENTITY stroke_color .*>', entity, data)
+ entity = '<!ENTITY stroke_color "%s">' % stroke
+ data = re.sub('<!ENTITY stroke_color .*>', entity, data)
- return rsvg.Handle(data=data)
+ return rsvg.Handle(data=data)
- def get_handle(self, name, color, size):
- info = self._theme.lookup_icon(name, int(size), 0)
+ def get_handle(self, name, color, size):
+ info = self._theme.lookup_icon(name, int(size), 0)
- if color:
- key = (info.get_filename(), color.to_string())
- else:
- key = info.get_filename()
+ if color:
+ key = (info.get_filename(), color.to_string())
+ else:
+ key = info.get_filename()
- if self._icons.has_key(key):
- icon = self._icons[key]
- else:
- icon = self._read_icon(info.get_filename(), color)
- self._icons[key] = icon
- return icon
+ if self._icons.has_key(key):
+ icon = self._icons[key]
+ else:
+ icon = self._read_icon(info.get_filename(), color)
+ self._icons[key] = icon
+ return icon
class CanvasIcon(hippo.CanvasBox, hippo.CanvasItem):
- __gtype_name__ = 'CanvasIcon'
-
- __gproperties__ = {
- 'icon-name': (str, None, None, None,
- gobject.PARAM_READWRITE),
- 'color' : (object, None, None,
- gobject.PARAM_READWRITE),
- 'size' : (int, None, None,
- 0, 1024, 24,
- gobject.PARAM_READWRITE)
- }
-
- _cache = _IconCache()
-
- def __init__(self, **kwargs):
- self._size = 24
- self._color = None
- self._icon_name = None
-
- hippo.CanvasBox.__init__(self, **kwargs)
-
- self._buffer = None
-
- self.connect('button-press-event', self._button_press_event_cb)
-
- def do_set_property(self, pspec, value):
- if pspec.name == 'icon-name':
- self._icon_name = value
- self._buffer = None
- self.emit_paint_needed(0, 0, -1, -1)
- elif pspec.name == 'color':
- self._buffer = None
- self._color = value
- self.emit_paint_needed(0, 0, -1, -1)
- elif pspec.name == 'size':
- self._buffer = None
- self._size = value
- self.emit_request_changed()
-
- def do_get_property(self, pspec):
- if pspec.name == 'size':
- return self._size
- elif pspec.name == 'icon-name':
- return self._icon_name
- elif pspec.name == 'color':
- return self._color
-
- def _get_buffer(self, cr, handle, size):
- if self._buffer == None:
- target = cr.get_target()
- surface = target.create_similar(cairo.CONTENT_COLOR_ALPHA,
- int(size) + 1, int(size) + 1)
-
- dimensions = handle.get_dimension_data()
- scale = float(size) / float(dimensions[0])
-
- ctx = cairo.Context(surface)
- ctx.scale(scale, scale)
- handle.render_cairo(ctx)
- del ctx
-
- self._buffer = surface
- self._buffer_scale = scale
-
- return self._buffer
-
- def do_paint_below_children(self, cr, damaged_box):
- icon_name = self._icon_name
- if icon_name == None:
- icon_name = 'stock-missing'
-
- handle = CanvasIcon._cache.get_handle(
- icon_name, self._color, self._size)
- buf = self._get_buffer(cr, handle, self._size)
-
- [width, height] = self.get_allocation()
- x = (width - self._size) / 2
- y = (height - self._size) / 2
-
- cr.set_source_surface(buf, x, y)
- cr.paint()
-
- def do_get_width_request(self):
- return self._size
-
- def do_get_height_request(self, for_width):
- return self._size
-
- def _button_press_event_cb(self, item, event):
- item.emit_activated()
+ __gtype_name__ = 'CanvasIcon'
+
+ __gproperties__ = {
+ 'icon-name': (str, None, None, None,
+ gobject.PARAM_READWRITE),
+ 'color' : (object, None, None,
+ gobject.PARAM_READWRITE),
+ 'size' : (int, None, None,
+ 0, 1024, 24,
+ gobject.PARAM_READWRITE)
+ }
+
+ _cache = _IconCache()
+
+ def __init__(self, **kwargs):
+ self._size = 24
+ self._color = None
+ self._icon_name = None
+
+ hippo.CanvasBox.__init__(self, **kwargs)
+
+ self._buffer = None
+
+ self.connect('button-press-event', self._button_press_event_cb)
+
+ def do_set_property(self, pspec, value):
+ if pspec.name == 'icon-name':
+ self._icon_name = value
+ self._buffer = None
+ self.emit_paint_needed(0, 0, -1, -1)
+ elif pspec.name == 'color':
+ self._buffer = None
+ self._color = value
+ self.emit_paint_needed(0, 0, -1, -1)
+ elif pspec.name == 'size':
+ self._buffer = None
+ self._size = value
+ self.emit_request_changed()
+
+ def do_get_property(self, pspec):
+ if pspec.name == 'size':
+ return self._size
+ elif pspec.name == 'icon-name':
+ return self._icon_name
+ elif pspec.name == 'color':
+ return self._color
+
+ def _get_buffer(self, cr, handle, size):
+ if self._buffer == None:
+ target = cr.get_target()
+ surface = target.create_similar(cairo.CONTENT_COLOR_ALPHA,
+ int(size) + 1, int(size) + 1)
+
+ dimensions = handle.get_dimension_data()
+ scale = float(size) / float(dimensions[0])
+
+ ctx = cairo.Context(surface)
+ ctx.scale(scale, scale)
+ handle.render_cairo(ctx)
+ del ctx
+
+ self._buffer = surface
+ self._buffer_scale = scale
+
+ return self._buffer
+
+ def do_paint_below_children(self, cr, damaged_box):
+ icon_name = self._icon_name
+ if icon_name == None:
+ icon_name = 'stock-missing'
+
+ handle = CanvasIcon._cache.get_handle(
+ icon_name, self._color, self._size)
+ buf = self._get_buffer(cr, handle, self._size)
+
+ [width, height] = self.get_allocation()
+ x = (width - self._size) / 2
+ y = (height - self._size) / 2
+
+ cr.set_source_surface(buf, x, y)
+ cr.paint()
+
+ def do_get_width_request(self):
+ return self._size
+
+ def do_get_height_request(self, for_width):
+ return self._size
+
+ def _button_press_event_cb(self, item, event):
+ item.emit_activated()
diff --git a/sugar/graphics/grid.py b/sugar/graphics/grid.py
index 350b4ec..cfbdf67 100644
--- a/sugar/graphics/grid.py
+++ b/sugar/graphics/grid.py
@@ -21,19 +21,19 @@ COLS = 16
ROWS = 12
class Grid(object):
- def __init__(self):
- self._factor = gtk.gdk.screen_width() / COLS
+ def __init__(self):
+ self._factor = gtk.gdk.screen_width() / COLS
- def point(self, grid_x, grid_y):
- return [grid_x * self._factor, grid_y * self._factor]
+ def point(self, grid_x, grid_y):
+ return [grid_x * self._factor, grid_y * self._factor]
- def rectangle(self, grid_x, grid_y, grid_w, grid_h):
- return [grid_x * self._factor, grid_y * self._factor,
- grid_w * self._factor, grid_h * self._factor]
+ def rectangle(self, grid_x, grid_y, grid_w, grid_h):
+ return [grid_x * self._factor, grid_y * self._factor,
+ grid_w * self._factor, grid_h * self._factor]
- def dimension(self, grid_dimension):
- return grid_dimension * self._factor
+ def dimension(self, grid_dimension):
+ return grid_dimension * self._factor
- def fit_point(self, x, y):
- return [int(x / self._factor), int(y / self._factor)]
-
+ def fit_point(self, x, y):
+ return [int(x / self._factor), int(y / self._factor)]
+
diff --git a/sugar/graphics/iconcolor.py b/sugar/graphics/iconcolor.py
index d736d54..71dfe18 100644
--- a/sugar/graphics/iconcolor.py
+++ b/sugar/graphics/iconcolor.py
@@ -20,32 +20,32 @@ import random
from sugar.graphics.colors import colors
def _parse_string(color_string):
- if color_string == 'white':
- return ['#ffffff', '#414141']
+ if color_string == 'white':
+ return ['#ffffff', '#414141']
- splitted = color_string.split(',')
- if len(splitted) == 2:
- return [splitted[0], splitted[1]]
- else:
- return None
+ splitted = color_string.split(',')
+ if len(splitted) == 2:
+ return [splitted[0], splitted[1]]
+ else:
+ return None
def is_valid(color_string):
- return (_parse_string(color_string) != None)
+ return (_parse_string(color_string) != None)
class IconColor:
- def __init__(self, color_string=None):
- if color_string == None or not is_valid(color_string):
- n = int(random.random() * (len(colors) - 1))
- [self._stroke, self._fill] = colors[n]
- else:
- [self._stroke, self._fill] = _parse_string(color_string)
+ def __init__(self, color_string=None):
+ if color_string == None or not is_valid(color_string):
+ n = int(random.random() * (len(colors) - 1))
+ [self._stroke, self._fill] = colors[n]
+ else:
+ [self._stroke, self._fill] = _parse_string(color_string)
- def get_stroke_color(self):
- return self._stroke
+ def get_stroke_color(self):
+ return self._stroke
- def get_fill_color(self):
- return self._fill
+ def get_fill_color(self):
+ return self._fill
- def to_string(self):
- return '%s,%s' % (self._stroke, self._fill)
+ def to_string(self):
+ return '%s,%s' % (self._stroke, self._fill)
diff --git a/sugar/graphics/menu.py b/sugar/graphics/menu.py
index 508dbb0..5b68d61 100644
--- a/sugar/graphics/menu.py
+++ b/sugar/graphics/menu.py
@@ -23,85 +23,85 @@ from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics import style
class Menu(gtk.Window):
- __gsignals__ = {
- 'action': (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE, ([int])),
- }
+ __gsignals__ = {
+ 'action': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE, ([int])),
+ }
- def __init__(self, title=None, content_box=None):
- gtk.Window.__init__(self, gtk.WINDOW_POPUP)
+ def __init__(self, title=None, content_box=None):
+ gtk.Window.__init__(self, gtk.WINDOW_POPUP)
- canvas = hippo.Canvas()
- self.add(canvas)
- canvas.show()
+ canvas = hippo.Canvas()
+ self.add(canvas)
+ canvas.show()
- self._root = hippo.CanvasBox()
- style.apply_stylesheet(self._root, 'menu')
- canvas.set_root(self._root)
+ self._root = hippo.CanvasBox()
+ style.apply_stylesheet(self._root, 'menu')
+ canvas.set_root(self._root)
- if title:
- self._title_item = hippo.CanvasText(text=title)
- style.apply_stylesheet(self._title_item, 'menu.Title')
- self._root.append(self._title_item)
- else:
- self._title_item = None
+ if title:
+ self._title_item = hippo.CanvasText(text=title)
+ style.apply_stylesheet(self._title_item, 'menu.Title')
+ self._root.append(self._title_item)
+ else:
+ self._title_item = None
- if content_box:
- separator = self._create_separator()
- self._root.append(separator)
- self._root.append(content_box)
+ if content_box:
+ separator = self._create_separator()
+ self._root.append(separator)
+ self._root.append(content_box)
- self._action_box = None
- self._item_box = None
+ self._action_box = None
+ self._item_box = None
- def _create_separator(self):
- separator = hippo.CanvasBox()
- style.apply_stylesheet(separator, 'menu.Separator')
- return separator
+ def _create_separator(self):
+ separator = hippo.CanvasBox()
+ style.apply_stylesheet(separator, 'menu.Separator')
+ return separator
- def _create_item_box(self):
- if self._title_item:
- separator = self._create_separator()
- self._root.append(separator)
+ def _create_item_box(self):
+ if self._title_item:
+ separator = self._create_separator()
+ self._root.append(separator)
- self._item_box = hippo.CanvasBox(
- orientation=hippo.ORIENTATION_VERTICAL)
- self._root.append(self._item_box)
+ self._item_box = hippo.CanvasBox(
+ orientation=hippo.ORIENTATION_VERTICAL)
+ self._root.append(self._item_box)
- def _create_action_box(self):
- separator = self._create_separator()
- self._root.append(separator)
+ def _create_action_box(self):
+ separator = self._create_separator()
+ self._root.append(separator)
- self._action_box = hippo.CanvasBox(
- orientation=hippo.ORIENTATION_HORIZONTAL)
- self._root.append(self._action_box)
+ self._action_box = hippo.CanvasBox(
+ orientation=hippo.ORIENTATION_HORIZONTAL)
+ self._root.append(self._action_box)
- def add_item(self, label, action_id):
- if not self._item_box:
- self._create_item_box()
+ def add_item(self, label, action_id):
+ if not self._item_box:
+ self._create_item_box()
- text = hippo.CanvasText(text=label)
- style.apply_stylesheet(text, 'menu.Item')
+ text = hippo.CanvasText(text=label)
+ style.apply_stylesheet(text, 'menu.Item')
- # FIXME need a way to make hippo items activable in python
- text.connect('button-press-event', self._item_clicked_cb, action_id)
- #text.connect('activated', self._action_clicked_cb, action_id)
+ # FIXME need a way to make hippo items activable in python
+ text.connect('button-press-event', self._item_clicked_cb, action_id)
+ #text.connect('activated', self._action_clicked_cb, action_id)
- self._item_box.append(text)
+ self._item_box.append(text)
- def add_action(self, icon, action_id):
- if not self._action_box:
- self._create_action_box()
+ def add_action(self, icon, action_id):
+ if not self._action_box:
+ self._create_action_box()
- style.apply_stylesheet(icon, 'menu.ActionIcon')
- icon.connect('activated', self._action_clicked_cb, action_id)
- self._action_box.append(icon)
+ style.apply_stylesheet(icon, 'menu.ActionIcon')
+ icon.connect('activated', self._action_clicked_cb, action_id)
+ self._action_box.append(icon)
- def remove_action(self, icon):
- self._action_box.remove(icon)
+ def remove_action(self, icon):
+ self._action_box.remove(icon)
- def _item_clicked_cb(self, icon, event, action):
- self.emit('action', action)
+ def _item_clicked_cb(self, icon, event, action):
+ self.emit('action', action)
- def _action_clicked_cb(self, icon, action):
- self.emit('action', action)
+ def _action_clicked_cb(self, icon, action):
+ self.emit('action', action)
diff --git a/sugar/graphics/menuicon.py b/sugar/graphics/menuicon.py
index 8c0041e..62d1275 100644
--- a/sugar/graphics/menuicon.py
+++ b/sugar/graphics/menuicon.py
@@ -23,58 +23,58 @@ from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics.timeline import Timeline
class MenuIcon(CanvasIcon):
- def __init__(self, menu_shell, **kwargs):
- CanvasIcon.__init__(self, **kwargs)
+ def __init__(self, menu_shell, **kwargs):
+ CanvasIcon.__init__(self, **kwargs)
- self._menu_shell = menu_shell
- self._menu = None
- self._hover_menu = False
+ self._menu_shell = menu_shell
+ self._menu = None
+ self._hover_menu = False
- self._timeline = Timeline(self)
- self._timeline.add_tag('popup', 6, 6)
- self._timeline.add_tag('before_popdown', 7, 7)
- self._timeline.add_tag('popdown', 8, 8)
+ self._timeline = Timeline(self)
+ self._timeline.add_tag('popup', 6, 6)
+ self._timeline.add_tag('before_popdown', 7, 7)
+ self._timeline.add_tag('popdown', 8, 8)
- self.connect('motion-notify-event', self._motion_notify_event_cb)
+ self.connect('motion-notify-event', self._motion_notify_event_cb)
- def do_popup(self, current, n_frames):
- if self._menu:
- return
+ def do_popup(self, current, n_frames):
+ if self._menu:
+ return
- self._menu = self.create_menu()
+ self._menu = self.create_menu()
- self._menu.connect('enter-notify-event',
- self._menu_enter_notify_event_cb)
- self._menu.connect('leave-notify-event',
- self._menu_leave_notify_event_cb)
+ self._menu.connect('enter-notify-event',
+ self._menu_enter_notify_event_cb)
+ self._menu.connect('leave-notify-event',
+ self._menu_leave_notify_event_cb)
- [x, y] = self._menu_shell.get_position(self._menu, self)
+ [x, y] = self._menu_shell.get_position(self._menu, self)
- self._menu.move(x, y)
- self._menu.show()
+ self._menu.move(x, y)
+ self._menu.show()
- self._menu_shell.set_active(self)
+ self._menu_shell.set_active(self)
- def do_popdown(self, current, frame):
- if self._menu:
- self._menu.destroy()
- self._menu = None
- self._menu_shell.set_active(None)
+ def do_popdown(self, current, frame):
+ if self._menu:
+ self._menu.destroy()
+ self._menu = None
+ self._menu_shell.set_active(None)
- def popdown(self):
- self._timeline.play('popdown', 'popdown')
+ def popdown(self):
+ self._timeline.play('popdown', 'popdown')
- def _motion_notify_event_cb(self, item, event):
- if event.detail == hippo.MOTION_DETAIL_ENTER:
- self._timeline.play(None, 'popup')
- elif event.detail == hippo.MOTION_DETAIL_LEAVE:
- if not self._hover_menu:
- self._timeline.play('before_popdown', 'popdown')
+ def _motion_notify_event_cb(self, item, event):
+ if event.detail == hippo.MOTION_DETAIL_ENTER:
+ self._timeline.play(None, 'popup')
+ elif event.detail == hippo.MOTION_DETAIL_LEAVE:
+ if not self._hover_menu:
+ self._timeline.play('before_popdown', 'popdown')
- def _menu_enter_notify_event_cb(self, widget, event):
- self._hover_menu = True
- self._timeline.play('popup', 'popup')
+ def _menu_enter_notify_event_cb(self, widget, event):
+ self._hover_menu = True
+ self._timeline.play('popup', 'popup')
- def _menu_leave_notify_event_cb(self, widget, event):
- self._hover_menu = False
- self._timeline.play('popdown', 'popdown')
+ def _menu_leave_notify_event_cb(self, widget, event):
+ self._hover_menu = False
+ self._timeline.play('popdown', 'popdown')
diff --git a/sugar/graphics/menushell.py b/sugar/graphics/menushell.py
index 48183e1..61b98b0 100644
--- a/sugar/graphics/menushell.py
+++ b/sugar/graphics/menushell.py
@@ -19,83 +19,83 @@ import gobject
import gtk
class MenuShell(gobject.GObject):
- __gsignals__ = {
- 'activated': (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE, ([])),
- 'deactivated': (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE, ([])),
- }
-
- AUTO = 0
- LEFT = 1
- RIGHT = 2
- TOP = 3
- BOTTOM = 4
-
- def __init__(self, parent_canvas):
- gobject.GObject.__init__(self)
-
- self._parent_canvas = parent_canvas
- self._menu_controller = None
- self._position = MenuShell.AUTO
-
- def set_position(self, position):
- self._position = position
-
- def is_active(self):
- return (self._menu_controller != None)
-
- def set_active(self, controller):
- if controller == None:
- self.emit('deactivated')
- else:
- self.emit('activated')
-
- if self._menu_controller:
- self._menu_controller.popdown()
- self._menu_controller = controller
-
- def _get_item_rect(self, item):
- [x, y] = item.get_context().translate_to_widget(item)
-
- [origin_x, origin_y] = self._parent_canvas.window.get_origin()
- x += origin_x
- y += origin_y
-
- [w, h] = item.get_allocation()
-
- return [x, y, w, h]
-
- def get_position(self, menu, item):
- [item_x, item_y, item_w, item_h] = self._get_item_rect(item)
- [menu_w, menu_h] = menu.size_request()
-
- left_x = item_x - menu_w
- left_y = item_y
- right_x = item_x + item_w
- right_y = item_y
- top_x = item_x
- top_y = item_y - menu_h
- bottom_x = item_x
- bottom_y = item_y + item_h
-
- if self._position == MenuShell.LEFT:
- [x, y] = [left_x, left_y]
- elif self._position == MenuShell.RIGHT:
- [x, y] = [right_x, right_y]
- elif self._position == MenuShell.TOP:
- [x, y] = [top_x, top_y]
- elif self._position == MenuShell.BOTTOM:
- [x, y] = [bottom_x, bottom_y]
- elif self._position == MenuShell.AUTO:
- [x, y] = [right_x, right_y]
- if x + menu_w > gtk.gdk.screen_width():
- [x, y] = [left_x, left_y]
-
- x = min(x, gtk.gdk.screen_width() - menu_w)
- x = max(0, x)
-
- y = min(y, gtk.gdk.screen_height() - menu_h)
- y = max(0, y)
-
- return [x, y]
+ __gsignals__ = {
+ 'activated': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE, ([])),
+ 'deactivated': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE, ([])),
+ }
+
+ AUTO = 0
+ LEFT = 1
+ RIGHT = 2
+ TOP = 3
+ BOTTOM = 4
+
+ def __init__(self, parent_canvas):
+ gobject.GObject.__init__(self)
+
+ self._parent_canvas = parent_canvas
+ self._menu_controller = None
+ self._position = MenuShell.AUTO
+
+ def set_position(self, position):
+ self._position = position
+
+ def is_active(self):
+ return (self._menu_controller != None)
+
+ def set_active(self, controller):
+ if controller == None:
+ self.emit('deactivated')
+ else:
+ self.emit('activated')
+
+ if self._menu_controller:
+ self._menu_controller.popdown()
+ self._menu_controller = controller
+
+ def _get_item_rect(self, item):
+ [x, y] = item.get_context().translate_to_widget(item)
+
+ [origin_x, origin_y] = self._parent_canvas.window.get_origin()
+ x += origin_x
+ y += origin_y
+
+ [w, h] = item.get_allocation()
+
+ return [x, y, w, h]
+
+ def get_position(self, menu, item):
+ [item_x, item_y, item_w, item_h] = self._get_item_rect(item)
+ [menu_w, menu_h] = menu.size_request()
+
+ left_x = item_x - menu_w
+ left_y = item_y
+ right_x = item_x + item_w
+ right_y = item_y
+ top_x = item_x
+ top_y = item_y - menu_h
+ bottom_x = item_x
+ bottom_y = item_y + item_h
+
+ if self._position == MenuShell.LEFT:
+ [x, y] = [left_x, left_y]
+ elif self._position == MenuShell.RIGHT:
+ [x, y] = [right_x, right_y]
+ elif self._position == MenuShell.TOP:
+ [x, y] = [top_x, top_y]
+ elif self._position == MenuShell.BOTTOM:
+ [x, y] = [bottom_x, bottom_y]
+ elif self._position == MenuShell.AUTO:
+ [x, y] = [right_x, right_y]
+ if x + menu_w > gtk.gdk.screen_width():
+ [x, y] = [left_x, left_y]
+
+ x = min(x, gtk.gdk.screen_width() - menu_w)
+ x = max(0, x)
+
+ y = min(y, gtk.gdk.screen_height() - menu_h)
+ y = max(0, y)
+
+ return [x, y]
diff --git a/sugar/graphics/snowflakebox.py b/sugar/graphics/snowflakebox.py
index 2af11cd..30f5b05 100644
--- a/sugar/graphics/snowflakebox.py
+++ b/sugar/graphics/snowflakebox.py
@@ -25,72 +25,72 @@ _CHILDREN_FACTOR = 1
_FLAKE_DISTANCE = 6
class SnowflakeBox(hippo.CanvasBox, hippo.CanvasItem):
- __gtype_name__ = 'SugarSnowflakeBox'
- def __init__(self, **kwargs):
- hippo.CanvasBox.__init__(self, **kwargs)
- self._root = None
+ __gtype_name__ = 'SugarSnowflakeBox'
+ def __init__(self, **kwargs):
+ hippo.CanvasBox.__init__(self, **kwargs)
+ self._root = None
- def set_root(self, icon):
- self._root = icon
+ def set_root(self, icon):
+ self._root = icon
- def _get_center(self):
- [width, height] = self.get_allocation()
- return [width / 2, height / 2]
+ def _get_center(self):
+ [width, height] = self.get_allocation()
+ return [width / 2, height / 2]
- def _get_radius(self):
- return _BASE_RADIUS + _CHILDREN_FACTOR * self._get_n_children()
+ def _get_radius(self):
+ return _BASE_RADIUS + _CHILDREN_FACTOR * self._get_n_children()
- def _layout_root(self):
- [width, height] = self._root.get_allocation()
- [cx, cy] = self._get_center()
+ def _layout_root(self):
+ [width, height] = self._root.get_allocation()
+ [cx, cy] = self._get_center()
- x = cx - (width / 2)
- y = cy - (height / 2)
+ x = cx - (width / 2)
+ y = cy - (height / 2)
- self.move(self._root, int(x), int(y))
+ self.move(self._root, int(x), int(y))
- def _get_n_children(self):
- return len(self.get_children()) - 1
+ def _get_n_children(self):
+ return len(self.get_children()) - 1
- def _layout_child(self, child, index):
- r = self._get_radius()
- if (self._get_n_children() > 10):
- r += _FLAKE_DISTANCE * (index % 3)
+ def _layout_child(self, child, index):
+ r = self._get_radius()
+ if (self._get_n_children() > 10):
+ r += _FLAKE_DISTANCE * (index % 3)
- angle = 2 * math.pi * index / self._get_n_children()
+ angle = 2 * math.pi * index / self._get_n_children()
- [width, height] = child.get_allocation()
- [cx, cy] = self._get_center()
+ [width, height] = child.get_allocation()
+ [cx, cy] = self._get_center()
- x = cx + math.cos(angle) * r - (width / 2)
- y = cy + math.sin(angle) * r - (height / 2)
+ x = cx + math.cos(angle) * r - (width / 2)
+ y = cy + math.sin(angle) * r - (height / 2)
- self.move(child, int(x), int(y))
+ self.move(child, int(x), int(y))
- def do_get_width_request(self):
- hippo.CanvasBox.do_get_width_request(self)
+ def do_get_width_request(self):
+ hippo.CanvasBox.do_get_width_request(self)
- max_child_size = 0
- for child in self.get_children():
- width = child.get_width_request()
- height = child.get_height_request(width)
- max_child_size = max (max_child_size, width)
- max_child_size = max (max_child_size, height)
+ max_child_size = 0
+ for child in self.get_children():
+ width = child.get_width_request()
+ height = child.get_height_request(width)
+ max_child_size = max (max_child_size, width)
+ max_child_size = max (max_child_size, height)
- return self._get_radius() * 2 + \
- max_child_size + _FLAKE_DISTANCE * 2
+ return self._get_radius() * 2 + \
+ max_child_size + _FLAKE_DISTANCE * 2
- def do_get_height_request(self, width):
- hippo.CanvasBox.do_get_height_request(self, width)
- return width
+ def do_get_height_request(self, width):
+ hippo.CanvasBox.do_get_height_request(self, width)
+ return width
- 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)
- self._layout_root()
+ self._layout_root()
- index = 0
- for child in self.get_children():
- if child != self._root:
- self._layout_child(child, index)
- index += 1
+ index = 0
+ for child in self.get_children():
+ if child != self._root:
+ self._layout_child(child, index)
+ index += 1
diff --git a/sugar/graphics/spreadbox.py b/sugar/graphics/spreadbox.py
index 7d4047d..59dfe9c 100644
--- a/sugar/graphics/spreadbox.py
+++ b/sugar/graphics/spreadbox.py
@@ -25,108 +25,108 @@ _DISTANCE_THRESHOLD = 10.0
_FORCE_CONSTANT = 0.1
class SpreadBox(hippo.CanvasBox, hippo.CanvasItem):
- __gtype_name__ = 'SugarSpreadBox'
+ __gtype_name__ = 'SugarSpreadBox'
- def __init__(self, **kwargs):
- hippo.CanvasBox.__init__(self, **kwargs)
+ def __init__(self, **kwargs):
+ hippo.CanvasBox.__init__(self, **kwargs)
- self._items_to_position = []
- self._stable = False
+ self._items_to_position = []
+ self._stable = False
- def add_item(self, item):
- self._items_to_position.append(item)
- self.append(item, hippo.PACK_FIXED)
+ def add_item(self, item):
+ self._items_to_position.append(item)
+ self.append(item, hippo.PACK_FIXED)
- def remove_item(self, item):
- if self._items_to_position.count(item) > 0:
- self._items_to_position.remove(item)
- self.remove(item)
+ def remove_item(self, item):
+ if self._items_to_position.count(item) > 0:
+ self._items_to_position.remove(item)
+ self.remove(item)
- def _get_item_radius(self, item):
- [width, height] = item.get_request()
- return math.sqrt(width ** 2 + height ** 2) / 2
+ def _get_item_radius(self, item):
+ [width, height] = item.get_request()
+ return math.sqrt(width ** 2 + height ** 2) / 2
- def _get_item_center(self, item):
- [width, height] = item.get_request()
- [x, y] = self.get_position(item)
+ def _get_item_center(self, item):
+ [width, height] = item.get_request()
+ [x, y] = self.get_position(item)
- c_x = int(x + float(width) / 2.0)
- c_y = int(y + float(height) / 2.0)
+ c_x = int(x + float(width) / 2.0)
+ c_y = int(y + float(height) / 2.0)
- return [c_x, c_y]
+ return [c_x, c_y]
- def _get_repulsion(self, icon1, icon2):
- [c1_x, c1_y] = self._get_item_center(icon1)
- [c2_x, c2_y] = self._get_item_center(icon2)
+ def _get_repulsion(self, icon1, icon2):
+ [c1_x, c1_y] = self._get_item_center(icon1)
+ [c2_x, c2_y] = self._get_item_center(icon2)
- a = c2_x - c1_x
- b = c2_y - c1_y
+ a = c2_x - c1_x
+ b = c2_y - c1_y
- r1 = self._get_item_radius(icon1)
- r2 = self._get_item_radius(icon2)
- distance = math.sqrt(a ** 2 + b ** 2) - r1 - r2
+ r1 = self._get_item_radius(icon1)
+ r2 = self._get_item_radius(icon2)
+ distance = math.sqrt(a ** 2 + b ** 2) - r1 - r2
- if distance < _DISTANCE_THRESHOLD:
- f_x = int(math.ceil(-_FORCE_CONSTANT * float(a)))
- f_y = int(math.ceil(-_FORCE_CONSTANT * float(b)))
- else:
- f_x = 0
- f_y = 0
+ if distance < _DISTANCE_THRESHOLD:
+ f_x = int(math.ceil(-_FORCE_CONSTANT * float(a)))
+ f_y = int(math.ceil(-_FORCE_CONSTANT * float(b)))
+ else:
+ f_x = 0
+ f_y = 0
- return [f_x, f_y]
+ return [f_x, f_y]
- def _clamp_position(self, icon, x, y):
- x = max(0, x)
- y = max(0, y)
+ def _clamp_position(self, icon, x, y):
+ x = max(0, x)
+ y = max(0, y)
- [item_w, item_h] = icon.get_request()
- [box_w, box_h] = self.get_allocation()
+ [item_w, item_h] = icon.get_request()
+ [box_w, box_h] = self.get_allocation()
- x = min(box_w - item_w, x)
- y = min(box_h - item_h, y)
+ x = min(box_w - item_w, x)
+ y = min(box_h - item_h, y)
- return [x, y]
+ return [x, y]
- def _spread_icons(self):
- self._stable = True
+ def _spread_icons(self):
+ self._stable = True
- for icon1 in self.get_children():
- vx = 0
- vy = 0
+ for icon1 in self.get_children():
+ vx = 0
+ vy = 0
- for icon2 in self.get_children():
- if icon1 != icon2:
- [f_x, f_y] = self._get_repulsion(icon1, icon2)
- if f_x != 0 or f_y != 0:
- self._stable = False
- vx += f_x
- vy += f_y
+ for icon2 in self.get_children():
+ if icon1 != icon2:
+ [f_x, f_y] = self._get_repulsion(icon1, icon2)
+ if f_x != 0 or f_y != 0:
+ self._stable = False
+ vx += f_x
+ vy += f_y
- if vx != 0 or vy != 0:
- [x, y] = self.get_position(icon1)
- new_x = x + vx
- new_y = y + vy
+ if vx != 0 or vy != 0:
+ [x, y] = self.get_position(icon1)
+ new_x = x + vx
+ new_y = y + vy
- [new_x, new_y] = self._clamp_position(icon1, new_x, new_y)
+ [new_x, new_y] = self._clamp_position(icon1, new_x, new_y)
- self.move(icon1, new_x, new_y)
+ self.move(icon1, new_x, new_y)
- 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)
- for item in self._items_to_position:
- [item_w, item_h] = item.get_request()
+ for item in self._items_to_position:
+ [item_w, item_h] = item.get_request()
- x = int(random.random() * width - item_w)
- y = int(random.random() * height - item_h)
+ x = int(random.random() * width - item_w)
+ y = int(random.random() * height - item_h)
- [x, y] = self._clamp_position(item, x, y)
- self.move(item, x, y)
+ [x, y] = self._clamp_position(item, x, y)
+ self.move(item, x, y)
- self._items_to_position = []
+ self._items_to_position = []
- tries = 20
- self._spread_icons()
- while not self._stable and tries > 0:
- self._spread_icons()
- tries -= 1
+ tries = 20
+ self._spread_icons()
+ while not self._stable and tries > 0:
+ self._spread_icons()
+ tries -= 1
diff --git a/sugar/graphics/style.py b/sugar/graphics/style.py
index f0ab3e8..6c4bff3 100644
--- a/sugar/graphics/style.py
+++ b/sugar/graphics/style.py
@@ -31,21 +31,21 @@ large_icon_size = standard_icon_size * 2.0
xlarge_icon_size = standard_icon_size * 3.0
def load_stylesheet(module):
- for objname in dir(module):
- if not objname.startswith('_'):
- obj = getattr(module, objname)
- if isinstance(obj, dict):
- register_stylesheet(objname.replace('_', '.'), obj)
+ for objname in dir(module):
+ if not objname.startswith('_'):
+ obj = getattr(module, objname)
+ if isinstance(obj, dict):
+ register_stylesheet(objname.replace('_', '.'), obj)
def register_stylesheet(name, style):
- _styles[name] = style
+ _styles[name] = style
def apply_stylesheet(item, stylesheet_name):
- if _styles.has_key(stylesheet_name):
- style_sheet = _styles[stylesheet_name]
- for name in style_sheet.keys():
- item.set_property(name, style_sheet[name])
+ if _styles.has_key(stylesheet_name):
+ style_sheet = _styles[stylesheet_name]
+ for name in style_sheet.keys():
+ item.set_property(name, style_sheet[name])
def get_font_description(style, relative_size):
- base_size = 18 * _screen_factor
- return '%s %dpx' % (style, int(base_size * relative_size))
+ base_size = 18 * _screen_factor
+ return '%s %dpx' % (style, int(base_size * relative_size))
diff --git a/sugar/graphics/stylesheet.py b/sugar/graphics/stylesheet.py
index d349733..ae9b4c8 100644
--- a/sugar/graphics/stylesheet.py
+++ b/sugar/graphics/stylesheet.py
@@ -1,31 +1,31 @@
from sugar.graphics import style
menu = {
- 'background_color' : 0x000000FF,
- 'spacing' : style.space_unit,
- 'padding' : style.space_unit
+ 'background_color' : 0x000000FF,
+ 'spacing' : style.space_unit,
+ 'padding' : style.space_unit
}
menu_Title = {
- 'color' : 0xFFFFFFFF,
- 'font' : style.get_font_description('Bold', 1.2)
+ 'color' : 0xFFFFFFFF,
+ 'font' : style.get_font_description('Bold', 1.2)
}
menu_Separator = {
- 'background_color' : 0xFFFFFFFF,
- 'box_height' : style.separator_thickness
+ 'background_color' : 0xFFFFFFFF,
+ 'box_height' : style.separator_thickness
}
menu_ActionIcon = {
- 'size' : style.standard_icon_size
+ 'size' : style.standard_icon_size
}
menu_Item = {
- 'color' : 0xFFFFFFFF,
- 'font' : style.get_font_description('Plain', 1.1)
+ 'color' : 0xFFFFFFFF,
+ 'font' : style.get_font_description('Plain', 1.1)
}
menu_Text = {
- 'color' : 0xFFFFFFFF,
- 'font' : style.get_font_description('Plain', 1.2)
+ 'color' : 0xFFFFFFFF,
+ 'font' : style.get_font_description('Plain', 1.2)
}
diff --git a/sugar/graphics/timeline.py b/sugar/graphics/timeline.py
index 5c40ca5..3944771 100644
--- a/sugar/graphics/timeline.py
+++ b/sugar/graphics/timeline.py
@@ -18,100 +18,100 @@
import gobject
class _Tag:
- def __init__(self, name, start_frame, end_frame):
- self.name = name
- self.start_frame = start_frame
- self.end_frame = end_frame
+ def __init__(self, name, start_frame, end_frame):
+ self.name = name
+ self.start_frame = start_frame
+ self.end_frame = end_frame
class TimelineObserver:
- def __init__(self, observer):
- self._observer = observer
+ def __init__(self, observer):
+ self._observer = observer
- def next_frame(self, tag, current_frame, n_frames):
- try:
- method = getattr(self._observer, 'do_' + tag)
- except AttributeError:
- method = None
+ def next_frame(self, tag, current_frame, n_frames):
+ try:
+ method = getattr(self._observer, 'do_' + tag)
+ except AttributeError:
+ method = None
- if method:
- method(current_frame, n_frames)
+ if method:
+ method(current_frame, n_frames)
class Timeline:
- def __init__(self, observer):
- self._fps = 12
- self._tags = []
- self._name_to_tag = {}
- self._current_frame = 0
- self._timeout_sid = 0
- self._observer = TimelineObserver(observer)
-
- def add_tag(self, name, start_frame, end_frame):
- tag = _Tag(name, start_frame, end_frame)
- self._tags.append(tag)
- self._name_to_tag[name] = tag
-
- def remove_tag(self, name):
- tag = self._tags[name]
- self._tags.remove(tag)
- del self._tags[name]
-
- def _next_frame(self, tag, frame):
- n_frames = tag.start_frame - tag.end_frame
- self._observer.next_frame(tag.name, frame, n_frames)
-
- def goto(self, tag_name, end_frame=False):
- self.pause()
-
- tag = self._name_to_tag[tag_name]
- if end_frame:
- self._current_frame = tag.end_frame
- else:
- self._current_frame = tag.start_frame
-
- self._next_frame(tag, self._current_frame)
-
- def on_tag(self, name):
- tag = self._name_to_tag[name]
- return (tag.start_frame <= self._current_frame and \
- tag.end_frame >= self._current_frame)
-
- def _get_tags_for_frame(self, frame):
- result = []
- for tag in self._tags:
- if tag.start_frame <= frame and tag.end_frame >= frame:
- result.append(tag)
- return result
-
- def _timeout_cb(self, end_frame):
- for tag in self._get_tags_for_frame(self._current_frame):
- cur_frame = self._current_frame - tag.start_frame
- self._next_frame(tag, cur_frame)
-
- if self._current_frame < end_frame:
- self._current_frame += 1
- return True
- else:
- return False
-
- def play(self, start_tag=None, stop_tag=None):
- self.pause()
-
- if start_tag == None:
- start = 0
- else:
- start = self._name_to_tag[start_tag].start_frame
-
- if stop_tag == None:
- end = self._tags[len(self._tags) - 1].end_frame
- else:
- end = self._name_to_tag[stop_tag].end_frame
-
- self._current_frame = start
-
- interval = 1000 / self._fps
- self._timeout_sid = gobject.timeout_add(
- interval, self._timeout_cb, end)
-
- def pause(self):
- if self._timeout_sid > 0:
- gobject.source_remove(self._timeout_sid)
+ def __init__(self, observer):
+ self._fps = 12
+ self._tags = []
+ self._name_to_tag = {}
+ self._current_frame = 0
+ self._timeout_sid = 0
+ self._observer = TimelineObserver(observer)
+
+ def add_tag(self, name, start_frame, end_frame):
+ tag = _Tag(name, start_frame, end_frame)
+ self._tags.append(tag)
+ self._name_to_tag[name] = tag
+
+ def remove_tag(self, name):
+ tag = self._tags[name]
+ self._tags.remove(tag)
+ del self._tags[name]
+
+ def _next_frame(self, tag, frame):
+ n_frames = tag.start_frame - tag.end_frame
+ self._observer.next_frame(tag.name, frame, n_frames)
+
+ def goto(self, tag_name, end_frame=False):
+ self.pause()
+
+ tag = self._name_to_tag[tag_name]
+ if end_frame:
+ self._current_frame = tag.end_frame
+ else:
+ self._current_frame = tag.start_frame
+
+ self._next_frame(tag, self._current_frame)
+
+ def on_tag(self, name):
+ tag = self._name_to_tag[name]
+ return (tag.start_frame <= self._current_frame and \
+ tag.end_frame >= self._current_frame)
+
+ def _get_tags_for_frame(self, frame):
+ result = []
+ for tag in self._tags:
+ if tag.start_frame <= frame and tag.end_frame >= frame:
+ result.append(tag)
+ return result
+
+ def _timeout_cb(self, end_frame):
+ for tag in self._get_tags_for_frame(self._current_frame):
+ cur_frame = self._current_frame - tag.start_frame
+ self._next_frame(tag, cur_frame)
+
+ if self._current_frame < end_frame:
+ self._current_frame += 1
+ return True
+ else:
+ return False
+
+ def play(self, start_tag=None, stop_tag=None):
+ self.pause()
+
+ if start_tag == None:
+ start = 0
+ else:
+ start = self._name_to_tag[start_tag].start_frame
+
+ if stop_tag == None:
+ end = self._tags[len(self._tags) - 1].end_frame
+ else:
+ end = self._name_to_tag[stop_tag].end_frame
+
+ self._current_frame = start
+
+ interval = 1000 / self._fps
+ self._timeout_sid = gobject.timeout_add(
+ interval, self._timeout_cb, end)
+
+ def pause(self):
+ if self._timeout_sid > 0:
+ gobject.source_remove(self._timeout_sid)