Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/toolkit/pixbuf.py
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/pixbuf.py')
-rw-r--r--toolkit/pixbuf.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/toolkit/pixbuf.py b/toolkit/pixbuf.py
index c3bb7d1..c9b9a78 100644
--- a/toolkit/pixbuf.py
+++ b/toolkit/pixbuf.py
@@ -18,14 +18,17 @@
import re
import cStringIO
-import gtk
-import rsvg
import cairo
import logging
-from sugar.graphics import style
-from sugar.graphics.xocolor import XoColor, is_valid
-from sugar.util import LRU
+import gi
+from gi.repository import Gtk
+from gi.repository import GdkPixbuf
+from gi.repository import Rsvg
+
+from sugar3.graphics import style
+from sugar3.graphics.xocolor import XoColor, is_valid
+from sugar3.util import LRU
def to_file(pixbuf):
@@ -47,20 +50,23 @@ def to_str(pixbuf):
def from_str(str):
"""Convert string to pixbuf object"""
- loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/png')
+ loader = GdkPixbuf.PixbufLoader.new_with_mime_type('image/png')
try:
loader.write(str)
+
except Exception, e:
logging.error('pixbuf.from_str: %s' % e)
return None
+
finally:
loader.close()
return loader.get_pixbuf()
-def at_size_with_ratio(pixbuf, width, height, type=gtk.gdk.INTERP_BILINEAR):
+def at_size_with_ratio(pixbuf, width, height, type=GdkPixbuf.InterpType.BILINEAR):
+
image_width = pixbuf.get_width()
image_height = pixbuf.get_height()
@@ -71,6 +77,7 @@ def at_size_with_ratio(pixbuf, width, height, type=gtk.gdk.INTERP_BILINEAR):
if ratio_width != ratio:
ratio_width = ratio
width = int(image_width * ratio)
+
elif ratio_height != ratio:
ratio_height = ratio
height = int(image_height * ratio)
@@ -82,7 +89,7 @@ def from_svg_at_size(filename=None, width=None, height=None, handle=None,
"""Scale and load SVG into pixbuf"""
if not handle:
- handle = rsvg.Handle(filename)
+ handle = Rsvg.Handle(filename)
dimensions = handle.get_dimension_data()
icon_width = dimensions[0]
@@ -97,6 +104,7 @@ def from_svg_at_size(filename=None, width=None, height=None, handle=None,
if ratio_width != ratio:
ratio_width = ratio
width = int(icon_width * ratio)
+
elif ratio_height != ratio:
ratio_height = ratio
height = int(icon_height * ratio)
@@ -109,7 +117,7 @@ def from_svg_at_size(filename=None, width=None, height=None, handle=None,
context.scale(ratio_width, ratio_height)
handle.render_cairo(context)
- loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/png')
+ loader = GdkPixbuf.PixbufLoader.new_with_mime_type('image/png')
surface.write_to_png(loader)
loader.close()