Re: [pygtk] Newbie: Capturing from a camera, displaying on a drawingArea.

2004-02-26 Thread John Hunter
> "Alexandre" == Alexandre Strube <[EMAIL PROTECTED]> writes:

Alexandre> The file "foo.png" is saved correctly, which means the
Alexandre> capture stuff is ok. However, nothing shows up on
Alexandre> "janela1". What am I doing wrong?

Alexandre> Thanks for your help,

As Gustavo pointed out, you cannot draw until the window is realized.

Here is some template code for drawing

#!/usr/bin/env python
# this is meant to be used as a template file to practice drawing commands
import pygtk
pygtk.require('2.0')
import gtk
from gtk import gdk

def draw(widget):
print 'draw'
gc = widget.window.new_gc()
widget.window.draw_rectangle( gc, 1, 100,100,100,100)

def configure_event(widget, event):
print 'config'
draw(widget)
return gtk.TRUE

def expose_event(widget, event):
print 'expose'
draw(widget)
return gtk.TRUE

def realize(widget):
print 'realize'
draw(widget)
return gtk.TRUE

win = gtk.Window()
win.set_size_request(640, 480)
win.show()


vbox = gtk.VBox()
vbox.show()
win.add(vbox)

da = gtk.DrawingArea()
da.connect('configure_event', configure_event)
da.connect('expose_event', configure_event)
da.connect('realize', realize)
da.show()
vbox.pack_start(da, gtk.TRUE, gtk.TRUE)


button = gtk.Button('Quit')
button.show()
vbox.pack_start(button, gtk.FALSE, gtk.FALSE)
button.connect('clicked', gtk.mainquit)
gtk.mainloop()

You will probably want to connect your function which grabs a frame
and displays it when called to the gtk idle handler or timer,

Also, do you need to go through PIL?   Can you not do something like.

  widget.window.draw_rgb_image(gc, 1, 1, WIDTH, HEIGHT, 
   gtk.gdk.RGB_DITHER_NONE, vid.getImage(0), stride)

JDH
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] gnome-python and suse 9.0

2004-02-26 Thread Tom Cato Amundsen
Has anyone ran gnome-python on suse 9.0? One user of Solfege is trying
to install solfege on a fresh suse 9.0 box, and he get this error
message:

Traceback (most recent call last):
  File "/usr/local/bin/solfege", line 46, in ?
  import src.mainwin
File "/usr/local/share/solfege/2.1.0/src/mainwin.py", line 149, in ?
import gnome, gnome.ui
ImportError: could not import bonobo.ui

Does anybody know what package contains the bonobo.ui module on suse 9?
On debian this it is in python2.3-gnome2.
-- 
Tom Cato Amundsen <[EMAIL PROTECTED]>
GNU Solfege - free eartraining, http://www.gnu.org/software/solfege/

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Newbie: Capturing from a camera, displaying on a drawingArea.

2004-02-26 Thread Gustavo J. A. M. Carneiro
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/