[cairo-commit] pycairo/examples/cairo_snippets snippets_png.py, 1.4, 1.5 snippets_pdf.py, NONE, 1.1

Steve Chaplin commit at pdx.freedesktop.org
Wed Apr 27 00:34:52 PDT 2005


Committed by: stevech1097

Update of /cvs/cairo/pycairo/examples/cairo_snippets
In directory gabe:/tmp/cvs-serv20093/examples/cairo_snippets

Modified Files:
	snippets_png.py 
Added Files:
	snippets_pdf.py 
Log Message:
SC

Index: snippets_png.py
===================================================================
RCS file: /cvs/cairo/pycairo/examples/cairo_snippets/snippets_png.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- snippets_png.py	27 Apr 2005 03:54:02 -0000	1.4
+++ snippets_png.py	27 Apr 2005 07:34:50 -0000	1.5
@@ -9,7 +9,7 @@
 
 from snippets import snip_list, snippet_normalize, snippet_set_bg_svg
 
-Width, Height = 256, 256
+width, height = 256, 256 # used by snippet_normalize()
 Verbose_mode = True
 
 
@@ -17,16 +17,17 @@
     if Verbose_mode:
         print 'processing %s' % snippet,
     
-    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, Width, Height)
+    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
     cr = cairo.Context()
     cr.set_target_surface(surface)
 
     cr.save()
-
-    width, height = Width, Height
-    
-    execfile ('snippets/%s.py' % snippet, globals(), locals())
-    
+    try:
+        execfile ('snippets/%s.py' % snippet, globals(), locals())
+    except:
+        exc_type, exc_value = sys.exc_info()[:2] 
+        print exc_type, exc_value
+        
     cr.restore()
 
     surface.write_to_png ('snippets/%s.png' % snippet)

--- NEW FILE: snippets_pdf.py ---
#!/usr/bin/env python
"""Python version of cairo-demo/cairo_snippets/cairo_snippets_pdf.c
create a file for each example rather than one large file for all examples
"""
from __future__ import division
from math import pi as M_PI  # used by many snippets
import sys

import cairo

from snippets import snip_list, snippet_normalize, snippet_set_bg_svg

X_inches, Y_inches = 2, 2
X_ppi, Y_ppi = 300, 300
width, height = X_inches * 96, Y_inches * 96  # used by snippet_normalize()

Verbose_mode = True

def do_snippet (snippet):
    if Verbose_mode:
        print 'processing %s' % snippet,
    
    file_obj = file('snippets/%s.pdf' % snippet, 'wb')
    surface = cairo.PDFSurface (file_obj, X_inches, Y_inches, X_ppi, Y_ppi)
    cr = cairo.Context()
    cr.set_target_surface(surface)

    cr.save()
    try:
        execfile ('snippets/%s.py' % snippet, globals(), locals())
    except:
        exc_type, exc_value = sys.exc_info()[:2] 
        print exc_type, exc_value
    
    cr.restore()

    cr.show_page()
    
    surface.finish()
    file_obj.close()

    if Verbose_mode:
        print

if __name__ == '__main__':
    if len(sys.argv) > 1 and sys.argv[1] == '-s':
        Verbose_mode=False
        del sys.argv[1]
    
    if len(sys.argv) > 1: # do specified snippets
        snippet_list = sys.argv[1:]
    else:                 # do all snippets
        snippet_list = snip_list

    for s in snippet_list:
        do_snippet (s)




More information about the cairo-commit mailing list