Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorC. Scott Ananian <cscott@cscott.net>2011-11-10 23:32:00 (GMT)
committer C. Scott Ananian <cscott@cscott.net>2011-11-10 23:32:00 (GMT)
commit5a01e94347c1cd78b0deb4fc64c649536ae6ac1f (patch)
treeec77cf17ef0297019434f4756912039922511683
parent3c3a5f03d1a2605b6773b472548da825199d5855 (diff)
Update Gdk.CairoContext in source (not needed for GTK3).
-rw-r--r--TurtleArt/sprites.py3
-rw-r--r--TurtleArt/tacanvas.py8
-rw-r--r--util/gtkcompat.py7
3 files changed, 13 insertions, 5 deletions
diff --git a/TurtleArt/sprites.py b/TurtleArt/sprites.py
index 9577656..a33b593 100644
--- a/TurtleArt/sprites.py
+++ b/TurtleArt/sprites.py
@@ -334,7 +334,8 @@ class Sprite:
self.rect.x + self._dx[i],
self.rect.y + self._dy[i])
elif _is_pixbuf(img):
- cr.set_source_pixbuf(img,
+ # on GTK2, cr must be a Gdk.CairoContext
+ Gdk.cairo_set_source_pixbuf(cr, img,
self.rect.x + self._dx[i],
self.rect.y + self._dy[i])
# self.surfaces[i] = cr.get_target()
diff --git a/TurtleArt/tacanvas.py b/TurtleArt/tacanvas.py
index 1c545a6..ac20092 100644
--- a/TurtleArt/tacanvas.py
+++ b/TurtleArt/tacanvas.py
@@ -106,7 +106,7 @@ class TurtleGraphics:
# Build a cairo.Context from a cairo.XlibSurface
self.canvas = cairo.Context(self.tw.turtle_canvas)
- cr = Gdk.CairoContext(self.canvas)
+ cr = Gdk.CairoContext(self.canvas) # GTK2 compat
cr.set_line_cap(1) # Set the line cap to be round
self.cx = 0
@@ -527,14 +527,14 @@ class TurtleGraphics:
def draw_pixbuf(self, pixbuf, a, b, x, y, w, h, path, share=True):
''' Draw a pixbuf '''
# Build a Gdk.CairoContext from a cairo.Context to access
- # the set_source_pixbuf attribute.
- cr = Gdk.CairoContext(self.canvas)
+ # the set_source_pixbuf attribute. (GTK2 only)
+ cr = Gdk.CairoContext(self.canvas) # GTK2 compat
cr.save()
# center the rotation on the center of the image
cr.translate(x + w / 2., y + h / 2.)
cr.rotate(self.heading * DEGTOR)
cr.translate(-x - w / 2., -y - h / 2.)
- cr.set_source_pixbuf(pixbuf, x, y)
+ Gdk.cairo_set_source_pixbuf(cr, pixbuf, x, y)
cr.rectangle(x, y, w, h)
cr.fill()
cr.restore()
diff --git a/util/gtkcompat.py b/util/gtkcompat.py
index b55091a..c188a13 100644
--- a/util/gtkcompat.py
+++ b/util/gtkcompat.py
@@ -16,6 +16,10 @@ try:
GObject.TYPE_NONE = None # compatibility hack
class GConf:
pass # XXX no more GConf, sigh
+
+ # No CairoContext wrapper needed for gir/gtk3
+ Gdk.CairoContext = lambda x: x # GTK2 compatibility
+
except ValueError, ImportError:
# fall back to old pygtk, with various evil hacks
import pygtk
@@ -36,6 +40,9 @@ except ValueError, ImportError:
RUN_FIRST = GObject.SIGNAL_RUN_FIRST
GObject.SignalFlags = GObjectSignalFlags
+ Gdk.cairo_set_source_pixbuf = \
+ lambda cr, img, x, y: cr.set_source_pixbuf(img, x, y)
+
class GdkEventMask:
EXPOSURE_MASK = Gdk.EXPOSURE_MASK
BUTTON_PRESS_MASK = Gdk.BUTTON_PRESS_MASK