On Mon, Mar 10, 2008 at 10:09 AM, Victor Lazzarini
<[EMAIL PROTECTED]> wrote:
>  what would be the best bet for going about implementing
>  structured graphics a-la Tkinter's canvas class in XO
>  activities? Would it be PyCairo? or PyGTK (gtk/gdk)?
>
>  also could anyone point to a PyGTK custom widget
>  tutorial somewhere? I had a look at one in
>  http://www.learningpython.com/2006/07/25/writing-a-custom-widget-using-pygtk/
>
>  but the code wouldn't work. Are there others?

goocanvas is another option; it's what I used for my icon-editor activity.

Attached is the goocanvas 'hello, world' activity using goocanvas'
python bindings.
 --scott

-- 
                         ( http://cscott.net/ )
#!/usr/bin/python2.5
"""Translate the example in goocanvas' manual into python."""

import gtk
import goocanvas
import sys

def on_delete_event(widget, event, data=None):
    """This is our handler for the "delete-event" signal of the
     window, which is emitted when the 'x' close button is clicked. We
     just exit here."""
    sys.exit(0)

def on_rect_button_press(item, target, event, data=None):
    """This handles button presses in item views. We simply output a
    message to the console."""
    print "rect item received button press!"
    return True

def main():
    window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    
    window.set_default_size(640, 600)
    window.show()
    window.connect('delete_event', on_delete_event)
  
    scrolled_win = gtk.ScrolledWindow()
    scrolled_win.set_shadow_type (gtk.SHADOW_IN)
    scrolled_win.show()
    window.add(scrolled_win)

    canvas = goocanvas.Canvas()
    canvas.set_size_request(600, 450)
    canvas.set_bounds(0,0,1000,1000)
    canvas.show()
    scrolled_win.add(canvas)

    root = canvas.get_root_item()
  
    # Add a few simple items.
    rect_item = goocanvas.Rect(parent=root,
                               x=100, y=100, width=400, height=400,
                               line_width=10.0, radius_x=20.0,
                               radius_y=10.0, stroke_color='yellow',
                               fill_color='red')

    text_item = goocanvas.Text (parent=root, text="Hello World", x=300, y=300,
                                anchor=gtk.ANCHOR_CENTER, font='Sans 24')
    text_item.rotate(45, 300, 300)
  
    # Connect a signal handler for the rectangle item.
    rect_item.connect('button_press_event', on_rect_button_press)
  
    # Pass control to the GTK+ main event loop.
    gtk.main()

if __name__=='__main__':
    main()
_______________________________________________
Devel mailing list
[email protected]
http://lists.laptop.org/listinfo/devel

Reply via email to