[Tutor] Detecting wx
John Fouhy
john at fouhy.net
Thu Feb 12 23:39:59 CET 2009
2009/2/13 Ricardo Aráoz <ricaraoz at gmail.com>:
> There are a couple of utilities I want to be able to run from the
> command window. Now, if I'm at the command window, or Idle, or other non
> wx shell I want to establish a wx app. But if I'm in pythonWin, PyCrust,
> or any other wx based shell then there is a wx event loop already
> running and if I create other I'll be in trouble. My question is if
> there is a way in which I can detect if there is a wx event loop running
> in my environment?
You could try something like:
wx.CallAfter(lambda: None)
Here's what I get in a quick test with no app running:
>>> import wx
>>> wx.CallAfter(lambda: None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/wx-2.8-mac-unicode/wx/_core.py",
line 14359, in CallAfter
assert app is not None, 'No wx.App created yet'
AssertionError: No wx.App created yet
Whereas if I do the same thing from pycrust, nothing happens (that is,
presumably my lambda executes).
--
John.
More information about the Tutor
mailing list