Questions about the event loop

Discussion in 'Python' started by bruno at modulix, May 16, 2006.

  1. 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 ''.split('@')])"
    bruno at modulix, May 16, 2006
    #1
    1. Advertising

  2. bruno at modulix

    egbert Guest

    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
    ========================================================================
    egbert, May 17, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Loop the loop...

    =?Utf-8?B?VGltOjouLg==?=, Feb 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,381
    Karl Seguin
    Feb 16, 2005
  2. Steven

    while loop in a while loop

    Steven, Mar 24, 2005, in forum: Java
    Replies:
    5
    Views:
    2,230
    Tim Slattery
    Mar 30, 2005
  3. -
    Replies:
    12
    Views:
    692
    Remon van Vliet
    Jun 15, 2005
  4. Byte
    Replies:
    4
    Views:
    415
  5. Isaac Won
    Replies:
    9
    Views:
    372
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page