[wxPython-users] Re: "Pushing" Data to Modules -- SOLVED!
Werner F. Bruhin
werner.bruhin at free.fr
Mon Dec 4 07:26:05 PST 2006
Hi Rich,
Rich Shepard wrote:
> On Mon, 4 Dec 2006, Werner F. Bruhin wrote:
>
>> Hi Rich,
>
> Good afternoon (your time), Werner:
Good morning to you then :-) .
>
>> In the sample code if I change:
>>
>> def MyPrint(msg):
>> to
>> def MyPrint():
>
> This threw me for a moment, because I had
> def setWidgets(msg):
> But, and this is embarrassing while being a solid lesson, what I need is
> def setWidgets(self, msg):
>
> And now the program loads. I expect that when I put content in this
> method
> it will work as desired.
>
> Thanks to Donn, Robin, and you what was so daunting when I first
> looked at
> the wx.lib.pubsub API page turns out to be no more complex than using any
> other wx. class. The Wiki page seems to be a bit more obtuse than it
> needs
> to be, too.
>
> I can summarize what I did in three steps:
>
> 1) In the application-global config.py's configData() class, I
> entered the
> one message I currently need ('projOpen = 1'); more messages can be
> entered
> as necessary in other parts of the model.
>
> 2) In the module/class that needs to tell the rest of the
> application that
> a project database file has been opened (i.e., a connection and cursor
> established), I import the class
> from wx.lib.pubsub import Publisher
> and have this line:
> Publisher().sendMessage('projOpen', data=None)
I think this should be:
Publisher().sendMessage(configData.projOpen, data=None)
Or use strings everywhere and forget to predefine them in your configdata.
>
> 3) In each of the modules/classes that need to set retrieved data
> into the
> appropriate widgets for display, the class is also imported
> from wx.lib.pubsub import Publisher
> and I have this command at the end of the __init__ method:
> Publisher().subscribe(self.setWidgets, 'projOpen')
Again this would be:
Publisher().subscribe(self.setWidgets, configData.projOpen)
>
> The called method is then defined by:
> def setWidgets(self, msg):
>
> All of this is much simpler than it seems. Of course, this is not an
> implimentation of the MVC/MVP, but a solution to the problem of
> inter-module
> communication (IMC?).
>
> Rich
>
See you
Werner
More information about the wxpython-users
mailing list