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

« back to all changes in this revision

Viewing changes to bindings/python/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2008-05-24 14:42:01 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080524144201-r3v8e4g2hv2q1i9x
Tags: 0.2.6-6
* debian/patches/04-fix-colormap.patch
 - Fix crash in awn-manager if colormap == None. Thanks Emme for the 
   patch. (Closes: #482030) 

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 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, os
 
22
import getopt
 
23
 
 
24
# load the required modules:
 
25
import gobject as _gobject
 
26
 
 
27
ver = getattr(_gobject, 'pygobject_version', ())
 
28
if ver < (2, 11, 1):
 
29
  raise ImportError("PyGTK requires PyGObject 2.11.1 or higher, but %s was found" % (ver,))
 
30
 
 
31
from awn import *
 
32
 
 
33
CONFIG_LIST_BOOL, CONFIG_LIST_FLOAT, CONFIG_LIST_INT, CONFIG_LIST_STRING = range(4)
 
34
CONFIG_DEFAULT_GROUP = 'DEFAULT'
 
35
 
 
36
uid = "0"
 
37
window = 0
 
38
orient = 0
 
39
height = 0
 
40
 
 
41
def init (argv):
 
42
  global uid
 
43
  global window
 
44
  global orient
 
45
  global height
 
46
 
 
47
  try: 
 
48
    opts, args = getopt.getopt (argv, "u:w:o:h:", 
 
49
                                ["uid=", "window=", "orient=", "height="])
 
50
  except getopt.GetoptError:
 
51
    print ("Unable to parse args")
 
52
    sys.exit (2)
 
53
 
 
54
  for opt, arg in opts:
 
55
    if opt in ("-u", "--uid"):
 
56
      uid = arg
 
57
      #print "uid = " + arg + " " + str (type (uid))
 
58
    elif opt in ("-w", "--window"):
 
59
      window = int (arg)
 
60
      #print "window = " + arg+ " " + str (type (window))
 
61
    elif opt in ("-o", "--orient"):
 
62
      orient = int (arg)
 
63
      #print "orient = " + arg + " " + str (type (orient))
 
64
    elif opt in ("-h", "--height"):
 
65
      height = int (arg)
 
66
      #print "height = " + arg + " " + str (type (height))
 
67
 
 
68
def init_applet (applet):
 
69
  global uid
 
70
  global orient
 
71
  global height
 
72
  global window
 
73
  plug = awn.Plug (applet)
 
74
  plug.add (applet)
 
75
  if (window):
 
76
    plug.construct (window)
 
77
  else:
 
78
    plug.construct (-1)
 
79
    plug.show_all ()
 
80
 
 
81
def check_dependencies(scope, *modules):
 
82
    not_found_modules = []
 
83
    for module in modules:
 
84
        try:
 
85
            scope[module] = __import__(module, scope)
 
86
        except ImportError:
 
87
            not_found_modules.append(module)
 
88
    if len(not_found_modules) > 0:
 
89
        try:
 
90
            import pygtk
 
91
            pygtk.require('2.0')
 
92
        except:
 
93
            pass
 
94
        import gtk
 
95
        RESPONSE_WIKI = 21
 
96
        msg =  'The following Python modules could not be found: %s.  There are a few possible explanations for this:\n' % (', '.join(not_found_modules))
 
97
        msg += '1. You do not have this Python module installed.  In this case, you should visit the AWN wiki\'s applets section to figure out the exact name of the package for your distribution that provides this module.\n'
 
98
        msg += '2. The module is installed in a non-standard location.  This is usually the case when you manually install a package, that is, not via your distribution\'s package manager.  This situation is explained in the FAQ section of the wiki.'
 
99
        dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_NONE, msg)
 
100
        dialog.add_button('AWN Wiki', RESPONSE_WIKI).grab_default()
 
101
        dialog.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
 
102
        dialog.set_alternative_button_order([gtk.RESPONSE_OK, RESPONSE_WIKI])
 
103
        if dialog.run() == RESPONSE_WIKI:
 
104
            url = 'http://wiki.awn-project.org/'
 
105
            import webbrowser
 
106
            if hasattr(webbrowser, 'open_new_tab'):
 
107
                webbrowser.open_new_tab(url)
 
108
            else:
 
109
                webbrowser.open_new(url)
 
110
        dialog.hide_all()
 
111
        dialog.destroy()
 
112
        import sys
 
113
        sys.exit(RESPONSE_WIKI)
 
114
 
 
115
class ConfigLock:
 
116
    def __init__(self, group, key):
 
117
        self.fd = config_key_lock_open(group, key)
 
118
 
 
119
    def lock(self, operation):
 
120
        config_key_lock(self.fd, operation)
 
121
 
 
122
    def close(self):
 
123
        config_key_lock_close(self.fd)