SWIGged updates for wxMac
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@20643 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1708,8 +1708,97 @@ def wxCallAfter(callable, *args, **kw):
|
||||
evt.kw = kw
|
||||
wxPostEvent(app, evt)
|
||||
|
||||
# an alias
|
||||
wxRunLater = wxCallAfter
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
|
||||
class wxFutureCall:
|
||||
"""
|
||||
A convenience class for wxTimer, that calls the given callable
|
||||
object once after the given amount of milliseconds, passing any
|
||||
positional or keyword args. The return value of the callable is
|
||||
availbale after it has been run with the GetResult method.
|
||||
|
||||
If you don't need to get the return value or restart the timer
|
||||
then there is no need to hold a reference to this object. It will
|
||||
hold a reference to itself while the timer is running (the timer
|
||||
has a reference to self.Notify) but the cycle will be broken when
|
||||
the timer completes, automatically cleaning up the wxFutureCall
|
||||
object.
|
||||
"""
|
||||
def __init__(self, millis, callable, *args, **kwargs):
|
||||
self.millis = millis
|
||||
self.callable = callable
|
||||
self.SetArgs(*args, **kwargs)
|
||||
self.runCount = 0
|
||||
self.hasRun = False
|
||||
self.result = None
|
||||
self.timer = None
|
||||
self.Start()
|
||||
|
||||
def __del__(self):
|
||||
self.Stop()
|
||||
|
||||
|
||||
def Start(self, millis=None):
|
||||
"""
|
||||
(Re)start the timer
|
||||
"""
|
||||
self.hasRun = False
|
||||
if millis is not None:
|
||||
self.millis = millis
|
||||
self.Stop()
|
||||
self.timer = wxPyTimer(self.Notify)
|
||||
self.timer.Start(self.millis, wxTIMER_ONE_SHOT)
|
||||
Restart = Start
|
||||
|
||||
|
||||
def Stop(self):
|
||||
"""
|
||||
Stop and destroy the timer.
|
||||
"""
|
||||
if self.timer is not None:
|
||||
self.timer.Stop()
|
||||
self.timer = None
|
||||
|
||||
|
||||
def GetInterval(self):
|
||||
if self.timer is not None:
|
||||
return self.timer.GetInterval()
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def IsRunning(self):
|
||||
return self.timer is not None and self.timer.IsRunning()
|
||||
|
||||
|
||||
def SetArgs(self, *args, **kwargs):
|
||||
"""
|
||||
(Re)set the args passed to the callable object. This is
|
||||
useful in conjunction with Restart if you want to schedule a
|
||||
new call to the same callable object but with different
|
||||
parameters.
|
||||
"""
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
def HasRun(self):
|
||||
return self.hasRun
|
||||
|
||||
def GetResult(self):
|
||||
return self.result
|
||||
|
||||
def Notify(self):
|
||||
"""
|
||||
The timer has expired so call the callable.
|
||||
"""
|
||||
if self.callable and getattr(self.callable, 'im_self', True):
|
||||
self.runCount += 1
|
||||
self.result = self.callable(*self.args, **self.kwargs)
|
||||
self.hasRun = True
|
||||
wxCallAfter(self.Stop)
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
@@ -1822,6 +1911,18 @@ class wxApp(wxPyApp):
|
||||
|
||||
def __init__(self, redirect=_defRedirect, filename=None, useBestVisual=False):
|
||||
wxPyApp.__init__(self)
|
||||
|
||||
if wx.wxPlatform == "__WXMAC__":
|
||||
try:
|
||||
import MacOS
|
||||
if not MacOS.WMAvailable():
|
||||
print """This program needs access to the screen. Please run with
|
||||
'pythonw', not 'python', and only when you are logged in on the main display
|
||||
of your Mac."""
|
||||
sys.exit(1)
|
||||
except:
|
||||
pass
|
||||
|
||||
self.stdioWin = None
|
||||
self.saveStdio = (sys.stdout, sys.stderr)
|
||||
|
||||
|
Reference in New Issue
Block a user