~screenlets-dev/screenlets/trunk

« back to all changes in this revision

Viewing changes to src/share/examples/services-example.py

  • Committer: Rico Pfaus
  • Date: 2007-08-20 10:47:06 UTC
  • Revision ID: ryx@ryxperience.com-20070820104706-bghrnlck8myqok0m
Bumped version to 0.0.11, creating new bazaar branch 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# This is an example of accessing the new ScreenletService. It can be used
 
4
# to access signals and methods within a Screenlet from other applications or
 
5
# other Screenlets.
 
6
 
 
7
# import services-module
 
8
import screenlets.services
 
9
 
 
10
# check for Clock-service
 
11
if not screenlets.services.service_is_running('Clock'):
 
12
        print "Clock-service not found. Pleaselaunch the ClockScreenlet first."
 
13
else:
 
14
        # get general interface for this screenlet
 
15
        service_iface = screenlets.services.get_service_by_name('Clock')
 
16
        # get interface to the ClockScreenlet's custom service (we need to
 
17
        # pass the special interface for the Clock's additonal methods here)
 
18
        clock_iface =  screenlets.services.get_service_by_name('Clock', 
 
19
                interface='org.screenlets.Clock')
 
20
        
 
21
        # if interface was returned, 
 
22
        if service_iface:
 
23
                
 
24
                try:
 
25
                        # get list with instance ids
 
26
                        ids = service_iface.list_instances()
 
27
                        for id in ids:
 
28
                                print id
 
29
                        
 
30
                        # id of first instance
 
31
                        instance_id = ids[0]
 
32
                        
 
33
                        # + METHDODS: remote-calling of methods in a Screenlet
 
34
                        # call testing functions
 
35
                        service_iface.debug('Hello World!')
 
36
                        service_iface.test()
 
37
                        # set options
 
38
                        #clock.set(instance_id, 'theme_name', 'tango')
 
39
                        service_iface.set(instance_id, 'x', 700)
 
40
                        service_iface.set(instance_id, 'y', 500)
 
41
                        # add a new instance
 
42
                        service_iface.add('myClock')
 
43
                        service_iface.set('myClock', 'scale', 3.5)
 
44
                        service_iface.set('myClock', 'theme_name', 'tango')
 
45
                        # if clock service is available
 
46
                        if clock:
 
47
                                # call special function of the ClockService
 
48
                                #clock.debug('TEST')
 
49
                                print clock_iface.get_time(instance_id)
 
50
                                print clock_iface.get_date(instance_id)
 
51
                        
 
52
                        # + SIGNALS: connecting to signals in a screenlet
 
53
                        def handle_alarm (instance_id):
 
54
                                print "Signal received: Clock '%s' raised alarm." % (instance_id)
 
55
                        clock_iface.connect_to_signal('alarm_start', handle_alarm)
 
56
                        
 
57
                        # start mainloop (needed to receive events)
 
58
                        import gobject
 
59
                        mainloop = gobject.MainLoop()
 
60
                        mainloop.run()
 
61
 
 
62
                except Exception, e:
 
63
                        print "Error: " + str(e)
 
64