diff options
author | Olivier Tilloy <olivier.tilloy@canonical.com> | 2012-10-05 13:26:10 +0000 |
---|---|---|
committer | Tarmac <> | 2012-10-05 13:26:10 +0000 |
commit | c3fbab270f60fc374bae50e787e0b2046f127a07 (patch) | |
tree | 61d0eae8f1c1e3d23fb6559cb19e920b167b187c /examples/exportactiongroup.py | |
parent | 7961150ad1eaa1b3bc62d5215e274a7b58b0ef72 (diff) | |
parent | 696fba50395807c344325af11e71ec74cf370c3d (diff) | |
download | qmenumodel-c3fbab270f60fc374bae50e787e0b2046f127a07.tar.gz qmenumodel-c3fbab270f60fc374bae50e787e0b2046f127a07.tar.bz2 qmenumodel-c3fbab270f60fc374bae50e787e0b2046f127a07.zip |
Tweaks to the structure of the code, and added example code.. Approved by Renato Araujo Oliveira Filho, jenkins.
Diffstat (limited to 'examples/exportactiongroup.py')
-rwxr-xr-x | examples/exportactiongroup.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/examples/exportactiongroup.py b/examples/exportactiongroup.py new file mode 100755 index 0000000..f69416e --- /dev/null +++ b/examples/exportactiongroup.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- + +""" +This example script exports an action group on the session bus under the name +com.canonical.testactiongroup and at the object path +/com/canonical/testactiongroup. +""" + +import sys + +from gi.repository import Gio +from gi.repository import GLib + + +BUS_NAME = 'com.canonical.testactiongroup' +BUS_OBJECT_PATH = '/com/canonical/testactiongroup' + + +def action_activated(action, data): + name = action.get_name() + if action.get_state_type() is None: + print 'stateless action activated: %s' % name + else: + print 'stateful action activated: %s (current state: %s)' % + (name, action.get_state()) + + +if __name__ == '__main__': + bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) + # Claim well-known bus name and ensure only one instance of self is running + # at any given time. + # http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-names + proxy = Gio.DBusProxy.new_sync(bus, 0, None, + 'org.freedesktop.DBus', + '/org/freedesktop/DBus', + 'org.freedesktop.DBus', None) + result = proxy.RequestName('(su)', BUS_NAME, 0x4) + if result != 1 : + print >> sys.stderr, ("Name '%s' is already owned on the session bus." + "Aborting.") % BUS_NAME + sys.exit(1) + + group = Gio.SimpleActionGroup() + foo = Gio.SimpleAction.new('foo', None) + group.insert(foo) + bar = Gio.SimpleAction.new_stateful('bar', None, GLib.Variant.new_boolean(False)) + group.insert(bar) + bleh = Gio.SimpleAction.new_stateful('bleh', None, GLib.Variant.new_string('bleh')) + group.insert(bleh) + for name in group.list_actions(): + action = group.lookup_action(name) + action.connect('activate', action_activated) + bus.export_action_group(BUS_OBJECT_PATH, group) + + GLib.MainLoop().run() + |