tpaviot/pythonocc — Issue #49: SimpleGUI.py is a little too simple...
Author: jf---
Created: 2011-12-29 21:03:27+00:00
State: open

Wow, i just dropped in the debugger, and the simplegui is not simple, its pretty stupid: look at the code finding a GUI backend; in fact on my machine it loads ALL of these backends...

I suggest the following:

try:
from traits.etsconfig.api import ETSConfig
if ETSConfig.toolkit == 'wx' [ or pyqt or pyside ]:
load that framework
except importError
load the first toolkit that succeeds and than stop loading it...
with a preference of Qt over Wx [ processEvents is awesome!!! ]

try:
import wx
HAVE_WX = True
except:
HAVE_WX = False
# Check PyQt
try:
from PyQt4 import QtCore, QtGui
HAVE_QT = True
except:
HAVE_QT = False
# Check python-xlib
try:
from Xlib import display as display_xlib, X
HAVE_XLIB = True
except:
HAVE_XLIB = False
# Then define the default backend
if HAVE_WX:
DEFAULT_BACKEND = 'wx'
elif HAVE_QT:
DEFAULT_BACKEND = 'qt'
elif HAVE_XLIB:
DEFAULT_BACKEND = 'x'
else:
raise AssertionError('No backend.')
# By default, used backend is the default_backend
USED_BACKEND = DEFAULT_BACKEND