]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_core_ex.py
1 #----------------------------------------------------------------------------
3 # Use Python's bool constants if available, make some if not
7 __builtins__
.True = 1==1
8 __builtins__
.False = 1==0
12 # workarounds for bad wxRTTI names
13 __wxPyPtrTypeMap
['wxGauge95'] = 'wxGauge'
14 __wxPyPtrTypeMap
['wxSlider95'] = 'wxSlider'
15 __wxPyPtrTypeMap
['wxStatusBar95'] = 'wxStatusBar'
18 #----------------------------------------------------------------------------
19 # Load version numbers from __version__... Ensure that major and minor
20 # versions are the same for both wxPython and wxWindows.
22 from __version__
import *
23 __version__
= VERSION_STRING
25 assert MAJOR_VERSION
== _core
.MAJOR_VERSION
, "wxPython/wxWindows version mismatch"
26 assert MINOR_VERSION
== _core
.MINOR_VERSION
, "wxPython/wxWindows version mismatch"
27 if RELEASE_VERSION
!= _core
.RELEASE_VERSION
:
29 warnings
.warn("wxPython/wxWindows release number mismatch")
31 #----------------------------------------------------------------------------
33 class PyDeadObjectError(AttributeError):
37 class _wxPyDeadObject(object):
39 Instances of wx objects that are OOR capable will have their __class__
40 changed to this class when the C++ object is deleted. This should help
41 prevent crashes due to referencing a bogus C++ pointer.
43 reprStr
= "wxPython wrapper for DELETED %s object! (The C++ object no longer exists.)"
44 attrStr
= "The C++ part of the %s object has been deleted, attribute access no longer allowed."
47 if not hasattr(self
, "_name"):
48 self
._name
= "[unknown]"
49 return self
.reprStr
% self
._name
51 def __getattr__( self
, *args
):
52 if not hasattr(self
, "_name"):
53 self
._name
= "[unknown]"
54 raise PyDeadObjectError( self
.attrStr
% self
._name
)
56 def __nonzero__(self
):
60 #----------------------------------------------------------------------------
61 _wxPyCallAfterId
= None
63 def CallAfter(callable, *args
, **kw
):
65 Call the specified function after the current and pending event
66 handlers have been completed. This is also good for making GUI
67 method calls from non-GUI threads.
70 assert app
, 'No wxApp created yet'
72 global _wxPyCallAfterId
73 if _wxPyCallAfterId
is None:
74 _wxPyCallAfterId
= wx
.NewEventType()
75 app
.Connect(-1, -1, _wxPyCallAfterId
,
76 lambda event
: event
.callable(*event
.args
, **event
.kw
) )
78 evt
.SetEventType(_wxPyCallAfterId
)
79 evt
.callable = callable
82 wx
.PostEvent(app
, evt
)
85 #----------------------------------------------------------------------------
90 A convenience class for wxTimer, that calls the given callable
91 object once after the given amount of milliseconds, passing any
92 positional or keyword args. The return value of the callable is
93 availbale after it has been run with the GetResult method.
95 If you don't need to get the return value or restart the timer
96 then there is no need to hold a reference to this object. It will
97 hold a reference to itself while the timer is running (the timer
98 has a reference to self.Notify) but the cycle will be broken when
99 the timer completes, automatically cleaning up the wx.FutureCall
102 def __init__(self
, millis
, callable, *args
, **kwargs
):
104 self
.callable = callable
105 self
.SetArgs(*args
, **kwargs
)
116 def Start(self
, millis
=None, *args
, **kwargs
):
121 if millis
is not None:
124 self
.SetArgs(*args
, **kwargs
)
126 self
.timer
= wx
.PyTimer(self
.Notify
)
127 self
.timer
.Start(self
.millis
, wx
.TIMER_ONE_SHOT
)
133 Stop and destroy the timer.
135 if self
.timer
is not None:
140 def GetInterval(self
):
141 if self
.timer
is not None:
142 return self
.timer
.GetInterval()
148 return self
.timer
is not None and self
.timer
.IsRunning()
151 def SetArgs(self
, *args
, **kwargs
):
153 (Re)set the args passed to the callable object. This is
154 useful in conjunction with Restart if you want to schedule a
155 new call to the same callable object but with different
170 The timer has expired so call the callable.
172 if self
.callable and getattr(self
.callable, 'im_self', True):
174 self
.result
= self
.callable(*self
.args
, **self
.kwargs
)
176 wx
.CallAfter(self
.Stop
)
179 #----------------------------------------------------------------------------
180 #----------------------------------------------------------------------------
182 # Import other modules in this package that should show up in the
183 # "core" wx namespace
185 from windows
import *
186 from controls
import *
189 #----------------------------------------------------------------------------
190 #----------------------------------------------------------------------------