Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSayamindu Dasgupta <sayamindu@gmail.com>2008-11-21 18:17:13 (GMT)
committer Sayamindu Dasgupta <sayamindu@gmail.com>2008-11-21 18:17:13 (GMT)
commit23048ad63a65548fffcf84ab90503722745d3a01 (patch)
treed4d62adbea206e13f934672e912605aa4bce9e1d
parent7a671156401046578743c7ab3b589c3f4da8829e (diff)
Initial Journal support
-rw-r--r--ImageViewerActivity.py57
1 files changed, 42 insertions, 15 deletions
diff --git a/ImageViewerActivity.py b/ImageViewerActivity.py
index cdb23a1..1f4e62f 100644
--- a/ImageViewerActivity.py
+++ b/ImageViewerActivity.py
@@ -21,8 +21,9 @@ import logging
from gettext import gettext as _
+import time
import sys, os
-import gtk
+import gtk, gobject
import ImageView
import ImageViewerToolbar
@@ -33,7 +34,9 @@ class ImageViewerActivity(activity.Activity):
activity.Activity.__init__(self, handle)
self.zoom = None
-
+ self._tempfile = None
+ self._close_requested = False
+
self.view = ImageView.ImageViewer()
toolbox = activity.ActivityToolbox(self)
@@ -60,20 +63,44 @@ class ImageViewerActivity(activity.Activity):
self.sw.show_all()
+
def read_file(self, file_path):
- self.view.set_file_location(file_path)
-
- #self.zoom = int(self.metadata.get('zoom', '0'))
- #if self.zoom == 0:
- # self.zoom = self.view.get_property('zoom')
- #else:
- # self.view.set_zoom(self.zoom)
-
- #def write_file(self, file_path):
- #try:
- # self.metadata['zoom'] = str(self.zoom)
- #except Exception, e:
- # logging.error('write_file(): %s', e)
+ tempfile = os.path.join(self.get_activity_root(), 'instance', \
+ 'tmp%i' % time.time())
+
+ os.link(file_path, tempfile)
+ self._tempfile = tempfile
+
+ self.view.set_file_location(self._tempfile)
+
+ self.zoom = int(self.metadata.get('zoom', '0'))
+ if self.zoom > 0:
+ self.view.set_zoom(self.zoom)
+
+ def write_file(self, file_path):
+ if self._tempfile is None:
+ # Stolen from Read to avoid Keep error
+ raise NotImplementedError
+
+ try:
+ self.metadata['zoom'] = str(self.zoom)
+ except Exception, e:
+ logging.error('write_file(): %s', e)
+
+ os.link(self._tempfile, file_path)
+
+ if self._close_requested:
+ os.unlink(self._tempfile)
+ self._tempfile = None
+
+ def can_close(self):
+ """
+ Prepare to cleanup on closing.
+ Called from self.close()
+ """
+ self._close_requested = True
+ return True
+
def __view_toolbar_go_fullscreen_cb(self, view_toolbar):
self._old_zoom = self.view.get_property('zoom') #XXX: Hack