Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Francis <francis@sugarlabs.org>2012-06-03 23:39:29 (GMT)
committer Daniel Francis <francis@sugarlabs.org>2012-06-03 23:39:29 (GMT)
commit0688745b73dc153e9239978006bdfb3532b16fd6 (patch)
treed4134c9024846ba175ae4a6801fb7fbd991202c8
parent029969fd533cfda6ef5bd2862294a9b9dd0c1afe (diff)
Saving and reading frames in journal
-rw-r--r--TODO3
-rw-r--r--activity.py25
-rw-r--r--animation.py3
3 files changed, 27 insertions, 4 deletions
diff --git a/TODO b/TODO
index 717f620..9f3503a 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,7 @@
New functions:
- - Save data in journal
+ - Export to other formats.
Fixes:
- Enable drag and drop between frames.
Bugs:
+ - Save correctly if the frames sequence if running inverse.
- Doesn't select another frame when the last frame is removed.
diff --git a/activity.py b/activity.py
index 5663d75..4cfbda4 100644
--- a/activity.py
+++ b/activity.py
@@ -116,6 +116,7 @@ class AnimateActivity(activity.Activity):
options_toolbar.insert(pingpong, -1)
self.modes_buttons = [normalmode, returnbutton, pingpong]
+ self.animation_mode = animation.RETURN_MODE
separator = gtk.SeparatorToolItem()
options_toolbar.insert(separator, -1)
@@ -163,6 +164,7 @@ class AnimateActivity(activity.Activity):
canvas = gtk.HBox()
self._animation = None
+ self._animation_frames = []
self._frames_list = FramesList()
self._frames_list.show()
@@ -186,12 +188,29 @@ class AnimateActivity(activity.Activity):
finally:
temp_file.close()
zfile.write(temp_file_path, 'config')
+ frames_path = tempfile.mktemp()
+ count = 0
+ for i in self._animation.images:
+ i.save(frames_path, 'png')
+ zfile.write(frames_path, 'frames/%d.png' % count)
+ count += 1
zfile.close()
os.remove(temp_file_path)
def read_file(self, file_path):
zfile = zipfile.ZipFile(file_path, 'r')
+ frames = zfile.namelist()
+ del(frames[frames.index('config')])
+ temp_frames_path = tempfile.mktemp()
+ for frame in frames:
+ frame_content = zfile.read(frame)
+ frame_file = open(temp_frames_path, 'w')
+ frame_file.write(frame_content)
+ frame_file.close()
+ pixbuf = gtk.gdk.pixbuf_new_from_file(temp_frames_path)
+ self._animation_frames.append(pixbuf)
+
str_io = StringIO(zfile.read('config'))
zfile.close()
@@ -215,7 +234,7 @@ class AnimateActivity(activity.Activity):
if result == gtk.RESPONSE_ACCEPT:
jobject = chooser.get_selected_object()
pixbuf = gtk.gdk.pixbuf_new_from_file(jobject.get_file_path())
- self._animation.add_image(jobject.get_file_path())
+ self._animation.add_image(pixbuf)
self._frames_list.add_frame(pixbuf)
else:
return
@@ -265,6 +284,10 @@ class AnimateActivity(activity.Activity):
if not self._animation:
self._animation = animation.Animation(width, height)
self._animation.set_mode(self._animation_mode)
+ for pixbuf in self._animation_frames:
+ self._animation.add_image(pixbuf)
+ self._frames_list.add_frame(pixbuf)
+ self._animation.set_fps(self._fpsbutton.get_value())
self._animation.show_all()
del self._animation_mode
diff --git a/animation.py b/animation.py
index f59e566..588dae4 100644
--- a/animation.py
+++ b/animation.py
@@ -101,9 +101,8 @@ class Animation(gtk.Image):
# Redraw image:
self.set_pos(self._current_image)
- def add_image(self, image_path):
+ def add_image(self, pixbuf):
"""Appends an image to the list"""
- pixbuf = gtk.gdk.pixbuf_new_from_file(image_path)
self.images.append(pixbuf)
def run(self):