Hi Bill,
I wrote a wrapper some time ago which appareantly makes pubsub behave
like what you are looking for in Louie. From this module you only need
to import the mixin 'Receiver' and the instance 'send'. You need to do
two steps: register any object with Receiver (e.g. with the name 'test')
and afterwards to subscribe the methods (e.g. the method 'write').
Afterwards you can send a notification by unifying the name of the
receiver and the method name with an underscore (e.g. 'test_write' ->
'send.test_write'). The only limitation is that you can not use dots.
(However after some hacking that could be a possibility as well.) In
this way there is no need for a message anymore and you can pass
arguments and/or keyword options.
In my applications I just copy pubsub.py locally and include events.py
as I also want that my application can work as a console application
without a gui. If you want to see a full application using my events
module, you can browse the trunk code of:
http://launchpad.net/phatch
You'll need bazaar to download it locally. Events.py is in phatch/core
Stani
events.py (2.48 KB)
···
--
wxPython-dev-digest-help@lists.wxwidgets.org schreef:
Onderwerp:
About Louie and lib.pubsub
Van:
"Bill Baxter" <wbaxter@gmail.com>
Datum:
Fri, 22 Jun 2007 11:59:56 +0900
Aan:
wxpython-dev@lists.wxwidgets.orgAan:
wxpython-dev@lists.wxwidgets.orgI posted something about this to the Louie mailing list, but since there
have been all of 5 messages there since last year, I didn't really expect a
reply, and indeed didn't get one.So at the risk of being off-topic I'm repeating myself here since this is
the place I heard about Louie.Here's my quick comparison of how Louie measures up to wx.lib.pubsub:
- on the plus side you can hook up arbitrary methods as callbacks, unlike
wx.lib.pubsub where your callback always has to take a single Message
parameter. With Louie, if you have a method sitting around that takes a
'value' parameter, you can hook up some notification to it directly rather
than having to write an adapter that takes a Message, extracts the
msg.data.value and then calls the function you really wanted to call. I'm
sure there's a cost you have to pay for this though. You can also just
use
positional arguments. So with louie you can do:louie.send('value_changed", sender, new_value)
and it can directly call a callback method like
def setDisplay(self, display):
self.text = str(display)whereas with pubsub you'd have to make another method to call the
setDisplay
one, something like:def onValueChanged(self, message):
self.setDisplay(message.data['new_value'])It's just an extra two-liner, but still it's kind of an annoyance for
someone used to Qt's way where signals can usually be hooked up to existing
slots that are just setters. Maybe you can lambda it down to a one-liner,
but it's still a little extra work.- on the minus side Louie uses a single global dispatcher. In that respect
wx.lib.pubsub is nicer, since you can create multiple
dispatchers/Publishers
with pubsub. This was a deal-breaker for me. If you have a app that
creates two main document frames, it makes no sense for there to be a
single
dispatcher that processes all the signals in both frames. The dispatcher
for events related to one document should really belong to that document,
and not be global. Having said that, it doesn't look like it would be
terribly hard to fix Louie to make the dispatcher a class.- also on the minus side, like I said, I posted a message to the Louie
mailing list and got no response. Seems like the project is pretty dead at
this time.--bb