A Qui, 2004-02-26 �s 01:48, Alexandre Strube escreveu:
> Hello list,
> 
> I'm trying to write a kind of webcam application in Python, using as
> user interface a .glade file. Until there, nothing difficult.
> 
> My problem is with getting the data from the webcam and putting it to
> screen. I can grab images from camera and save it to files, but I don't
> know how to put it on a gtk widget.
> 
> I have a drawingArea widget, called "janela1". I'm receiving data from
> video4linux to the variable "im", and converting this to a string again
> for putting it on the window, as stated at
> " http://www.daa.com.au/pipermail/pygtk/2004-January/006731.html "
> 
> The code follows:
> 
>   janela1=xml.get_widget('drawingarea1')  # gets drawingarea widget
>   gc=janela1.window.new_gc()         # creates a new window context
>   vid=inicializavideo()              # initializes video4linux stuff
>   im=Image.fromstring("RGB",(WIDTH,HEIGHT),vid.getImage(0)) # grab image
>   im.save("foo.png","PNG")                 # Saves image file (it works)
>   buff=im.tostring()
>   janela1.window.draw_rgb_image(gc, 1, 1, WIDTH, HEIGHT,
> gtk.gdk.RGB_DITHER_NONE, buff)
>   gtk.main()
> 
> 
> The file "foo.png" is saved correctly, which means the capture stuff is
> ok. However, nothing shows up on "janela1". What am I doing wrong?

  You are not understanding correctly the philosophy of GTK (or X)
programming.  In GTK, you never draw directly to a widget.  Instead, you
tell the X server the widget needs to be redrawn, then the X server
calls you back telling you to draw an area of your widget.
  To summarise, you should:
        1. connect a handler to 'expose-event' signal.  The handler has the
following signature:
                def expose_event_cb(widget, event): ....
           event is a structure containing the fields: x, y, width, height. 
These fields define the area that actually needs to be painted, which
might be different from the entire widget area if, for example, there is
a window on top of the widget, partially obscuring it.
        2. call widget.queue_draw() whenever you want to repaint your widget.

  You might want to read a GTK tutorial, to better understand these
issues.

  Regards.

-- 
Gustavo Jo�o Alves Marques Carneiro
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
The universe is always one step beyond logic.

_______________________________________________
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