Popular recipes by Jørgen Cederberg http://code.activestate.com/recipes/users/359004/2003-01-13T09:38:15-08:00ActiveState Code RecipesObserver Pattern (Python)
2003-01-13T09:38:15-08:00Jørgen Cederberghttp://code.activestate.com/recipes/users/359004/http://code.activestate.com/recipes/131499-observer-pattern/
<p style="color: grey">
Python
recipe 131499
by <a href="/recipes/users/359004/">Jørgen Cederberg</a>
(<a href="/recipes/tags/oop/">oop</a>).
Revision 2.
</p>
<p>This is a Python implementation of the observer pattern described by Gamma et. al. It defines a one-to many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.</p>
<p>The example should output:
Setting Data 1 = 10
DecimalViewer: Subject Data 1 has data 10
HexViewer: Subject Data 1 has data 0xa
Setting Data 2 = 15
HexViewer: Subject Data 2 has data 0xf
DecimalViewer: Subject Data 2 has data 15
Setting Data 1 = 3
DecimalViewer: Subject Data 1 has data 3
HexViewer: Subject Data 1 has data 0x3
Setting Data 2 = 5
HexViewer: Subject Data 2 has data 0x5
DecimalViewer: Subject Data 2 has data 5
Detach HexViewer from data1 and data2.
Setting Data 1 = 10
DecimalViewer: Subject Data 1 has data 10
Setting Data 2 = 15
DecimalViewer: Subject Data 2 has data 15</p>
Stopwatch in Tkinter (Python)
2002-05-23T13:51:38-07:00Jørgen Cederberghttp://code.activestate.com/recipes/users/359004/http://code.activestate.com/recipes/124894-stopwatch-in-tkinter/
<p style="color: grey">
Python
recipe 124894
by <a href="/recipes/users/359004/">Jørgen Cederberg</a>
(<a href="/recipes/tags/ui/">ui</a>).
Revision 2.
</p>
<p>This is a small implementation of a stopwatch widget in Tkinter. The widget displays a label with minutes:seconds:1/100-seconds. The label is updated every 50 ms, but that can easily be changed. Methods are availble for starting, stopping and resetting the stopwatch. A simple program demonstrates the widget.</p>