[wxPython-dev] Re: About Louie and lib.pubsub

Bill Baxter wbaxter at gmail.com
Mon Jun 25 23:02:42 PDT 2007


Thanks for the response, Stani.  I haven't swallowed the GPL pill,
though, so there's not much I can do with the source code you posted,
though I do appreciate your effort to help.

I actually just discovered one big thing about lib.pubsub that I had
completely wrong.  It *does* in fact use a global publisher.  I
thought I was creating new instances of publisher everywhere by
calling Publisher() but it turns out that pubsub just returns a
reference to the same global PublisherClass singleton every time.

So, durn.  That means pubsub is less suited than Louie for the
listener/observer pattern because there's no easy way to filter on
senders.

Ok, a little more looking and I found a nice cookbook recipe for
Signals/Slots which is really more what I'm after.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439356
Adding a simple "Publisher" class onto that which maps key->Signal()
object gives me a decentralized publisher class that can call slot
methods directly.  It doesn't have hierarchical topics, but that's not
something I really need.

--bb


On 6/22/07, Stani's Python Editor <spe.stani.be at gmail.com> wrote:
> 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
> --
> http://pythonide.stani.be
>




More information about the wxpython-dev mailing list