| Home | Trees | Indices | Help |
|
|---|
|
|
1 """GNUmed wx.Timer proxy object.
2
3 @copyright: author(s)
4 """
5 ############################################################################
6 # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/wxpython/gmTimer.py,v $
7 # $Id: gmTimer.py,v 1.13 2008-12-26 16:04:12 ncq Exp $
8 __version__ = "$Revision: 1.13 $"
9 __author__ = "K. Hilbert <Karsten.Hilbert@gmx.net>"
10 __licence__ = "GPL (details at http://www.gnu.org)"
11
12 # stdlib
13 import logging
14
15 # 3rd party
16 import wx
17
18
19 _log = logging.getLogger('gm.timers')
20 _timers = []
21 #===========================================================================
23 global _timers
24 _log.info('shutting down %s pending timers', len(_timers))
25 for timer in _timers:
26 _log.debug('timer [%s]', timer.cookie)
27 timer.Stop()
28 _timers = []
29 #===========================================================================
31 """wx.Timer proxy.
32
33 It would be quite useful to tune the delay
34 according to current network speed either at
35 application startup or even during runtime.
36 """
38 """Set up our timer with reasonable defaults.
39
40 - delay default is 300ms as per Richard Terry's experience
41 - delay should be tailored to network speed/user speed
42 - <cookie> is passed to <callback> when <delay> is up
43 """
44 # sanity check
45 if not callable(callback):
46 raise ValueError("[%s]: <callback> %s is not a callable()" % (self.__class__.__name__, callback))
47
48 if cookie is None:
49 self.cookie = id(self)
50 else:
51 self.cookie = cookie
52 self.__callback = callback
53 self.__delay = delay
54
55 wx.Timer.__init__(self)
56
57 _log.debug('setting up timer: cookie [%s], delay %sms', self.cookie, self.__delay)
58
59 global _timers
60 _timers.append(self)
61 #-----------------------------------------------------------------------
63 if milliseconds == -1:
64 milliseconds = self.__delay
65 wx.Timer.Start(self, milliseconds=milliseconds, oneShot=oneShot)
66 #-----------------------------------------------------------------------
69 #-----------------------------------------------------------------------
75 #===========================================================================
76 if __name__ == '__main__':
77 import time
78
79 #-----------------------------------------------------------------------
82 #-----------------------------------------------------------------------
90 #-----------------------------------------------------------------------
91 app = cApp(0)
92 # and enter the main event loop
93 app.MainLoop()
94 print "waiting 10 seconds for timer to trigger"
95 time.sleep(10)
96 #===========================================================================
97 # $Log: gmTimer.py,v $
98 # Revision 1.13 2008-12-26 16:04:12 ncq
99 # - properly shutdown timers
100 #
101 # Revision 1.12 2008/07/13 16:23:27 ncq
102 # - add some debugging
103 #
104 # Revision 1.11 2007/02/05 12:11:58 ncq
105 # - imports cleanup
106 # - remove gmLog
107 #
108 # Revision 1.10 2005/09/28 21:27:30 ncq
109 # - a lot of wx2.6-ification
110 #
111 # Revision 1.9 2005/09/28 19:47:01 ncq
112 # - runs until login dialog
113 #
114 # Revision 1.8 2005/09/28 15:57:48 ncq
115 # - a whole bunch of wx.Foo -> wx.Foo
116 #
117 # Revision 1.7 2005/09/27 20:44:59 ncq
118 # - wx.wx* -> wx.*
119 #
120 # Revision 1.6 2005/09/26 18:01:51 ncq
121 # - use proper way to import wx26 vs wx2.4
122 # - note: THIS WILL BREAK RUNNING THE CLIENT IN SOME PLACES
123 # - time for fixup
124 #
125 # Revision 1.5 2005/07/24 09:21:09 ncq
126 # - use proxy Start() to work around Windows timer Start() glitches
127 #
128 # Revision 1.4 2005/07/23 21:12:19 ncq
129 # - no keywords for Windows in Start()
130 #
131 # Revision 1.3 2005/07/23 21:08:28 ncq
132 # - explicitely use milliseconds=-1 as Windows seems to require it
133 #
134 # Revision 1.2 2005/07/23 20:47:02 ncq
135 # - start wxApp instance when testing - needed in windows
136 #
137 # Revision 1.1 2004/12/23 15:07:36 ncq
138 # - provide a convenient wxTimer proxy object
139 #
140 #
141
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Mon Nov 29 04:06:02 2010 | http://epydoc.sourceforge.net |