~screenlets-dev/screenlets/trunk

« back to all changes in this revision

Viewing changes to src/share/examples/services-example-3.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 if our needed service is running, exit if not
 
11
if not screenlets.services.service_is_running('MailCheck'):
 
12
        print "MailCheckScreenlet is not running."
 
13
        import sys
 
14
        sys.exit(1)
 
15
 
 
16
# get interface to the MailCheckScreenlet's service
 
17
mc =  screenlets.services.get_service_by_name('MailCheck')
 
18
 
 
19
# if interface was returned, 
 
20
if mc:
 
21
        try:
 
22
                # get id of first instance (we only want one here)
 
23
                instance_id = mc.get_first_instance()
 
24
                
 
25
                print "try getting/setting normal values"
 
26
                print mc.get(instance_id, 'x')
 
27
                mc.set(instance_id, 'x', 400)
 
28
                
 
29
                print "try getting/setting protected values"
 
30
                print mc.get(instance_id, 'pop3_account')
 
31
                mc.set(instance_id, 'pop3_account', ('user', 'pass'))
 
32
                
 
33
                # start mainloop (needed to receive events)
 
34
                import gobject
 
35
                mainloop = gobject.MainLoop()
 
36
                mainloop.run()
 
37
 
 
38
        except Exception, e:
 
39
                print "Error: " + str(e)
 
40