[postr] Save dragged images as PNG in temporary files
- From: GermÃn Poà CaamaÃo <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [postr] Save dragged images as PNG in temporary files
- Date: Thu, 4 Oct 2012 01:21:30 +0000 (UTC)
commit 54c4353ff6072b2fd368872c5cf9c253bb4a5cde
Author: GermÃn Poo-CaamaÃo <gpoo gnome org>
Date: Wed Oct 3 18:17:29 2012 -0700
Save dragged images as PNG in temporary files
We can determine the right size file and we do not need to
convert it to upload it.
Signed-off-by: GermÃn Poo-CaamaÃo <gpoo gnome org>
https://bugzilla.gnome.org/show_bug.cgi?id=507228
src/postr.py | 29 +++++++++++++++++++++++------
1 files changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/src/postr.py b/src/postr.py
index 8ee87b4..70dd838 100644
--- a/src/postr.py
+++ b/src/postr.py
@@ -20,6 +20,7 @@
import logging, os, urllib
from urlparse import urlparse
from os.path import basename
+from tempfile import mkstemp
from gi.repository import GObject, Gtk, GConf, GdkPixbuf, Gio, Gdk
@@ -164,6 +165,10 @@ class Postr(UniqueApp):
if has_gtkspell:
gtkspell.Spell(self.desc_view)
+ # We create temporary files when we receive images as Pixbufs
+ # (drag & drop). We have to delete them at the of the session.
+ self.temporary_files = []
+
# TODO: remove this
self.current_it = None
self.last_folder = None
@@ -491,6 +496,9 @@ class Postr(UniqueApp):
elif response == Gtk.ResponseType.ACCEPT:
self.save_upload_set()
+ for gfile in self.temporary_files:
+ gfile.delete(None)
+
import twisted.internet.reactor
twisted.internet.reactor.stop()
@@ -875,14 +883,23 @@ class Postr(UniqueApp):
sizes = get_thumb_size(pixbuf.get_width(), pixbuf.get_height(), 64, 64)
thumb = pixbuf.scale_simple(sizes[0], sizes[1], GdkPixbuf.InterpType.BILINEAR)
- # TODO: This is wrong, and should generate a PNG here and use the
- # size of the PNG
- size = pixbuf.get_width() * pixbuf.get_height() * pixbuf.get_n_channels()
+ # Generate a PNG to get the right size file and to send a
+ # smaller image to Flickr
+ filename = mkstemp('-postr.png')[1]
+ pixbuf.savev(filename, 'png', [], [])
+
+ gfile = Gio.File.new_for_path(filename)
+ self.temporary_files.append(gfile)
+
+ fileinfo = gfile.query_info(_FILE_ATTRIBUTES,
+ Gio.FileQueryInfoFlags.NONE, None)
- print selection
+ # TODO: Since we store the pixbuf in a temporary file, we
+ # could just call add_image_file(), once add_image_file()
+ # does not open a file 3 times.
self.model.set(self.model.append(),
- ImageStore.COL_IMAGE, pixbuf,
- ImageStore.COL_SIZE, long(size),
+ ImageStore.COL_SIZE, fileinfo.get_size(),
+ ImageStore.COL_URI, gfile.get_uri(),
ImageStore.COL_PREVIEW, preview,
ImageStore.COL_THUMBNAIL, thumb,
ImageStore.COL_TITLE, "",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]