From: Robin Dunn [mailto:robin@alldunn.com]
Sent: August 4, 2006 1:12 PMOliver Schoenborn wrote:
> This is now easier to use, IMO. Feedback welcome.The eventType parameter in DelayedResult.ByEvent should be
named eventBinder or something similar. (eventType is the
name used for the numeric event IDs.)
So, just to make sure I understand: the Threads example in the demo has
the following code:
# This creates a new Event class and a EVT binder function
(UpdateBarEvent, EVT_UPDATE_BARGRAPH) = wx.lib.newevent.NewEvent()
...
evt = UpdateBarEvent(...)
wx.PostEvent(self.win, evt)
...
self.Bind(EVT_UPDATE_BARGRAPH, self.OnUpdate)
This suggests the first item in the pair returned from NewEvent() is the
new event class, and the second item is the binder. In this case the
byEvent() and ByEvent.__init__() take an event class, not a binder; they
just care to know what type of event to generate, and who gets it, and
leaves the binding up to the caller (because the DelayedResult.byEvent()
could be used many times, yet you only want to bind once).
Do I have the terminology inverted?
Would it make sense to allow appending of listeners instead
of just prepending?
No. The unit test takes shortcuts that make sense for black-box testing,
but are otherwise misleading in terms of use of the module. I will
include better docs and add a test that can be used as an example.
The ByClass and ByEvent names aren't very intuitive for what
they do, but I'm not able to think of anything else at the
moment to suggest...
I doubt they would ever be used directly by the user. Instead, consider:
import DelayedResult
...
delayedResult1 = DelayedResult.byCall(callable)
delayedResult2 = DelayedResult.byEvent(evtHandler, evtClass)
assert isinstance(delayedResult1, DelayedResult.DelayedResult)
assert isinstance(delayedResult2, DelayedResult.DelayedResult)
In first case you are creating a delayed result that will be transmitted
by calling your callable, vs in second case by generating an event that
is given to your handler object.
Oliver
DelayedResult.py (12.4 KB)
···
-----Original Message-----