Questions about the event loop

B

bruno at modulix

egbert said:
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
 
E

egbert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top