Hi John,

Thanks for the input.

I tried what was recommended, using a DrawingArea.window as the drawable, drawing to 
this, and then get_from_drawable to the pixbuf.  I display the DrawingArea to another 
window and the line shows up fine.  The window displaying the derived pixbuf doesn't 
show it...  The code follows (python 2.2, gtk 2.0):

#!/usr/bin/env python

import sys, pygtk

pygtk.require("2.0")

import gtk

def delete_event(win, event=None):
    gtk.mainquit()

def expose_handler(widget, *args):
    #print "widget e_h", widget, args
    gc=widget.window.new_gc()
    colormap=widget.get_colormap()
    red=colormap.alloc_color("red")
    alloc=widget.get_allocation()
    x0=alloc[0]
    y0=alloc[1]
    x1=alloc[2]
    y1=alloc[3]
    #print "x0",x0,"y0",y0,"x1",x1,"y1",y1
    gc.set_foreground(red)
    widget.window.draw_line(gc,x0,y0,x1,y1)
    
def do_display(pixbuf, name):
    win=gtk.Window()
    win.connect("delete_event",delete_event)
    win.set_title(name)

    box=gtk.VBox()
    win.add(box)

    swin=gtk.ScrolledWindow()
    box.pack_start(swin, gtk.TRUE, gtk.TRUE, 0)

    image=gtk.Image()
    image.set_from_pixbuf(pixbuf)

    swin.add_with_viewport(image)
    win.set_default_size(600,480)

    win.show_all()


# window to hold drawable
window=gtk.Window()

# drawingarea used to draw graphics to be exported to pixbuf
drawingarea=gtk.DrawingArea()
drawingarea.set_size_request(1000,1000)
drawingarea.connect("expose-event",expose_handler)

window.add(drawingarea)
window.show_all()
#window.hide()

# get ready to draw graphics
drawable=drawingarea.window
colormap=drawable.get_colormap()
red=colormap.alloc_color("red")
print drawingarea.get_parent_window()
#drawingarea.set_size_request(1000,1000)
#alloc=drawingarea.get_allocation()
#print alloc[0],alloc[1],alloc[2],alloc[3]
gc=drawable.new_gc()
gc.set_foreground(red)
drawable.draw_line(gc,0,0,1000,1000)

# create pixbuf and transfer data to it
pixbuf=gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,0,8,1000,1000)
pixbuf=pixbuf.get_from_drawable(drawable,colormap,0,0,0,0,1000,1000)
print "height", pixbuf.get_height()
fname="Test"

# display pixbuf in scrolled window
do_display(pixbuf,fname)

gtk.mainloop()



On Wed, 21 Jan 2004 21:34:17 -0600
John Hunter <[EMAIL PROTECTED]> wrote:

> >>>>> "Luc" == Luc Lefebvre <[EMAIL PROTECTED]> writes:
> 
>     Luc> I would like to set the contents of the pixbuf with
>     Luc> draw_lines from a series of points.  There has to be a way of
>     Luc> doing this but I've been reading for a few days and trying
>     Luc> things, and have managed to get myself even more confused.
> 
> Sorry, this is off the cuff, but here's the basic idea
> 
> Draw to a gtk.gdk.Drawable as usual
> 
>     drawable.draw_lines(gc, zip(x, y))
> 
> Then draw to the pixbuf from the drawable
> 
>     pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8, width, height) 
>     pixbuf.get_from_drawable(
>         drawable, drawable.get_colormap(), 0, 0, 0, 0, width, height)
> 
> Hope this helps,
> JDH


-- 
Luc Lefebvre

In the beginner's mind there are many possibilities,
in the expert's mind there are few.                     <Shunryu Suzuki>

Key fingerprint = D2E5 5E35 B910 6F4E 0242  EC63 0FD9 96D0 C7F4 784E
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to