Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Coudoin <bruno.coudoin@free.fr>2009-10-31 22:39:31 (GMT)
committer Bruno Coudoin <bruno.coudoin@free.fr>2009-10-31 22:39:31 (GMT)
commit914f22c5ca24da2dcef7c13ce3a00f61f5140511 (patch)
treef9e1c8ba54ee770b8e10fb4a01c99e21b28e6d58
parent6c0bf5ed3a2573a3a190bb60801a9d94dc37a5c0 (diff)
Improved version of the save feature. Now can save / Load multiple items and frames.
What does not work yet is the colors of the items. Added a feature to let the children specify the last frame to display by right clicking on a frame.
-rw-r--r--src/anim-activity/AnimItem.py64
-rw-r--r--src/anim-activity/Timeline.py29
-rw-r--r--src/anim-activity/anim.py2
-rw-r--r--src/anim-activity/anim.xml.in2
4 files changed, 76 insertions, 21 deletions
diff --git a/src/anim-activity/AnimItem.py b/src/anim-activity/AnimItem.py
index d359371..0759906 100644
--- a/src/anim-activity/AnimItem.py
+++ b/src/anim-activity/AnimItem.py
@@ -32,10 +32,22 @@ class AnimItem:
anim = None
def __init__(self, anim_):
+ self.init(anim_)
+ gcompris.sound.play_ogg("sounds/bleep.wav")
+ # We keep the timeline index to which we are visible
+ # This is a list of tuple (from, to)
+ self.visible = []
+
+ # The timeline store the state of this item in time.
+ # The key is the time (number) and the value is a tuple
+ # (properties, transformation).
+ self.timeline = {}
+
+
+ def init(self, anim_):
AnimItem.anim = anim_
self.rootitem = goocanvas.Group(parent = anim_.rootitem)
self.drawing_area = anim_.drawing_area
- gcompris.sound.play_ogg("sounds/bleep.wav")
self.step = 1
@@ -45,31 +57,53 @@ class AnimItem:
self.old_x = 0
self.old_y = 0
- # We keep the timeline index to which we are visible
- # This is a list of tuple (from, to)
- self.visible = []
- # The timeline store the state of this item in time.
- # The key is the time (number) and the value is a tuple
- # (properties, transformation).
- self.timeline = {}
+ # Sadly matrix are not saved by pickle, don't know why
+ # excactly. This code transform the matrix as a regular
+ # python list.
+ def matrixDump(self, m):
+ return [m[0],m[1],m[2],m[3],m[4],m[5]]
+
+ # Sadly matrix are not saved by pickle, don't know why
+ # excactly. This code transform a python list to
+ # a cairo matrix.
+ def matrixRestore(self, m):
+ return cairo.Matrix(m[0], m[1], m[2],
+ m[3], m[4], m[5])
+
+ def timelineDump(self, timeline):
+ result = {}
+ for k, v in timeline.iteritems():
+ result[k] = [v[0], self.matrixDump(v[1])]
+ return result
+
+ def timelineRestore(self, timeline):
+ result = {}
+ for k, v in timeline.iteritems():
+ result[k] = [v[0], self.matrixRestore(v[1])]
+ return result
+
+ def __getstate__(self):
+ print self.timeline
+ return [self.visible, self.timelineDump(self.timeline)]
+
+ def __setstate__(self, dict):
+ self.visible = dict[0]
+ self.timeline = self.timelineRestore(dict[1])
+ self.anchor = None
def dump(self):
print "Dump AnimItem:"
print self.timeline
- print self.item
- print self.rootitem
+ pass
+
def restore(self, anim_):
print "restore AnimItem:"
print self.timeline
- AnimItem.anim = anim_
+ self.init(anim_)
print AnimItem.anim
print AnimItem.anim.rootitem
- self.rootitem = goocanvas.Group(parent = AnimItem.anim.rootitem)
- # Should not have saved anchor in the first place
- self.anchor = None
- pass
def test(self):
self.set_visible(0, 10)
diff --git a/src/anim-activity/Timeline.py b/src/anim-activity/Timeline.py
index 3a69ea1..7ab1d37 100644
--- a/src/anim-activity/Timeline.py
+++ b/src/anim-activity/Timeline.py
@@ -39,6 +39,7 @@ class Timeline:
self.selected = None
self.timelinelist = []
self.current_time = 0
+ self.last_mark = -1
def hide(self):
self.rootitem.props.visibility = goocanvas.ITEM_INVISIBLE
@@ -51,6 +52,8 @@ class Timeline:
self.selected_color = 0x3030AAFFL
self.default_color = 0xFFFFFFFFL
+ self.default_stroke = 0x101080FFL
+ self.marked_stroke = 0xC01010FFL
# Timeline coord
x1 = self.drawing_area[0]
@@ -78,7 +81,7 @@ class Timeline:
width = w,
height = h,
fill_color_rgba = self.default_color,
- stroke_color_rgba = 0x101080FFL,
+ stroke_color_rgba = self.default_stroke,
line_width=1.0,
radius_x=3.0,
radius_y=3.0)
@@ -98,17 +101,19 @@ class Timeline:
# Select the first item in the timeline
self.current_time = 0
self.select_it(self.selected)
+ self.lastmark_it(self.timelinelist[t-1])
# Return the current selected time
def get_time(self):
return self.current_time
def set_time(self, time):
- self.select_it(item, self.timelinelist[time])
+ self.select_it(self.timelinelist[time])
def next(self):
self.current_time += 1
- if self.current_time >= len(self.timelinelist):
+ if self.current_time >= min(len(self.timelinelist),
+ self.last_mark + 1):
self.current_time = 0
self.select_it(self.timelinelist[self.current_time])
@@ -132,9 +137,23 @@ class Timeline:
# Let anim knows there is a new time set
self.anim.refresh(self.get_time())
+ def lastmark_it(self, item):
+ # Unmark previous mark
+ if self.last_mark >= 0:
+ marked_item = self.timelinelist[self.last_mark]
+ marked_item.set_properties(stroke_color_rgba = self.default_stroke)
+
+ item.set_properties(stroke_color_rgba = self.marked_stroke)
+ self.last_mark = item.get_data("time")
+
+ def get_last_mark(self):
+ return self.last_mark
+
#
def timeline_item_event(self, item, target, event):
- self.select_it(item)
-
+ if event.button == 1:
+ self.select_it(item)
+ else:
+ self.lastmark_it(item)
diff --git a/src/anim-activity/anim.py b/src/anim-activity/anim.py
index f8b68e0..4e0111d 100644
--- a/src/anim-activity/anim.py
+++ b/src/anim-activity/anim.py
@@ -764,6 +764,8 @@ class Gcompris_anim:
if 'desc' != fles.format_string['gcompris']:
if (desc == 'GCompris draw 3 cPikle file'
or desc == 'GCompris anim 3 cPikle file'):
+ for item in self.animlist:
+ item.delete()
print "load"
self.animlist = pickle.load(file)
for item in self.animlist:
diff --git a/src/anim-activity/anim.xml.in b/src/anim-activity/anim.xml.in
index 6d52b3c..52d58bd 100644
--- a/src/anim-activity/anim.xml.in
+++ b/src/anim-activity/anim.xml.in
@@ -13,6 +13,6 @@
<_description>Free drawing and animation tool.</_description>
<_prerequisite>Needs to be capable of moving and clicking the mouse easily</_prerequisite>
<_goal>In this game, children can draw freely. The goal is to discover how to create attractive drawings based on basic shapes: rectangles, ellipses and lines. To give children a wider range of choices, a set of images can also be used.</_goal>
- <_manual>Select a drawing tool on the left, and a color down the bottom. Then click and drag in the white area to create a new shape. Once you've completed a drawing, you can take a snapshot of it with the 'camera' button. This creates a new image with the same content, a copy of your image. You can then edit it by moving objects a little bit or adding/deleting objects. When you create several drawings and then click on the 'film' button, you will see all your images in a continuous slide-show (an infinite loop pattern). You can also change the viewing speed in this mode. In viewing mode, click on the 'drawing' button to return to drawing mode. You can then edit each image in your animation, by using the image selector in the bottom-left corner of the screen. You can also save and reload your animations with the 'floppy disk' and 'folder' buttons.</_manual>
+ <_manual>Select a drawing tool on the left, and a color down the bottom. Then click and drag in the white area to create a new shape. Once you've completed a drawing, you can select a new frame to work on by selecting one of the small rectangles on the bottom. Each frame contains the same content as its previous one. You can then edit it by moving objects a little bit or adding/deleting objects. When you create several frames and then click on the 'film' button, you will see all your images in a continuous slide-show (an infinite loop pattern). You can change the last image in your film by right clicking on a time frame. You can also change the viewing speed in this mode. In viewing mode, click on the 'drawing' button to return to drawing mode. You can also save and reload your animations with the 'floppy disk' and 'folder' buttons.</_manual>
</Board>
</GCompris>