[wxPython-users] Re: "Pushing" Data to Modules -- SOLVED!

Rich Shepard rshepard at appl-ecosys.com
Mon Dec 4 06:28:53 PST 2006


On Mon, 4 Dec 2006, Werner F. Bruhin wrote:

> Hi Rich,

Good afternoon (your time), Werner:

> 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)

   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')

   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

-- 
Richard B. Shepard, Ph.D.               |    The Environmental Permitting
Applied Ecosystem Services, Inc.(TM)    |            Accelerator
<http://www.appl-ecosys.com>     Voice: 503-667-4517      Fax: 503-667-8863




More information about the wxpython-users mailing list