[cairo-commit] pycairo/examples/gtk cairo-demo.py, 1.7,
1.8 cairo-knockout.py, 1.11, 1.12 hangman.py, 1.7,
1.8 lsystem.py, 1.7, 1.8 png_view.py, 1.9, 1.10 text.py, 1.8, 1.9
Steve Chaplin
commit at pdx.freedesktop.org
Sun Aug 28 19:31:22 PDT 2005
Committed by: stevech1097
Update of /cvs/cairo/pycairo/examples/gtk
In directory gabe:/tmp/cvs-serv753/examples/gtk
Modified Files:
cairo-demo.py cairo-knockout.py hangman.py lsystem.py
png_view.py text.py
Log Message:
'SC'
Index: cairo-demo.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/gtk/cairo-demo.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- cairo-demo.py 9 Aug 2005 14:37:55 -0000 1.7
+++ cairo-demo.py 29 Aug 2005 02:31:19 -0000 1.8
@@ -1,9 +1,10 @@
#!/usr/bin/env python
"""Based on cairo-demo/X11/cairo-demo.c
"""
-import gtk
import cairo
-import cairo.gtk
+import gtk
+if gtk.pygtk_version < (2,7,0):
+ import cairo.gtk
SIZE = 30
@@ -78,14 +79,14 @@
def stroke_shapes(ctx, x, y):
draw_shapes(ctx, x, y, False)
-def expose(drawingarea, event):
- drawable = drawingarea.window
- width = drawingarea.allocation.width
- height = drawingarea.allocation.height
+def expose (da, event):
+ x, y, width, height = da.allocation
- drawable.clear()
+ if gtk.pygtk_version >= (2,7,0):
+ ctx = da.window.cairo_create()
+ else:
+ ctx = cairo.gtk.gdk_cairo_create(da.window)
- ctx = cairo.gtk.gdk_cairo_create(drawable)
ctx.set_source_rgb(0, 0, 0)
ctx.set_line_width(SIZE / 4)
@@ -113,7 +114,7 @@
def main():
win = gtk.Window()
- win.connect('destroy', lambda x: gtk.main_quit())
+ win.connect('destroy', gtk.main_quit)
win.set_default_size(450, 550)
drawingarea = gtk.DrawingArea()
Index: cairo-knockout.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/gtk/cairo-knockout.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- cairo-knockout.py 9 Aug 2005 14:37:55 -0000 1.11
+++ cairo-knockout.py 29 Aug 2005 02:31:20 -0000 1.12
@@ -6,9 +6,10 @@
import math
import sys
-import gtk
import cairo
-import cairo.gtk
+import gtk
+if gtk.pygtk_version < (2,7,0):
+ import cairo.gtk
def oval_path(ctx, xc, yc, xr, yr):
@@ -105,7 +106,10 @@
ctx.paint()
def expose(drawingarea, event):
- ctx = cairo.gtk.gdk_cairo_create(drawingarea.window)
+ if gtk.pygtk_version >= (2,7,0):
+ ctx = drawingarea.window.cairo_create()
+ else:
+ ctx = cairo.gtk.gdk_cairo_create(drawingarea.window)
draw (ctx, drawingarea.allocation.width, drawingarea.allocation.height)
Index: hangman.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/gtk/hangman.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- hangman.py 22 Jun 2005 00:48:07 -0000 1.7
+++ hangman.py 29 Aug 2005 02:31:20 -0000 1.8
@@ -27,9 +27,10 @@
from math import pi
from random import randint
-import gtk
import cairo
-import cairo.gtk
+import gtk
+if gtk.pygtk_version < (2,7,0):
+ import cairo.gtk
letters_guessed = ""
letters_guessed_right = ""
@@ -38,7 +39,7 @@
body_parts = 6
words = ['cairo', 'graphics', 'pencil', 'keyboard', 'science', 'ricochet', 'flood', 'president', 'sanity']
-idxRandom = randint(0, len(words) -1)
+idxRandom = randint(0, len(words) -1)
word_chosen = words[idxRandom]
#print "The secret word is " + word_chosen
@@ -65,9 +66,12 @@
size = height
pixmap = gtk.gdk.Pixmap (widget.window, width, height)
-
- ctx = cairo.gtk.gdk_cairo_create(pixmap)
-
+
+ if gtk.pygtk_version >= (2,7,0):
+ ctx = pixmap.cairo_create()
+ else:
+ ctx = cairo.gtk.gdk_cairo_create(pixmap)
+
# set the background
ctx.set_source_rgb(0.7,0.7,0.7)
ctx.rectangle(0,0,width, height)
@@ -93,7 +97,7 @@
else:
ctx.move_to(idxLetter * 15, 150)
ctx.show_text('_')
-
+
# Draw Letters Guessed
ctx.move_to(0, 160)
@@ -138,7 +142,7 @@
ctx.line_to(130, 130)
ctx.set_source_rgb(0, 0, 0)
ctx.stroke()
-
+
# Draw 2nd stair
ctx.move_to(50, 130)
@@ -146,7 +150,7 @@
ctx.line_to(60, 121)
ctx.line_to(130, 121)
ctx.stroke()
-
+
# Draw 3rd stair
ctx.move_to(60, 121)
@@ -154,9 +158,9 @@
ctx.line_to(70, 113)
ctx.line_to(130, 113)
ctx.stroke()
-
+
# Draw 4th(top) stair
-
+
ctx.move_to(70, 113)
ctx.line_to(70, 105)
ctx.line_to(130, 105)
@@ -189,7 +193,7 @@
ctx.move_to(100.5, 19)
ctx.line_to(99.5, 21)
ctx.line_to(100.5, 21)
-
+
# Draw Mouth
if len(letters_guessed_wrong) < 6:
@@ -201,7 +205,7 @@
ctx.move_to(100.5, 24)
ctx.arc(100, 24, .5, 0, 2*pi)
ctx.set_line_width(.5)
- ctx.stroke()
+ ctx.stroke()
ctx.set_source_rgb(0, 0, 0)
ctx.set_line_width(1)
@@ -233,7 +237,7 @@
ctx.move_to(100, 70)
ctx.line_to(112, 95)
ctx.stroke()
-
+
# Draw Leg 2
if len(letters_guessed_wrong) > 5:
@@ -243,7 +247,7 @@
# draw pixmap to gdk.window
gc = gtk.gdk.GC(widget.window)
- widget.window.draw_drawable(gc, pixmap, 0,0, 0,0, -1,-1)
+ widget.window.draw_drawable(gc, pixmap, 0,0, 0,0, -1,-1)
win = gtk.Window()
@@ -255,6 +259,6 @@
win.add(drawingarea)
drawingarea.connect('expose_event', expose_event)
drawingarea.set_size_request(300,320)
-
+
win.show_all()
gtk.main()
Index: lsystem.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/gtk/lsystem.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- lsystem.py 9 Aug 2005 14:37:55 -0000 1.7
+++ lsystem.py 29 Aug 2005 02:31:20 -0000 1.8
@@ -1,8 +1,9 @@
#!/usr/bin/env python
-import gtk
import cairo
-import cairo.gtk
+import gtk
+if gtk.pygtk_version < (2,7,0):
+ import cairo.gtk
# Copyright 2003 Jesse Andrews (jdandr2 at uky.edu) under GPL
@@ -24,12 +25,12 @@
def expose( self, drawingarea, event ):
drawable = drawingarea.window
- width = drawingarea.allocation.width
- height = drawingarea.allocation.height
-
- drawable.clear()
+ x, y, width, height = drawingarea.allocation
- ctx = cairo.gtk.gdk_cairo_create(drawable)
+ if gtk.pygtk_version >= (2,7,0):
+ ctx = drawable.cairo_create()
+ else:
+ ctx = cairo.gtk.gdk_cairo_create(drawable)
ctx.set_source_rgb(0, 0, 0)
Index: png_view.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/gtk/png_view.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- png_view.py 9 Aug 2005 14:37:55 -0000 1.9
+++ png_view.py 29 Aug 2005 02:31:20 -0000 1.10
@@ -4,14 +4,17 @@
import sys
-import gtk
import cairo
-import cairo.gtk
+import gtk
+if gtk.pygtk_version < (2,7,0):
+ import cairo.gtk
-def expose_event(widget, event, surface):
- widget.window.clear()
- ctx = cairo.gtk.gdk_cairo_create(widget.window)
+def expose_event(widget, event, surface):
+ if gtk.pygtk_version >= (2,7,0):
+ ctx = widget.window.cairo_create()
+ else:
+ ctx = cairo.gtk.gdk_cairo_create(widget.window)
ctx.set_source_surface(surface, 0,0)
ctx.paint()
@@ -26,7 +29,7 @@
Height = surface.get_height()
win = gtk.Window()
-win.connect('destroy', lambda x: gtk.main_quit())
+win.connect('destroy', gtk.main_quit)
drawingarea = gtk.DrawingArea()
win.add(drawingarea)
Index: text.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/gtk/text.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- text.py 9 Aug 2005 14:37:55 -0000 1.8
+++ text.py 29 Aug 2005 02:31:20 -0000 1.9
@@ -1,13 +1,15 @@
#!/usr/bin/env python
-import gtk
import cairo
-import cairo.gtk
+import gtk
+if gtk.pygtk_version < (2,7,0):
+ import cairo.gtk
def expose_event(widget, event):
- widget.window.clear()
-
- ctx = cairo.gtk.gdk_cairo_create(widget.window)
+ if gtk.pygtk_version >= (2,7,0):
+ ctx = widget.window.cairo_create()
+ else:
+ ctx = cairo.gtk.gdk_cairo_create(widget.window)
ctx.set_line_width(6)
ctx.set_tolerance(.1)
@@ -32,7 +34,7 @@
ctx.show_text('Hello World')
win = gtk.Window()
-win.connect('destroy', lambda x: gtk.main_quit())
+win.connect('destroy', gtk.main_quit)
drawingarea = gtk.DrawingArea()
win.add(drawingarea)
More information about the cairo-commit
mailing list