On Tuesday 25 February 2003 02:04, John K Luebs wrote:
> On Mon, Feb 24, 2003 at 06:10:26PM -0500, Rob Landley wrote:
> > I'm getting an attribute error trying to call anything on the Event
> > object passed to me.  I tried dumping a __dict__ and that isn't there
> > either.
> >
> > The wrapper doesn't make SENSE, in any case.  The logic of get_coords
> > would be that a python method call was modifying its (integer) arguments,
> > which is remarkably un-pythonic.  (Pass it a mutable list, sure.  But
> > that's not what it claims should be happening.)  Maybe the C bindings can
> > do this, but ouch.
>
> How do you know the wrapper doesn't make sense if you couldn't get it
> to work? Most of the C idioms used in GTK are mapped to their Python
> equivalent idiom. Overall, PyGTK has a pretty good setup.

What is the python equivalent idiom of call by reference?  
(blah.get_coords([x],[y]) is a straighter translation, but 
(x,y)=blah.get_coords() seems more pythonic, somehow...)

I'm not expecting there to be anything wrong with the wrapper, actually.  It's 
mostly the lack of documentation, and Google's tendency to turn up the advice 
"look in gtk.py", which has been obsoleted and the API changed quite a bit 
since the copy I found on the web...

> > Here's some sample code showing things I've tried, which didn't work.
>
> In the future, if you have a short code snippet just append it to the
> body of your message. Attachments are a pain and not easily quotable.

Sorry.

> You must create a mainloop, by calling gtk.mainloop().

"gtk.mainloop()" won't let you ctrl-c out of the program at the console it was 
called from.  Using "while gtk.mainiteration(): pass" instead lets you exit, 
although you have to call sys.exit() rather than gtk.mainquit() to make it go 
away from elsewhere.  (Which just highlights that I have no CLUE what the 
return value from gtk.mainiteration is supposed to mean, in the GUI toolkits 
I know on other platforms, 0 means end of mainloop...)

Probably there are very important reasons not to do this.  I'd love to know 
what they are...

> Your iteration
> loop has two major problems. The first one is that you haven't
> properly initialized the GTK+ mainloop which is causing you all kinds of
> grief.  GTK+ will complain about this only when you call certain
> functions, notably gtk.mainquit() (which usually exists somewhere in
> every program).

hence lambda a: sys.exit(0).  (Not saying it's good, just saying it did a good 
immitation of working when I tried it.)

> The second problem is that your while loop never sleeps
> and imposes 100% CPU load.

It had a default argument "block=true" back when gtk.py was written in python.  
My little KDE bar graph loadmeter didn't spike when I switched it, either.  
(Just tried running something with that and it seemed happy...)

> This is unacceptable because it will suck the
> life very quickly out of any battery powered device (laptop users will
> hate you). It also is unnecessarily unfair to lower priority processes.

I'm running it on a laptop.  My desktop machine is 1500 miles away in Austin.

> In otherwords, your example has no need for gtk.mainiteration().
> gtk.mainiteration() is generally used when you are performing some long
> process and want to periodically flush the gtk event queue. You can use
> something like this:
>
> while gtk.events_pending(): gtk.mainiteration()

I would be thrilled to use gtk.mainloop() if it didn't eat ctrl-c in the xterm 
I ran the GTK app from.  Any idea how to get it to not eat ctrl-c?

> Rarely does one use gtk.mainiteration by itself in a loop, and never in
> an unconditional loop.

Unless one is trying to work around a bug in mainloop().  (Which for all I 
know is an artifact of Red Hat 8.  At the very least I'm 3 versions behind, 
but building it from source didn't work due to horked dependencies I haven't 
had time or inclination to resolve yet.)

> Getting that taken care of you should find that the GdkEvent object
> (that you name b in your signal handler) has a get_coords function. The
> get_coords function returns the coordinates as a tuple, which seems to be
> as Pythonic as one could ask for.

Cool.  I'll give it a try, thanks. :)

>  --jkl

Rob

-- 
penguicon.sf.net - A combination Linux Expo and Science Fiction Convention, 
May 2-4 2003 in Warren, Michigan. Tutorials, installfest, filk, masquerade...
_______________________________________________
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