import gtk import cairo import array #import goocanvas import weakref import gc def fini(foo): print "data is no more", foo def create_stipple(): color = gtk.gdk.color_parse ("mediumseagreen") stipple_data = array.array('B', [0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255]) stipple_data[2] = stipple_data[14] = color.red >> 8 stipple_data[1] = stipple_data[13] = color.green >> 8 stipple_data[0] = stipple_data[12] = color.blue >> 8 print stipple_data.tolist() surface = cairo.ImageSurface.create_for_data (stipple_data, cairo.FORMAT_ARGB32, 2, 2, 8) pattern = cairo.SurfacePattern(surface) pattern.set_extend (cairo.EXTEND_REPEAT) data = weakref.ref(stipple_data, fini) return pattern # w = gtk.Window() # w.connect("destroy", gtk.main_quit) # c = goocanvas.Canvas(automatic_bounds = True, # bounds_from_origin = False, # bounds_padding = 4.0, # background_color_rgb = 0xC3C3FF) print "Creating pattern" pattern = create_stipple() print "Pattern created" print "Deleting pattern" del pattern while gc.collect(): pass print "Pattern deleted" # root = c.get_root_item() # r = goocanvas.Rect(parent = root, # x = 90, # y = 40, # width = 90, # height = 60, # fill_pattern = pattern, # stroke_color = "black", # line_width = 4.0) # w.add(c) # w.show_all() # gtk.main()