diff options
author | Aleksey Lim <alsroot@member.fsf.org> | 2009-04-15 15:51:05 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@member.fsf.org> | 2009-04-15 15:51:05 (GMT) |
commit | 1dd6328dd6388f34efc4706e6c31bb79299a3a1d (patch) | |
tree | ed10b8d4b2bd247d87aa968a3cc16f00f47c5d74 /src | |
parent | 2e67241ae1f2ed1fc30469f9e1a8d58792a7853f (diff) | |
parent | 86b4ecd4363ceb4fbdea279cf28f7a3e90793759 (diff) |
Merge branch 'zipfile'
Diffstat (limited to 'src')
-rw-r--r-- | src/BaseThought.py | 5 | ||||
-rw-r--r-- | src/DrawingThought.py | 2 | ||||
-rw-r--r-- | src/ImageThought.py | 92 | ||||
-rw-r--r-- | src/MMapArea.py | 31 | ||||
-rw-r--r-- | src/PeriodicSaveThread.py | 37 | ||||
-rw-r--r-- | src/TextThought.py | 2 |
6 files changed, 55 insertions, 114 deletions
diff --git a/src/BaseThought.py b/src/BaseThought.py index 6e15497..9f5c265 100644 --- a/src/BaseThought.py +++ b/src/BaseThought.py @@ -186,12 +186,15 @@ class BaseThought (gobject.GObject): def draw (self, context): pass - def load (self, node): + def load (self, node, tar): pass def update_save (self): pass + def save (self, tar): + pass + def copy_text (self, clip): pass diff --git a/src/DrawingThought.py b/src/DrawingThought.py index 357d72f..8b2e34e 100644 --- a/src/DrawingThought.py +++ b/src/DrawingThought.py @@ -383,7 +383,7 @@ class DrawingThought (ResizableThought): elem.setAttribute ("color", p.color.to_string()) return - def load (self, node): + def load (self, node, tar): tmp = node.getAttribute ("ul-coords") self.ul = utils.parse_coords (tmp) tmp = node.getAttribute ("lr-coords") diff --git a/src/ImageThought.py b/src/ImageThought.py index 52de5a6..c9c4d07 100644 --- a/src/ImageThought.py +++ b/src/ImageThought.py @@ -26,6 +26,9 @@ import gettext _ = gettext.gettext import cairo import os +import logging +import tempfile +import cStringIO from sugar import mime @@ -50,49 +53,37 @@ class ImageThought (ResizableThought): # FIXME: Work in progress, needs at least activity self to create # tmp files/links in the right places and reference the window. - def journal_open_image (self, filename=None): - if not filename: - self.object_chooser_active = True - if hasattr(mime, 'GENERIC_TYPE_IMAGE'): - chooser = ObjectChooser(_('Choose image'), - what_filter=mime.GENERIC_TYPE_IMAGE) - else: - chooser = ObjectChooser(_('Choose image')) - - try: - result = chooser.run() - if result == gtk.RESPONSE_ACCEPT and chooser.get_selected_object(): - jobject = chooser.get_selected_object() - else: - return False - - if jobject and jobject.file_path: - fname = os.path.join(get_activity_root(), 'tmp', - os.path.basename(jobject.file_path)) - os.rename(jobject.file_path, fname) - else: - return False - finally: - chooser.destroy() - del chooser - self.object_chooser_active = False + def journal_open_image (self): + self.object_chooser_active = True + if hasattr(mime, 'GENERIC_TYPE_IMAGE'): + chooser = ObjectChooser(_('Choose image'), + what_filter=mime.GENERIC_TYPE_IMAGE) else: - fname = filename - - print "fname =",fname + chooser = ObjectChooser(_('Choose image')) try: - self.orig_pic = gtk.gdk.pixbuf_new_from_file (fname) - except: - try: - # lets see if file was imported and is already extracted - fname = utils.get_save_dir() + 'images/' + utils.strip_path_from_file_name(filename) - self.orig_pic = gtk.gdk.pixbuf_new_from_file (fname) - except: + result = chooser.run() + if result == gtk.RESPONSE_ACCEPT and chooser.get_selected_object(): + jobject = chooser.get_selected_object() + else: return False - self.filename = fname - self.text = fname[fname.rfind('/')+1:fname.rfind('.')] + if jobject and jobject.file_path: + logging.debug("journal_open_image: fname=%s" % jobject.file_path) + try: + self.orig_pic = gtk.gdk.pixbuf_new_from_file (jobject.file_path) + self.filename = os.path.join('images', os.path.basename(jobject.file_path)) + except Exception, e: + logging.error("journal_open_image: %s" % e) + return False + else: + return False + finally: + chooser.destroy() + del chooser + self.object_chooser_active = False + + self.text = self.filename[0:self.filename.rfind('.')] self.recalc_edges(True) return True @@ -197,14 +188,18 @@ class ImageThought (ResizableThought): self.element.removeAttribute ("primary_root") except xml.dom.NotFoundErr: pass - return - def load (self, node): + def save (self, tar): + if not [i for i in tar.getnames() if i == self.filename]: + tar.write(self.filename, self.orig_pic) + + def load (self, node, tar): tmp = node.getAttribute ("ul-coords") self.ul = utils.parse_coords (tmp) tmp = node.getAttribute ("lr-coords") self.lr = utils.parse_coords (tmp) - self.filename = node.getAttribute ("file") + self.filename = os.path.join('images', + os.path.basename(node.getAttribute ("file"))) self.identity = int (node.getAttribute ("identity")) try: tmp = node.getAttribute ("background-color") @@ -223,20 +218,9 @@ class ImageThought (ResizableThought): print "Unknown: "+n.nodeName margin = utils.margin_required (utils.STYLE_NORMAL) self.pic_location = (self.ul[0]+margin[0], self.ul[1]+margin[1]) - self.okay = self.journal_open_image (self.filename) + self.orig_pic = tar.read_pixbuf(self.filename) self.lr = (self.pic_location[0]+self.width+margin[2], self.pic_location[1]+self.height+margin[3]) - if not self.okay: - dialog = gtk.MessageDialog (None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, - gtk.MESSAGE_WARNING, gtk.BUTTONS_CLOSE, - _("Error loading file")) - dialog.format_secondary_text (_("%s could not be found. Associated thought will be empty."%self.filename)) - dialog.run () - dialog.hide () - self.pic = None - self.orig_pic = None - else: - self.recalc_edges() - return + self.recalc_edges() def enter (self): self.editing = True diff --git a/src/MMapArea.py b/src/MMapArea.py index d920cdd..a0a16df 100644 --- a/src/MMapArea.py +++ b/src/MMapArea.py @@ -85,12 +85,6 @@ class MMapArea (gtk.DrawingArea): __gsignals__ = dict (title_changed = (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING, )), - doc_save = (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)), - doc_delete = (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, - ()), change_mode = (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT, )), @@ -1011,10 +1005,10 @@ class MMapArea (gtk.DrawingArea): self.invalidate () return True - def load_thought (self, node, type): + def load_thought (self, node, type, tar): thought = self.create_new_thought (None, type, loading = True) thought.creating = False - thought.load (node) + thought.load (node, tar) def load_link (self, node): link = Link (self.save) @@ -1024,16 +1018,16 @@ class MMapArea (gtk.DrawingArea): element = link.get_save_element () self.element.appendChild (element) - def load_thyself (self, top_element, doc): + def load_thyself (self, top_element, doc, tar): for node in top_element.childNodes: if node.nodeName == "thought": - self.load_thought (node, MODE_TEXT) + self.load_thought (node, MODE_TEXT, tar) elif node.nodeName == "image_thought": - self.load_thought (node, MODE_IMAGE) + self.load_thought (node, MODE_IMAGE, tar) elif node.nodeName == "drawing_thought": - self.load_thought (node, MODE_DRAW) + self.load_thought (node, MODE_DRAW, tar) elif node.nodeName == "res_thought": - self.load_thought (node, MODE_RESOURCE) + self.load_thought (node, MODE_RESOURCE, tar) elif node.nodeName == "link": self.load_link (node) else: @@ -1084,18 +1078,15 @@ class MMapArea (gtk.DrawingArea): for l in del_links: self.delete_link (l) - def prepare_save(self): + def update_save(self): for t in self.thoughts: t.update_save () for l in self.links: l.update_save () - def save_thyself (self): - self.prepare_save() - if len(self.thoughts) > 0: - self.emit ("doc_save", self.save, self.element) - else: - self.emit ("doc_delete") + def save_thyself(self, tar): + for t in self.thoughts: + t.save(tar) def text_selection_cb (self, thought, start, end, text): self.emit ("text_selection_changed", start, end, text) diff --git a/src/PeriodicSaveThread.py b/src/PeriodicSaveThread.py deleted file mode 100644 index 1747e90..0000000 --- a/src/PeriodicSaveThread.py +++ /dev/null @@ -1,37 +0,0 @@ -# PeriodicSaveThread.py -# This file is part of Labyrinth -# -# Copyright (C) 2008 - Labyrinth-Dev-Team -# -# Labyrinth is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# Labyrinth is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Labyrinth; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, -# Boston, MA 02110-1301 USA -# - -import threading -import time - -class PeriodicSaveThread(threading.Thread): - - def __init__(self, main_area): - threading.Thread.__init__(self) - self.main_area = main_area - self.cancel = False - - def run (self): - time.sleep (60) - while not self.cancel: - self.main_area.save_thyself () - time.sleep (60) - diff --git a/src/TextThought.py b/src/TextThought.py index 38b0ca7..59fb914 100644 --- a/src/TextThought.py +++ b/src/TextThought.py @@ -886,7 +886,7 @@ class TextThought (ResizableThought): self.bindex = self.b_f_i (self.index) self.text = tmp - def load (self, node): + def load (self, node, tar): self.index = int (node.getAttribute ("cursor")) self.end_index = self.index tmp = node.getAttribute ("ul-coords") |