[wxpython-dev] Google SoC Project - MVC
Robin Dunn
robin at alldunn.com
Fri May 30 11:48:38 PDT 2008
Nitro wrote:
> I am doing the same for FloatCanvas. Internally I wrote a little "event
> manager" which just wraps wx.lib.pubsub so it can be replaced with
> another implementation if desired. One of the problems I encountered
> while doing this is that topics are supposed to be only strings.
Or tuples of strings.
> This
> seems to be a problem, because if I want to subscribe only for the
> updates of a specific object it's not (cleanly) possible.
>
> Doing something like
>
> obj = createSomeModelWhichSendsEventsWhenItChanges()
> Publisher().subscribe( (obj,), obj_all_messages_handler )
> Publisher().subscribe( (obj, 'sizeChanged'), obj_size_changed_handler )
>
> is not possible right now.
If obj has a unique name then you can just use that for a component of
the topic name.
> Maybe you could set the topic to
> (str(id(obj)),), but that doesn't seem like a clean solution.
It amounts to almost the same thing, except with a name then the
programmer could set that if they want to be able to use it later for
some reason, like a find object by name function.
> I am also
> wondering whether this would work at all for the default wxPython
> objects, because you might get different objs for the same underlying
> C++ object. Of course not using any of these objects doesn't create the
> problem.
>
> I can see three solutions:
Here is another. Use the hierarchal matching capabilities of pubsub to
help with topic filtering and matching. For example, you might define a
rule that all FC topics should use a set number of components, perhaps
something like:
action.canvasName.layerName.objName
(or the equivalent tuple form.) Already with pubsub you'll be able to
subscribe to messages that are more general or more detailed (from left
to right in the topic name.) For example, you can get all sizeChanged
actions in the fooCanvas by just subscribing to "sizeChanged.fooCanvas",
or whatever. Next, add to pubsub the ability to do wildcard topic
matches and you'll then be able to go the other direction. For example
to get messages for any action on the redCircle object you can subscribe
to "*.*.*.redCircle". Does that give you everything you need?
You may also want to look at pubsub3. It's the next generation of
pubsub forked off into its own project. I haven't had the time to
integrate it back into wxPython but it should probably be done one of
these days.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-dev
mailing list