def has_display():
"""
Tests to see if Python is currently running with gtk
"""
# FIXME: currently, Gtk.init_check() requires all strings
# in argv, and we might have unicode.
temp, sys.argv = sys.argv, sys.argv[:1]
try:
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
except ImportError:
return False
try:
test = Gtk.init_check(temp) and \
Gdk.Display.get_default()
sys.argv = temp
return bool(test)
except:
sys.argv = temp
return False
# A couple of places add menu accelerators using <alt>, which doesn't
# work with Gtk-quartz. <Meta> is the usually correct replacement, but
# in one case the key is a number, and <meta>number is used by Spaces
# (a mac feature), so we'll use control instead.
评论列表
文章目录