Movatterモバイル変換


[0]ホーム

URL:


SASE Observer Design Pattern with Tkinter widgets as Observers

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


Has anybody implemented the Self-Addressed Stamped Envelope (SASE) variationof the Observer Design Pattern in python registering Tkinter widgets witha Subject? You can find a full discussion of the SASE pattern starting onpage 312 of The Design Patterns Smalltalk Companion, I will give a shortone: 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 theparticular change that happened.  With a SASE the observers registerthemselves 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 beinterested in anything other than user-generated events, such as mouseclicks, 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 labelturns 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 outif my widgets need updating on their behalf, or how to communicatewith those existing widgets if if finds any that needs them.Is there another event mechanism that I am missing totally? Or do I justnot know how to use these ones?Thanks very much for your time and patience,Laura Creightonlac at cd.chalmers.se


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp