SASE Observer Design Pattern with Tkinter widgets as Observers

Laura Creighton lac at cd.chalmers.se
Sun Apr 8 11:58:30 EDT 2001


Has anybody implemented the Self-Addressed Stamped Envelope (SASE) variation
of the Observer Design Pattern in python registering Tkinter widgets with
a Subject? You can find a full discussion of the SASE pattern starting on
page 312 of The Design Patterns Smalltalk Companion, I will give a short
one:
 
Having set up a relationship between a Subject and its many Observers,
it would be very convenient if instead of notifying ALL of its dependents,
a Subject could only notify those who happened to be interested in the
particular change that happened.  With a SASE the observers register
themselves with the Subject and tell the subject a) who they are 
b) what event(s) they care about c) what they would like to be ordered 
to do when that event happens <with whatever parameters should be sent 
with the order>

Sounds neat.  But I cannot figure out how to get Tkinter widgets to be
interested in anything other than user-generated events, such as mouse
clicks, after, and all its friends for generating alarms, and 
_tkinter.createfilehandler(file, mask, function) which you use 
when a file's status changes.  I don't think that this works with Windows,
so a thread equivalent is probably in order --  after I find out how to do 
this at all, first,  that is.

As a tiny example, I decided to make a small label which prints the time.
When the time gets later than (whenever you select) the time label
turns red and says ``It is only xx minutes until THE LAST TRAM leaves.
You DON'T want to have to WALK home AGAIN.''

Then I started sending UDP packets down a socket using 
s.sendto(time.asctime(time.localtime(time.time())), addr) 
where s is a socket and addr is a nice port to listen to on this host.
Works great. Dead easy.  Python is wonderful, I just wrote a server in 9 
lines.  My client end can listen just fine using tkinter.createfilehandler 
where the function is just sock.recvfrom with a print statement. 
 
But I can't figure out how to get my Subject to then start figuring out
if my widgets need updating on their behalf, or how to communicate
with those existing widgets if if finds any that needs them.
Is there another event mechanism that I am missing totally? Or do I just
not know how to use these ones?

Thanks very much for your time and patience,
Laura Creighton
lac at cd.chalmers.se




More information about the Python-list mailing list