Back to index

libindicate  12.10.0
listen-and-print.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 #Copyright 2009 Canonical Ltd.
00004 #
00005 #Authors:
00006 #    Eitan Isaacson <eitan@ascender.com>
00007 #
00008 #This program is free software: you can redistribute it and/or modify it 
00009 #under the terms of either or both of the following licenses:
00010 #
00011 #1) the GNU Lesser General Public License version 3, as published by the 
00012 #Free Software Foundation; and/or
00013 #2) the GNU Lesser General Public License version 2.1, as published by 
00014 #the Free Software Foundation.
00015 #
00016 #This program is distributed in the hope that it will be useful, but 
00017 #WITHOUT ANY WARRANTY; without even the implied warranties of 
00018 #MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 
00019 #PURPOSE.  See the applicable version of the GNU Lesser General Public 
00020 #License for more details.
00021 #
00022 #You should have received a copy of both the GNU Lesser General Public 
00023 #License version 3 and version 2.1 along with this program.  If not, see 
00024 #<http://www.gnu.org/licenses/>
00025 #
00026 
00027 import indicate
00028 import gobject
00029 import gtk
00030 from time import time, ctime, strftime, localtime
00031 
00032 def show_property_cb(listener, server, indicator, prop, propertydata):
00033     print "Indicator Property:       %s %s %s %s" % \
00034         (server, indicator, prop, propertydata)
00035 
00036 def show_property_time_cb(listener, server, indicator, prop, propertydata):
00037     print "Indicator Property:       %s %s %s %s" % \
00038         (server, indicator, prop, 
00039          strftime("%I:%M", localtime(propertydata)))
00040 
00041 def show_property_icon_cb(listener, server, indicator, prop, propertydata):
00042     print "Indicator Property:       %s %s %s %dx%d" % \
00043         (server, indicator, prop, 
00044          propertydata.get_width(), propertydata.get_height())
00045 
00046 def show_property(listener, server, indicator, prop):
00047     if prop == "icon":
00048         listener.get_indicator_property_icon(server, indicator, 
00049                                              prop, show_property_icon_cb)
00050     elif prop == "time":
00051         listener.get_indicator_property_time(server, indicator, 
00052                                              prop, show_property_time_cb)
00053     else:
00054         listener.get_indicator_property(server, indicator, 
00055                                         prop, show_property_cb)
00056 
00057 def get_properties(listener, server, indicator):
00058     # TODO: Not in libindicate API yet.
00059     return
00060 
00061 def indicator_added(listener, server, indicator):
00062     print "Indicator Added:          %s %s" % \
00063         (server, indicator)
00064 
00065 def indicator_removed(listener, server, indicator):
00066     print "Indicator Removed:        %s %s" % \
00067         (server, indicator)
00068 
00069 def indicator_modified(listener, server, indicator, prop):
00070     print "Indicator Modified:       %s %s %s" % \
00071         (server, indicator, prop)
00072     show_property(listener, server, 
00073                   indicator, prop)
00074 
00075 def type_cb(listener, server, value):
00076     print "Indicator Server Type:    %s %s" % \
00077         (server, value)
00078 
00079 def desktop_cb(listener, server, value):
00080     print "Indicator Server Desktop: %s %s" % \
00081         (server, value)
00082 
00083 def server_added(listener, server, typ):
00084     print "Indicator Server Added:   %s %s" % \
00085         (server.get_dbusname(), typ)
00086     listener.server_get_type(server, type_cb)
00087     listener.server_get_desktop(server, desktop_cb)
00088 
00089 def server_removed(listener, server, typ):
00090     print "Indicator Server Removed: %s %s" % \
00091         (server, typ)
00092 
00093 if __name__ == "__main__":
00094     listener = indicate.indicate_listener_ref_default()
00095     listener.connect("indicator-added", indicator_added)
00096     listener.connect("indicator-removed", indicator_removed)
00097     listener.connect("indicator-modified", indicator_modified)
00098     listener.connect("server-added", server_added)
00099     listener.connect("server-removed", server_removed)
00100 
00101     gtk.main()