|
From: Mike C. F. <mcf...@vr...> - 2005-09-23 16:10:27
|
Nitro wrote:
> First, thanks for the kind help!
NP.
> PyDispatcher works great so far. I have just a single place where I
> wondered how this is tackled with pydispatcher.
Should probably discuss this on the mailing list so that others can
follow along and/or supply their own comments. Copying there.
> There's a class DataSource which can send data upon request:
>
> dispatcher.connect(self.OnRequestData, signal = Events.RequestData)
> def OnRequestData(self, channel = 0):
> # retrieve/generate data here
> dispatcher.send(sender = self, signal = Events.NewData, channel =
> channel)
>
> A DataReceivers might look it like:
>
> def QueryData(self):
> dispatcher.connect(self.OnNewData, signal = Events.NewData)
> dispatcher.send(sender = self, signal = Events.RequestData,
> channel = 0)
> def OnNewData(self):
> # if some other object requested data for channel 1, this will
> arrive here, too. Not what I want!
>
>
> I hope you can clearly see the problem. If there are two data
> receivers, one which requests channel = 0 and the other channel = 1
> data, then both receivers will receive both data streams (they
> requested only one).
> Is there a way to do this better with PyDispatcher? I don't want to
> manually generate events for each channel combination, like
> Events.RequestDataChannel1, Events.RequestDataChannel2, ... .
> Should I make the signal more complex and call it like
>
> DataSource:
> dispatcher.connect(self.OnRequestData, signal =
> Events.RequestData(channel = ANY_CHANNEL))
>
> DataReceiver:
> def QueryData(self):
> dispatcher.connect(self.OnNewData, signal = Events.NewData(channel
> = 0) )
> dispatcher.send( sender = self, signal =
> Events.RequestData(channel = 0) )
>
> However, now the source won't get the request anymore since
> Events.RequestData(channel = ANY_CHANNEL) doesn't match the hash of
> Events.RequestData(channel = 0) . How do you accomplish this? I think
> it's similar to these parent signals.
>
> -Matthias
Yes, this is basically the same problem as "parent" signals solve. It
could be solved about as well by creating multiple dispatchers
(something the original recipe's code doesn't really support). For
your particular problem, consider this:
fullSignal = (Events.NewData, 0)
this defines a different signal for each channel's NewData. You can
then also register for:
parentSignal = (Events.NewData,)
and send messages as:
results = []
while signal:
results.extend( dispatcher.send( sender, signal, **named ) )
signal = signal[:-1]
return results
such that registering for the parent signal works too. Real-world uses
will likely also want a way to specify *not* to continue processing,
that's left as an exercise, as it's normally application specific.
HTH,
Mike
--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
|