Package gtk
[hide private]
[frames] | no frames]

Source Code for Package gtk

  1  # -*- Mode: Python; py-indent-offset: 4 -*- 
  2  # pygtk - Python bindings for the GTK toolkit. 
  3  # Copyright (C) 1998-2003  James Henstridge 
  4  #               2004-2006  Johan Dahlin 
  5  # 
  6  #   gtk/__init__.py: initialisation file for gtk package. 
  7  # 
  8  # This library is free software; you can redistribute it and/or 
  9  # modify it under the terms of the GNU Lesser General Public 
 10  # License as published by the Free Software Foundation; either 
 11  # version 2.1 of the License, or (at your option) any later version. 
 12  # 
 13  # This library is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 16  # Lesser General Public License for more details. 
 17  # 
 18  # You should have received a copy of the GNU Lesser General Public 
 19  # License along with this library; if not, write to the Free Software 
 20  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
 21  # USA 
 22   
 23  import sys 
 24   
 25  # For broken embedded programs which forgot to call Sys_SetArgv 
 26  if not hasattr(sys, 'argv'): 
 27      sys.argv = [] 
 28   
 29  # load the required modules: 
 30  import gobject as _gobject 
 31   
 32  ver = getattr(_gobject, 'pygobject_version', ()) 
 33  if ver < (2, 11, 1): 
 34      raise ImportError( 
 35          "PyGTK requires PyGObject 2.11.1 or higher, but %s was found" % (ver,)) 
 36   
 37  if 'gtk._gtk' in sys.modules: 
 38      _gtk = sys.modules['gtk._gtk'] 
 39  else: 
 40      from gtk import _gtk 
 41   
 42  import gdk 
 43   
 44  from gtk._lazyutils import LazyNamespace, LazyModule 
 45  from gtk.deprecation import _Deprecated, _DeprecatedConstant 
 46   
47 -def _init():
48 import sys 49 50 sys_path = sys.path[:] 51 52 _gtk.init_check() 53 54 # init_check calls PySys_SetArgv which calls sys.path.insert(0, ''), 55 # which causes problems for pychecker, restore it if modified. 56 if sys.path != sys_path: 57 sys.path[:] = sys_path 58 59 # install the default log handlers 60 _gtk.add_log_handlers()
61 62 keysyms = LazyModule('keysyms', locals()) 63 64 _init() 65 66 # CAPI 67 _PyGtk_API = _gtk._PyGtk_API 68 69 gdk.INPUT_READ = _gobject.IO_IN | _gobject.IO_HUP | _gobject.IO_ERR 70 gdk.INPUT_WRITE = _gobject.IO_OUT | _gobject.IO_HUP 71 gdk.INPUT_EXCEPTION = _gobject.IO_PRI 72 73 # Python 2.5+ context manager, usable through 'with' keyword.
74 -class _Lock(object):
75 __enter__ = gdk.threads_enter
76 - def __exit__(*ignored):
77 gdk.threads_leave()
78 gdk.lock = _Lock() 79 80 # old names compatibility ... 81 idle_add = _Deprecated(_gobject, 'idle_add', 'idle_add', 'gobject') 82 idle_remove = _Deprecated(_gobject, 'source_remove', 'idle_remove', 'gobject') 83 timeout_add = _Deprecated(_gobject, 'timeout_add', 'timeout_add', 'gobject') 84 timeout_remove = _Deprecated(_gobject, 'source_remove', 'timeout_remove', 85 'gobject') 86 input_add = _Deprecated(_gobject, 'io_add_watch', 'input_add', 'gobject') 87 input_add_full = _Deprecated(_gobject, 'io_add_watch', 'input_add_full', 88 'gobject') 89 input_remove = _Deprecated(_gobject, 'source_remove', 'input_remove', 'gobject') 90 91 mainloop = _Deprecated('gtk', 'main', 'mainloop') 92 mainquit = _Deprecated('gtk', 'main_quit', 'mainquit') 93 mainiteration = _Deprecated('gtk', 'main_iteration', 94 'mainiteration') 95 load_font = _Deprecated(gdk, 'Font', 'load_font', 'gtk.gdk') 96 load_fontset = _Deprecated(gdk, 'fontset_load', 'load_fontset', 97 'gtk.gdk') 98 create_pixmap = _Deprecated(gdk, 'Pixmap', 'create_pixmap', 'gtk.gdk') 99 create_pixmap_from_xpm = _Deprecated(gdk, 'pixmap_create_from_xpm', 100 'pixmap_create_from_xpm', 'gtk.gdk') 101 create_pixmap_from_xpm_d = _Deprecated(gdk, 'pixmap_create_from_xpm_d', 102 'pixmap_create_from_xpm_d', 'gtk.gdk') 103 104 threads_init = _Deprecated(gdk, 'threads_init', 'threads_init', 'gtk.gdk') 105 threads_enter = _Deprecated(gdk, 'threads_enter', 'threads_enter', 'gtk.gdk') 106 threads_leave = _Deprecated(gdk, 'threads_leave', 'threads_leave', 'gtk.gdk') 107 108 TRUE = _DeprecatedConstant(True, 'gtk.TRUE', 'True') 109 FALSE = _DeprecatedConstant(False, 'gtk.FALSE', 'False') 110 111 # Can't figure out how to deprecate gdk.Warning 112 gdk.Warning = Warning 113 114 # We don't want to export this 115 del _Deprecated, _DeprecatedConstant, _gobject, _init, _Lock 116 117 # Do this as late as possible, so programs like pyflakes can check 118 # everything above 119 from gtk._gtk import * 120 121 # Make PyGTK interactive 122 set_interactive(1) 123 124 # # For testing, so you can just turn off dynamicnamespace in gtk.override 125 # if hasattr(_gtk, '_get_symbol_names'): 126 # import gtk 127 # ns = LazyNamespace(_gtk, locals()) 128 # ns.add_submodule('glade', '_glade') 129 # ns.add_submodule('_gtk', 'gtk._gtk') 130 # sys.modules['gtk'] = ns 131 # sys.modules['gtk.glade'] = LazyModule('_glade', {}) 132