[wxPython-users] Sending/Using Data with wx.lib.pubsub

Werner F. Bruhin werner.bruhin at free.fr
Mon Oct 1 07:26:07 PDT 2007


Rich,

Rich Shepard wrote:
> On Mon, 1 Oct 2007, chris botos wrote:
>
>> The subscribed function should look something like this:
>>
>> def SubscribedFunction(self, message):
>>    newvar = message.data
>>    etc.
>
> Chris,
>
>   I'm missing something crucial in the syntax because I cannot get it
> working here.
>
>   I use a module, config.py, as a blackboard to share variables among
> modules. This is where the messages to be published are found. For
> example, there's the publisher message 'projVars' in this module. 
> config.py
> is imported into all other modules and assigned to the variable
> 'self.appData'.
>
>   The sending module has the line:
>
>     Publisher().sendMessage(self.appData.projVars, data=newvar)
>
>   The listening module has this line:
>
>     Publisher().subscribe(self.loadParVar, self.appData.projVars)
>
> In this listener module I just added the function:
>
>       def projVars(self, message):
>         self.newvar = self.appData.projVars.data
Shouldn't this be:
            self.newvar = message.data
>
> but the variable 'self.newvar' is not seen when I try to use it in 
> another
> function:
>
>   File "/data1/eikos/fuzSetPage.py", line 391, in loadParVar
>     self.dispVar = self.newvar
> AttributeError: 'modFzySet' object has no attribute 'newvar'
If no message was ever received, i.e. before you call the above line 391 
then this would be normal.

Maybe you want to initialize self.newvar to e.g. None during the init of 
fuzSetPage.py.

Werner
>
>   So I've missed something in your reply on implementing the function for
> the subscribed function. Is what I've missed visible in what I include
> above?
>
> TIA,
>
> Rich
>





More information about the wxpython-users mailing list