Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Questions about the event loop

Reply
Thread Tools

Questions about the event loop

 
 
bruno at modulix
Guest
Posts: n/a
 
      05-16-2006
egbert wrote:
> What does a gui_event_loop know ?
>
> My gui is based on pygtk,
> but i suppose the mechanism is the same everywhere.
>
> The gui is created within a class-instance within a function.
> Normally, ie without a gui, everything that happens within
> a function is forgotten as soon the function ends.
>
> But in a gui_event_loop the callback-method within the function
> can be called, and this callbacks calls another function
> also within the same first function.
> And that function already stopped.


s/stopped/returned/


I guess that what bother you has to do with closures.

def foo(bar):
buu = "buu"
def baaz(baak):
print bar, buu, baak

print "foo(%s") return..." % bar
return baaz

dodo = Foo('parrot')
dudu = Foo('dead')

dodo(42)
dudu("ni")

As you can see, after foo() has returned, dodo() and dudu() 'remember'
the environment in which they where created. A closure is a function
that carries it's environment with it.

>
> Maybe somebody can explain what is going on, or where I can find
> further explanations.
>

http://en.wikipedia.org/wiki/Closure_(computer_science)
http://www.python.org/dev/peps/pep-0227/
http://docs.python.org/ref/naming.html#naming

HTH
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
 
 
 
egbert
Guest
Posts: n/a
 
      05-17-2006
What does a gui_event_loop know ?

My gui is based on pygtk,
but i suppose the mechanism is the same everywhere.

The gui is created within a class-instance within a function.
Normally, ie without a gui, everything that happens within
a function is forgotten as soon the function ends.

But in a gui_event_loop the callback-method within the function
can be called, and this callbacks calls another function
also within the same first function.
And that function already stopped.

Maybe somebody can explain what is going on, or where I can find
further explanations.

The structure of my gui script is as follows:
import gtk
def func():
def callback_helper():
...
class Klas(object):
def __init__(self):
...
# create gui with self.callback()
...
def callback(self, widget):
callback_helper()
...
klas = Klas()

func()
gtk.main()

egbert
--
Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991
================================================== ======================
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM
Loop the loop... =?Utf-8?B?VGltOjouLg==?= ASP .Net 2 02-16-2005 12:21 PM
Re: Questions....questions....questions Patrick Michael A+ Certification 0 06-16-2004 04:53 PM



Advertisments