~cwayne/onehundredscopes/utilities-precise-with-thesaurus

« back to all changes in this revision

Viewing changes to src/unity-lens-utilities

  • Committer: David Callé
  • Date: 2011-11-20 20:17:51 UTC
  • Revision ID: davidc@framli.eu-20111120201751-9snyokm1irexnj6s
Branch init + packaging

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
3
#    Copyright (c) 2011 David Calle <davidc@framli.eu>
 
4
 
 
5
#    This program is free software: you can redistribute it and/or modify
 
6
#    it under the terms of the GNU General Public License as published by
 
7
#    the Free Software Foundation, either version 3 of the License, or
 
8
#    (at your option) any later version.
 
9
 
 
10
#    This program is distributed in the hope that it will be useful,
 
11
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
#    GNU General Public License for more details.
 
14
 
 
15
#    You should have received a copy of the GNU General Public License
 
16
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 
 
18
import sys
 
19
import os
 
20
from gi.repository import GLib, GObject, Gio
 
21
from gi.repository import Dee
 
22
# FIXME: Some weird bug in Dee or PyGI makes Dee fail unless we probe
 
23
#        it *before* we import the Unity module... ?!
 
24
_m = dir(Dee.SequenceModel)
 
25
from gi.repository import Unity
 
26
 
 
27
BUS_NAME = "net.launchpad.lens.utilities"
 
28
 
 
29
class Daemon:
 
30
 
 
31
        def __init__ (self):
 
32
                # The path for the Lens *must* also match the one in our .lens file
 
33
                self._lens = Unity.Lens.new ("/net/launchpad/lens/utilities", "utilities")
 
34
                self._scope = Unity.Scope.new ("/net/launchpad/lens/utilities/main")
 
35
                
 
36
                self._lens.props.search_hint = "Use tools"
 
37
                self._lens.props.visible = False;
 
38
                self._lens.props.search_in_global = True;
 
39
                
 
40
                # Populate categories
 
41
                cats = []
 
42
                cats.append (Unity.Category.new ("Unity.CategoryRenderer.VERTICAL_TILE",
 
43
                                                 Gio.ThemedIcon.new("None"),
 
44
                                                 Unity.CategoryRenderer.VERTICAL_TILE))
 
45
 
 
46
                self._lens.props.categories = cats
 
47
                
 
48
                # Populate filters
 
49
                filters = []
 
50
                self._lens.props.filters = filters
 
51
                self._lens.export ();
 
52
 
 
53
if __name__ == "__main__":
 
54
        session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)
 
55
        session_bus = Gio.DBusProxy.new_sync (session_bus_connection, 0, None,
 
56
                                              'org.freedesktop.DBus',
 
57
                                              '/org/freedesktop/DBus',
 
58
                                              'org.freedesktop.DBus', None)
 
59
        result = session_bus.call_sync('RequestName',
 
60
                                       GLib.Variant ("(su)", (BUS_NAME, 0x4)),
 
61
                                       0, -1, None)
 
62
                                       
 
63
        # Unpack variant response with signature "(u)". 1 means we got it.
 
64
        result = result.unpack()[0]
 
65
        
 
66
        if result != 1 :
 
67
                print >> sys.stderr, "Failed to own name %s. Bailing out." % BUS_NAME
 
68
                raise SystemExit (1)
 
69
        
 
70
        daemon = Daemon()
 
71
        GObject.MainLoop().run()