Tom> Can someone port this do pygtk2? Is enough functions wrapped yet to
    Tom> do this?

    >> from gtk import *
    >> 
    >> def _on_expose(drawingarea, event):
    >> # get the GdkWindow
    >> window = event.window
    >> 
    >> # get the GC
    >> gc = window.new_gc()
    >> 
    >> # create a green color
    >> color = drawingarea.get_colormap().alloc(0x0000, 0xFFFF, 0x0000)
    >> 
    >> # use this color for drawing
    >> gc.foreground = color
    >> 
    >> # draw a line
    >> drawingarea.draw_line(gc, 0, 0, 200, 200)
    >> 
    >> 
    >> # the usual stuff
    >> win = GtkWindow()
    >> win.connect("destroy", mainquit)
    >> win.show()
    >> 
    >> # create the drawing area
    >> drawingarea = GtkDrawingArea()
    >> drawingarea.connect("expose-event", _on_expose)
    >> drawingarea.show()
    >> win.add(drawingarea)
    >> 
    >> # enter the mainloop
    >> mainloop()

I came up with this:

    #!/usr/bin/env python

    import gtk

    def _on_expose(drawingarea, event):
        # get the GdkWindow
        window = event.window

        # get the GC
        gc = window.new_gc()

        # create a green color
        color = gtk.gdk.color_parse("green")

        # use this color for drawing
        gc.foreground = color

        # draw a line
        drawingarea.window.draw_line(gc, 0, 0, 200, 200)


    # the usual stuff
    win = gtk.Window()
    win.connect("destroy", gtk.mainquit)
    win.show()

    # create the drawing area
    drawingarea = gtk.DrawingArea()
    drawingarea.connect("expose-event", _on_expose)
    drawingarea.show()
    win.add(drawingarea)

    # enter the mainloop
    gtk.mainloop()

Everything seems to work (no errors), but the line is drawn in black.  Note
that the DrawingArea widget doesn't support draw_* directly.  I had to dive
into the underlying Gdk widget for that.

Suggested fix(es)?

-- 
Skip Montanaro ([EMAIL PROTECTED])
http://www.mojam.com/
http://www.musi-cal.com/
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to