Add assignments for unmodified classes
[pygtk-shell.git] / PyGTKShell / Core.py
blob2132f7e14a93cf6c553241ba5eee31b189d4c78c
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """
4 PyGTK Shell core.
6 This module imports the required and optional dependencies and checks
7 their versions (TODO).
8 """
10 # Copyright (C) 2007,2009 Felix Rabe <public@felixrabe.net>
12 # This library is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU Lesser General Public
14 # License as published by the Free Software Foundation; either
15 # version 2.1 of the License, or (at your option) any later version.
17 # This library is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # Lesser General Public License for more details.
22 # You should have received a copy of the GNU Lesser General Public License
23 # along with this library; if not, write to the Free Software Foundation,
24 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 from PyGTKShell.Config import pygtkshell_config
27 _config = pygtkshell_config
28 pygtkshell_version = _config["version"] # DEPRECATED!
30 ## PyGTK
32 import gtk
33 import gtk.keysyms
34 import gobject
35 import pango
37 ## Cairo
39 cairo = None # Cairo not provided
40 if _config["api-provide-cairo"]:
41 import cairo
43 ## DBus
45 dbus = None # DBus not provided
46 if _config["api-provide-dbus"]:
47 import dbus
49 ## GConf
51 gconf = None # GConf not provided
52 if _config["api-provide-gconf"]:
53 import gconf
55 ## GtkSourceView
57 gtksourceview = None # GtkSourceView not provided
58 if _config["api-provide-gtksourceview"]:
59 try:
60 import gtksourceview2 as gtksourceview
61 except:
62 import gtksourceview
64 ## Twisted
66 twisted = None # Twisted not provided
67 if _config["api-provide-twisted"]:
68 import twisted
70 if _config["main-loop-integrate-twisted"]:
71 from twisted.internet import gtk2reactor
72 _twisted_reactor = gtk2reactor.portableInstall()
74 ## i18n
76 import gettext
77 # "a_" is used instead of plain "_" because Core gets * imported by API
78 # and API gets * imported by users. But "_" can't be imported anyway...
79 a_ = gettext.translation("pygtkshell", fallback = True).gettext
81 ## Integrated main loop support
83 """
84 PyGTK Shell main loop support. (TODO: move these docs into a docstring.)
86 You do not have to use these mechanisms if you are going to only use the
87 PyGTK main loop, i.e. by calling gtk.main() and gtk.main_quit().
89 Supported:
90 - PyGTK (gtk.main) always used
91 - Twisted (PortableGtkReactor) used on demand
92 - TODO: DBus
94 Usage:
95 # Boilerplate:
96 from PyGTKShell.Config import _config
97 _config["main-loop-integrate-dbus"] = True # not yet implemented
98 _config["main-loop-integrate-twisted"] = True
99 from PyGTKShell.API import *
101 # Set up your application here:
102 w = Window()
104 # Boilerplate:
105 main_loop_run()
108 def main_loop_run(*a, **kw):
109 integrate_dbus = _config["main-loop-integrate-dbus"]
110 integrate_twisted = _config["main-loop-integrate-twisted"]
111 if integrate_twisted:
112 _twisted_reactor.run(*a, **kw)
113 else:
114 gtk.main(*a, **kw)
116 def main_loop_quit(*a, **kw):
117 integrate_dbus = _config["main-loop-integrate-dbus"]
118 integrate_twisted = _config["main-loop-integrate-twisted"]
119 if integrate_twisted:
120 if not _twisted_reactor._stopped: # Twisted is picky about this
121 _twisted_reactor.stop(*a, **kw)
122 else:
123 gtk.main_quit(*a, **kw)