def _detect_toolkit():
  global _toolkit
  # use curses if its specified
  if '--curses' in sys.argv:
    _toolkit = TOOLKIT_CURSES
    return

  # use chrome if specified
  if '--chrome' in sys.argv:
    _toolkit = TOOLKIT_CHROME
    return

  # check whether we even have X
  if os.getenv('DISPLAY'):
    can_have_gui = True
  elif sys.platform == 'darwin':
    can_have_gui = True
  else:
    can_have_gui = False

  # try using gtk
  if can_have_gui:
    try:
      import pygtk
      pygtk.require('2.0')
      _toolkit = TOOLKIT_GTK
      return
    except __HOLE__:
      pass

  # if that didn't work, try using wx
  if can_have_gui:
    try:
      import wx
      _toolkit = TOOLKIT_WX
      return
    except ImportError:
      if sys.platform == 'darwin':
        sys.stderr.write("""You could have a nice pretty WxWidgets-based UI!

1. Download wxpython 2.9 Cocoa for python 2.7: http://downloads.sourceforge.net/wxpython/wxPython2.9-osx-2.9.5.0-cocoa-py2.7.dmg
2. Mount the image (double click the downloaded .dmg file)
3. Open a Terminal window, and run the following:
   sudo installer -pkg /Volumes/wxPython2.9-osx-2.9.5.0-cocoa-py2.7/wxPython2.9-osx-cocoa-py2.7.pkg  -target /

""")

  # use curses as a last resort
  if '--curses' in sys.argv or not can_have_gui:
    _toolkit = TOOLKIT_CURSES
    return

  _toolkit = None
dataset/ETHPy150Open natduca/quickopen/src/message_loop.py/_detect_toolkit