[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Gui




On Jun 28, 2005, at 4:33 AM, Marcus von Appen wrote:

On, Tue Jun 28, 2005, Simon Wittber wrote:


It certainly wouldn't make Twisted obsolete, it would only make the
syntax more convenient.


Yes I would agree, I guess I meant to imply that perhaps callback style frameworks will need to adapt or fade away.


Why that? I currently do not see any big benefit of the coroutines. They seem to be pretty interesting for chaining and async operations, but how could those be connected to user interfaces?

# using coroutines internally # notice that the flow is naturally top to bottom foo = getNetworkBytes() do stuff with foo

# not using coroutines internally
# notice that the flow is pretty much backwards
def gotFoo(foo):
    do stuff with foo
getNetworkBytes().addCallback(gotFoo)


Current user interfaces mostly work this way:

hid sends event ->
event queue gets event and distributes it ->
widget receives hid event internally and calls handlers OR
sends an acknowledgement event, which causes connected handlers
to be run


How a user interface implementing this PEP generators would do that? Any
idea or (pseudo-)example?

For individual UI elements it's not a big deal, but at a higher level you can do something like this:


if userSaidYesToDialog():
    do stuff

Without having to use a nested UI runloop.

For network programming and certain other kinds of processing, coroutines are a HUGE win because you only have two kinds of events that can happen per-socket and each socket is distinct (bytes or error). For GUI stuff, where you have a much more complicated state machine, it's not such a big deal.. the only real advantage to coroutines that I've seen is for integrating with networking code and for doing incremental processing (yielding to the GUI runloop for some amount of time without returning from the function).

-bob