]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_core_ex.py
1 #----------------------------------------------------------------------------
3 # Use Python's bool constants if available, make aliases if not
10 # Backwards compaatibility
15 # workarounds for bad wxRTTI names
16 __wxPyPtrTypeMap
['wxGauge95'] = 'wxGauge'
17 __wxPyPtrTypeMap
['wxSlider95'] = 'wxSlider'
18 __wxPyPtrTypeMap
['wxStatusBar95'] = 'wxStatusBar'
21 #----------------------------------------------------------------------------
22 # Load version numbers from __version__... Ensure that major and minor
23 # versions are the same for both wxPython and wxWindows.
25 from __version__
import *
26 __version__
= VERSION_STRING
28 assert MAJOR_VERSION
== _core
.MAJOR_VERSION
, "wxPython/wxWindows version mismatch"
29 assert MINOR_VERSION
== _core
.MINOR_VERSION
, "wxPython/wxWindows version mismatch"
30 if RELEASE_VERSION
!= _core
.RELEASE_VERSION
:
32 warnings
.warn("wxPython/wxWindows release number mismatch")
34 #----------------------------------------------------------------------------
36 class PyDeadObjectError(AttributeError):
40 class _wxPyDeadObject(object):
42 Instances of wx objects that are OOR capable will have their __class__
43 changed to this class when the C++ object is deleted. This should help
44 prevent crashes due to referencing a bogus C++ pointer.
46 reprStr
= "wxPython wrapper for DELETED %s object! (The C++ object no longer exists.)"
47 attrStr
= "The C++ part of the %s object has been deleted, attribute access no longer allowed."
50 if not hasattr(self
, "_name"):
51 self
._name
= "[unknown]"
52 return self
.reprStr
% self
._name
54 def __getattr__( self
, *args
):
55 if not hasattr(self
, "_name"):
56 self
._name
= "[unknown]"
57 raise PyDeadObjectError( self
.attrStr
% self
._name
)
59 def __nonzero__(self
):
63 #----------------------------------------------------------------------------
64 _wxPyCallAfterId
= None
66 def CallAfter(callable, *args
, **kw
):
68 Call the specified function after the current and pending event
69 handlers have been completed. This is also good for making GUI
70 method calls from non-GUI threads.
73 assert app
, 'No wxApp created yet'
75 global _wxPyCallAfterId
76 if _wxPyCallAfterId
is None:
77 _wxPyCallAfterId
= wx
.NewEventType()
78 app
.Connect(-1, -1, _wxPyCallAfterId
,
79 lambda event
: event
.callable(*event
.args
, **event
.kw
) )
81 evt
.SetEventType(_wxPyCallAfterId
)
82 evt
.callable = callable
85 wx
.PostEvent(app
, evt
)
88 #----------------------------------------------------------------------------
93 A convenience class for wxTimer, that calls the given callable
94 object once after the given amount of milliseconds, passing any
95 positional or keyword args. The return value of the callable is
96 availbale after it has been run with the GetResult method.
98 If you don't need to get the return value or restart the timer
99 then there is no need to hold a reference to this object. It will
100 hold a reference to itself while the timer is running (the timer
101 has a reference to self.Notify) but the cycle will be broken when
102 the timer completes, automatically cleaning up the wx.FutureCall
105 def __init__(self
, millis
, callable, *args
, **kwargs
):
107 self
.callable = callable
108 self
.SetArgs(*args
, **kwargs
)
119 def Start(self
, millis
=None, *args
, **kwargs
):
124 if millis
is not None:
127 self
.SetArgs(*args
, **kwargs
)
129 self
.timer
= wx
.PyTimer(self
.Notify
)
130 self
.timer
.Start(self
.millis
, wx
.TIMER_ONE_SHOT
)
136 Stop and destroy the timer.
138 if self
.timer
is not None:
143 def GetInterval(self
):
144 if self
.timer
is not None:
145 return self
.timer
.GetInterval()
151 return self
.timer
is not None and self
.timer
.IsRunning()
154 def SetArgs(self
, *args
, **kwargs
):
156 (Re)set the args passed to the callable object. This is
157 useful in conjunction with Restart if you want to schedule a
158 new call to the same callable object but with different
173 The timer has expired so call the callable.
175 if self
.callable and getattr(self
.callable, 'im_self', True):
177 self
.result
= self
.callable(*self
.args
, **self
.kwargs
)
179 wx
.CallAfter(self
.Stop
)
182 #----------------------------------------------------------------------------
183 #----------------------------------------------------------------------------
185 # Import other modules in this package that should show up in the
186 # "core" wx namespace
188 from windows
import *
189 from controls
import *
192 #----------------------------------------------------------------------------
193 #----------------------------------------------------------------------------