aboutsummaryrefslogtreecommitdiff
path: root/tests/examples/orientation_experiment2.py
blob: e421e2a4cc655999808a7fb1b96d9d0bf74fb1b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import traceback
import dbus
import sys
import gobject

from dbus.mainloop.glib import DBusGMainLoop

edge_key = "Context.Device.Orientation.edgeUp"
facing_key = "Context.Device.Orientation.facingUp"

def handle_signal(changed):
	print "Got signal"
	struct1 = changed[edge_key]
	struct2 = changed[facing_key]
	print "Orientation:", struct1[1], struct2[1]

def execute_subscribe():
	bus = dbus.SessionBus()
	try:
		proxy_object_manager = bus.get_object("org.freedesktop.ContextKit","/org/freedesktop/ContextKit/Manager")
		iface_manager = dbus.Interface(proxy_object_manager, "org.freedesktop.ContextKit.Manager")
		print "Requesting the subscriber object"
		# Get the subscriber object
		new_object_path = iface_manager.GetSubscriber()
		
		print "Got an object path", new_object_path
		# And then execute the actual subscribe property_names
		
		proxy_object_subscriber = bus.get_object("org.freedesktop.ContextKit", new_object_path)
		iface_subscriber = dbus.Interface(proxy_object_subscriber, "org.freedesktop.ContextKit.Subscriber")
		
		# Connect to the signal
		print "Connecting to the signal"
		iface_subscriber.connect_to_signal("Changed", handle_signal)
		
		print "Executing the Subscribe"
		ret = iface_subscriber.Subscribe([edge_key, facing_key])
		
		print "Returned:", ret
		
		loop = gobject.MainLoop()
		loop.run()

	except dbus.DBusException:
		print "Caught an exception"
		traceback.print_exc()


if __name__ == "__main__":
	DBusGMainLoop(set_as_default=True)
	
	execute_subscribe()