~ubuntu-branches/ubuntu/lucid/avant-window-navigator/lucid

« back to all changes in this revision

Viewing changes to bindings/python/__init__.py.in

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-04-11 21:17:27 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100411211727-m89sz4jd9dcd1ci4
Tags: 0.4.0-0ubuntu1
* New upstream release.
 - Fix crash when event is NULL (LP: #550541)
 - Fix crash in awn-setting when adding applet (LP: #557778)
* debian/control
 - Add mention of Awn in the description.
 - Add depends on python-desktop-agnostic for python-awn.
* debian/patches
 - 02-bad-pointer-init.patch: From upstream, bad unitialized pointer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2007 Neil Jagdish Patel <njpatel@gmail.com>
 
2
# Copyright (c) 2008, 2009 Mark Lee <avant-wn@lazymalevolence.com>
 
3
#
 
4
# This library is free software; you can redistribute it and/or
 
5
# modify it under the terms of the GNU Lesser General Public
 
6
# License as published by the Free Software Foundation; either
 
7
# version 2 of the License, or (at your option) any later version.
 
8
#
 
9
# This library is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
# Lesser General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public
 
15
# License along with this library; if not, write to the
 
16
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
# Boston, MA 02111-1307, USA.
 
18
 
 
19
# -*- Mode: Python; py-indent-offset: 4 -*-
 
20
 
 
21
import sys
 
22
from gettext import gettext as _
 
23
import locale
 
24
import getopt
 
25
 
 
26
# load the required modules:
 
27
import gobject
 
28
 
 
29
_version = getattr(gobject, 'pygobject_version', ())
 
30
if _version < (2, 11, 1):
 
31
    raise ImportError("Awn requires PyGObject >= 2.11.1, but %s was found" %
 
32
                      _version)
 
33
 
 
34
import gtk
 
35
 
 
36
from awn import *
 
37
import desktopagnostic.vfs
 
38
 
 
39
uid = "0"
 
40
window = 0
 
41
panel_id = 0
 
42
 
 
43
# i18n support
 
44
LOCALEDIR = '@LOCALEDIR@'
 
45
TEXTDOMAIN = '@GETTEXT_PACKAGE@'
 
46
locale.bindtextdomain(TEXTDOMAIN, LOCALEDIR)
 
47
 
 
48
def init(argv):
 
49
    global uid
 
50
    global window
 
51
    global panel_id
 
52
 
 
53
    desktopagnostic.vfs.init()
 
54
    
 
55
    try:
 
56
        opts, args = getopt.getopt(argv, "u:w:i:",
 
57
                                   ["uid=", "window=", "panel-id="])
 
58
    except getopt.GetoptError:
 
59
        print("Unable to parse args")
 
60
        sys.exit(2)
 
61
 
 
62
    for opt, arg in opts:
 
63
        if opt in ("-u", "--uid"):
 
64
            uid = arg
 
65
        elif opt in ("-w", "--window"):
 
66
            # casting to long because of
 
67
            # http://bugzilla.gnome.org/show_bug.cgi?id=539365
 
68
            window = long(arg)
 
69
        elif opt in ("-i", "--panel-id"):
 
70
            panel_id = int(arg)
 
71
 
 
72
 
 
73
def embed_applet(applet):
 
74
    gtk.Plug.__init__(applet, globals()['window'])
 
75
    # applet's embedded signal handler automatically calls show_all()
 
76
 
 
77
 
 
78
def check_dependencies(scope, *modules, **choice_modules):
 
79
    '''
 
80
    Special flag: exit_on_failure=bool
 
81
    Makes the applet exit if a dependency is not found.
 
82
    '''
 
83
    exit_on_failure = True
 
84
    if len(choice_modules) > 0 and 'exit_on_failure' in choice_modules:
 
85
        exit_on_failure = bool(choice_modules['exit_on_failure'])
 
86
        del choice_modules['exit_on_failure']
 
87
    not_found_modules = []
 
88
 
 
89
    def add_module(module, name=None):
 
90
        try:
 
91
            if '.' in module:
 
92
                mod_split = module.split('.')
 
93
                submod = mod_split[-1]
 
94
                from_list = [submod]
 
95
                if name is None:
 
96
                    name = submod
 
97
            else:
 
98
                if name is None:
 
99
                    name = module
 
100
                from_list = []
 
101
            scope[name] = __import__(module, scope, locals(), from_list)
 
102
            return True
 
103
        except ImportError:
 
104
            return False
 
105
    for module in modules:
 
106
        success = add_module(module)
 
107
        if not success:
 
108
            not_found_modules.append(module)
 
109
    for name, mods in choice_modules.iteritems():
 
110
        found = False
 
111
        for module in mods:
 
112
            success = add_module(module, name)
 
113
            if success:
 
114
                found = True
 
115
                break
 
116
        if not found:
 
117
            not_found_modules.append(' or '.join(mods))
 
118
    if len(not_found_modules) > 0:
 
119
        try:
 
120
            import pygtk
 
121
            pygtk.require('2.0')
 
122
        except:
 
123
            pass
 
124
        import gtk
 
125
        RESPONSE_WIKI = 21
 
126
        msg = _('''\
 
127
The following Python modules could not be found: %s.  There are a few possible
 
128
explanations for this:
 
129
 
 
130
1. You do not have this Python module installed.  In this case, you should
 
131
visit the AWN wiki's applets section to figure out the exact name of the
 
132
package for your distribution that provides this module.
 
133
 
 
134
2. The module is installed in a non-standard location.  This is usually the
 
135
case when you manually install a package, that is, not via your distribution's
 
136
package manager.  This situation is explained in the FAQ section of the wiki.
 
137
''') % ', '.join(not_found_modules)
 
138
 
 
139
        dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR,
 
140
                                   gtk.BUTTONS_NONE, msg)
 
141
        dialog.add_button(_('Awn Wiki'), RESPONSE_WIKI).grab_default()
 
142
        dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
 
143
        dialog.set_alternative_button_order([gtk.RESPONSE_OK, RESPONSE_WIKI])
 
144
        if dialog.run() == RESPONSE_WIKI:
 
145
            url = 'http://wiki.awn-project.org/Applets:Dependencies'
 
146
            import webbrowser
 
147
            if hasattr(webbrowser, 'open_new_tab'):
 
148
                webbrowser.open_new_tab(url)
 
149
            else:
 
150
                webbrowser.open_new(url)
 
151
        dialog.hide_all()
 
152
        dialog.destroy()
 
153
        if exit_on_failure:
 
154
            import sys
 
155
            sys.exit(RESPONSE_WIKI)