diff options
author | Bruno Coudoin <bruno.coudoin@free.fr> | 2009-11-01 17:35:08 (GMT) |
---|---|---|
committer | Bruno Coudoin <bruno.coudoin@free.fr> | 2009-11-01 17:35:08 (GMT) |
commit | 87dec57fc0451469cfb612cba3a9024ced1015bb (patch) | |
tree | 70f2eb5ee66aa6a58467f8afcf440f8340153e18 | |
parent | e282df91da12e13433b1a2e00c15648e936eb8c7 (diff) |
Added support for load/save for images.
-rw-r--r-- | src/anim-activity/AnimItem.py | 70 | ||||
-rw-r--r-- | src/anim-activity/anim.py | 5 |
2 files changed, 60 insertions, 15 deletions
diff --git a/src/anim-activity/AnimItem.py b/src/anim-activity/AnimItem.py index d796d5b..b6bf7ea 100644 --- a/src/anim-activity/AnimItem.py +++ b/src/anim-activity/AnimItem.py @@ -88,14 +88,24 @@ class AnimItem: def __getstate__(self): return [self.visible, self.filled, - self.timelineDump(self.timeline)] + self.timelineDump(self.timeline), + self.save_addon()] def __setstate__(self, dict): self.visible = dict[0] self.filled = dict[1] self.timeline = self.timelineRestore(dict[2]) + self.load_addon(dict[3]) self.anchor = None + # Some item types need to save/load more + # than the item properties + def save_addon(self): + return None + + def load_addon(self, addon): + pass + def dump(self): print "Dump AnimItem:" print self.timeline @@ -621,15 +631,6 @@ class Anchor: # class AnimItemRect(AnimItem): - # This is called when an animation file is loaded - def restore(self, anim_): - AnimItem.restore(self, anim_) - self.item = \ - goocanvas.Rect( - parent = self.rootitem - ) - AnimItem.init_item(self) - def __init__(self, anim, x, y, color_fill, color_stroke, line_width): AnimItem.__init__(self, anim) x,y = self.snap_to_grid(x, y) @@ -650,6 +651,14 @@ class AnimItemRect(AnimItem): AnimItem.init_item(self) + # This is called when an animation file is loaded + def restore(self, anim_): + AnimItem.restore(self, anim_) + self.item = \ + goocanvas.Rect( + parent = self.rootitem + ) + AnimItem.init_item(self) # Fixme, should replace set_bounds in resize cases def scale_bounds(self, p1, p2): @@ -733,6 +742,15 @@ class AnimItemEllipse(AnimItem): AnimItem.init_item(self) + # This is called when an animation file is loaded + def restore(self, anim_): + AnimItem.restore(self, anim_) + self.item = \ + goocanvas.Ellipse( + parent = self.rootitem + ) + AnimItem.init_item(self) + def set_bounds(self, p1, p2): (x1, y1, x2, y2) = self.snap_obj_to_grid(p1, p2) radius_x = abs((x2 - x1) / 2) @@ -787,7 +805,6 @@ class AnimItemEllipse(AnimItem): # class AnimItemLine(AnimItem): - def __init__(self, anim, x, y, color_fill, color_stroke, line_width): AnimItem.__init__(self, anim) @@ -803,6 +820,14 @@ class AnimItemLine(AnimItem): AnimItem.init_item(self) + # This is called when an animation file is loaded + def restore(self, anim_): + AnimItem.restore(self, anim_) + self.item = \ + goocanvas.Polyline( + parent = self.rootitem + ) + AnimItem.init_item(self) def set_bounds(self, p1, p2): (x1, y1, x2, y2) = self.snap_point_to_grid(p1, p2) @@ -856,10 +881,13 @@ class AnimItemLine(AnimItem): class AnimItemPixmap(AnimItem): - def __init__(self, anim, x, y, pixbuf): + def __init__(self, anim, x, y, image): AnimItem.__init__(self, anim) x, y = self.snap_to_grid(x, y) + # Keep the image for the load/save feature + self.image = image + pixbuf = gcompris.utils.load_pixmap(image) self.item = \ goocanvas.Image( parent = self.rootitem, @@ -871,6 +899,24 @@ class AnimItemPixmap(AnimItem): self.sx = self.sy = 1.0 + # This is called when an animation file is loaded + def restore(self, anim_): + AnimItem.restore(self, anim_) + pixbuf = gcompris.utils.load_pixmap(self.image) + self.item = \ + goocanvas.Image( + parent = self.rootitem, + pixbuf = pixbuf, + ) + AnimItem.init_item(self) + + def save_addon(self): + return self.image + + def load_addon(self, image): + self.image = image + + def set_bounds(self, p1, p2): (x1, y1, x2, y2) = self.snap_obj_to_grid(p1, p2) bounds = self.item.get_bounds() diff --git a/src/anim-activity/anim.py b/src/anim-activity/anim.py index 7f4f9d2..bfa8a9f 100644 --- a/src/anim-activity/anim.py +++ b/src/anim-activity/anim.py @@ -809,14 +809,13 @@ def general_restore(filename, filetype, fles): def image_selected(image, fles): #fles is used because self is not passed through callback - print "image selected %s" %(image,) - pixmap = gcompris.utils.load_pixmap(image) + #print "image selected %s" %(image,) # Always display the image at the center of the drawing area cx = (fles.drawing_area[2] - fles.drawing_area[0]) / 2 cy = (fles.drawing_area[3] - fles.drawing_area[1]) / 2 - fles.created_object = AnimItemPixmap(fles, cx, cy, pixmap) + fles.created_object = AnimItemPixmap(fles, cx, cy, image) if fles.created_object: fles.created_object.create_item_event(fles.root_drawingitem, |