1
by David Callé
Branch init |
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.ohscopes" |
|
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/ohscopes", "ohscopes") |
|
34 |
self._scope = Unity.Scope.new ("/net/launchpad/lens/ohscopes/main") |
|
35 |
||
36 |
self._lens.props.search_hint = "Test Scopes" |
|
37 |
self._lens.props.visible = True; |
|
38 |
self._lens.props.search_in_global = False; |
|
39 |
||
40 |
# Populate categories
|
|
41 |
icon_ohscopes = "/usr/share/ohscopes/data/ohscopes-lens.svg" |
|
42 |
cats = [] |
|
43 |
cats.append (Unity.Category.new ("Unity.CategoryRenderer.VERTICAL_TILE", |
|
44 |
Gio.ThemedIcon.new(icon_ohscopes), |
|
45 |
Unity.CategoryRenderer.VERTICAL_TILE)) |
|
46 |
cats.append (Unity.Category.new ("Unity.CategoryRenderer.HORIZONTAL_TILE", |
|
47 |
Gio.ThemedIcon.new(icon_ohscopes), |
|
48 |
Unity.CategoryRenderer.HORIZONTAL_TILE)) |
|
49 |
||
50 |
self._lens.props.categories = cats |
|
51 |
||
52 |
# Populate filters
|
|
53 |
filters = [] |
|
54 |
self._lens.props.filters = filters |
|
55 |
||
56 |
self._lens.export (); |
|
57 |
||
58 |
if __name__ == "__main__": |
|
59 |
session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None) |
|
60 |
session_bus = Gio.DBusProxy.new_sync (session_bus_connection, 0, None, |
|
61 |
'org.freedesktop.DBus', |
|
62 |
'/org/freedesktop/DBus', |
|
63 |
'org.freedesktop.DBus', None) |
|
64 |
result = session_bus.call_sync('RequestName', |
|
65 |
GLib.Variant ("(su)", (BUS_NAME, 0x4)), |
|
66 |
0, -1, None) |
|
67 |
||
68 |
# Unpack variant response with signature "(u)". 1 means we got it.
|
|
69 |
result = result.unpack()[0] |
|
70 |
||
71 |
if result != 1 : |
|
72 |
print >> sys.stderr, "Failed to own name %s. Bailing out." % BUS_NAME |
|
73 |
raise SystemExit (1) |
|
74 |
||
75 |
daemon = Daemon() |
|
76 |
GObject.MainLoop().run() |