"Pushing" Data to Modules
Donn Ingle
donn.ingle at gmail.com
Sat Dec 2 10:35:06 PST 2006
Rich Shepard wrote:
> I have no problems with the concept(s); I've used that model in C for
> years, even though it didn't have a name.
Oops. Sorry about that. I am totally new to it - I'm a spaghetti coder!
> I read further, it seemed that I had it backwards. Now, I'm not at all
> sure what's happening. Nor, why the messages are numbered rather than
> using strings; e.g., "file open."
Well, I reckon you're way beyond my little attempt. At the end, I include
some samples given to me (on this list) recently. Perhaps those will help
you more.
I used "ear" to indicate that it was going to listen and "shout" to indicate
that one wants something heard. To my mind they make sense :) So, yeah you
got them backwards.
I used descriptive variable names rather than strings because when I get
python errors, it shows the variables involved and I can see which 'topic'
is involved in the car smash. With strings, you don't get to see
what 'topic' was involved. Well, that's my story!
> In the vast universe of working wxPython apps, there must be at least
> one
> that uses these classes so we can learn how to use them for ourselves. No?
This is what I have been pointed to:
1.
http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi?11:mss:48197:200602:okmajbebilmpeafpdlco
2. See attached samples by Werner F. Bruhin
He said "The post Dan pointed out looks very good.
There is also quit a bit of test code in the
pubsub.py module. For what it is worth I attach the
very crude test stuff (run pubsubApp, press the
button and close it, output goes to standard out)
I put together for myself to try to understand it."
3. There are two good articels on the wiki, neither
mention pubsub, but they may help you. I found them incomplete
as far as concept goes.
http://wiki.wxpython.org/index.cgi/ModelViewController
http://wiki.wxpython.org/index.cgi/ModelViewPresenter
Good luck,
Donn.
-------------- next part --------------
# -*- coding: iso-8859-1 -*-#
"""Use it as follows:
import mypublisher as mypub
# to subscribe
mypub.publisher.subscribe(functionToCall, mypub.statusText)
# to notify
mypub.publisher.sendMessage(mypub.statusText, _('Text for status line'))
"""
from wx.lib.pubsub import Publisher
# Define variables for valid pubsub stuff, one could use strings, but
# I find this better as you get a clear failure if there is a problem, e.g. mistyped value
statusText = 1 # pass status text in data section
dataNeedsSaving = 2 # pass parent in data section to limit propagation, e.g. self.parent
comboBoxRefresh = 3 # pass table name in data section, e.g. 'country_ls'
wineDetails = 4 # pass ('refresh' | 'changed' | 'changedMulti' | 'added' | 'deleted', pkeys) in data section
bottleDetails = 5 # pass ('changed' | 'added' | 'deleted', pkeys) in data section
vintageDetails = 6 # pass ('changed' | 'added' | 'deleted', pkeys) in data section
consumptionDetails = 7 # pass ('changed' | 'added' | 'deleted', pkeys) in data section
purchaseDetails = 8 # pass ('changed' | 'added' | 'deleted', pkeys) in data section
setGetText = 10
setGetTextLC = 11
refreshWineFamily = 12
politics = 13
def SetDefaults():
global publisher
publisher = Publisher()
# subscribe to everything just for test
publisher.subscribe(MyPrint, '')
def MyPrint(msg):
print '****************'
print 'for testing only'
print msg.topic
print msg.data
print '****************'
SetDefaults()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pubsubApp.py
Type: application/x-python
Size: 478 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20061202/ca8eeb79/pubsubApp.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pubsubtest.py
Type: text/x-java
Size: 1559 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20061202/ca8eeb79/pubsubtest.java
More information about the wxpython-users
mailing list