示例#1
0
def main():
    try:
        import pynotify
    except ImportError:
        print "You don't have the Python libnotify binding installed."
        sys.exit()
    
    if not pynotify.init("timernotify"):
        print "Libnotify could not be initialized."
        sys.exit()
    
    parser = OptionParser(usage="usage: python -m timernotify [options]", 
            add_help_option=False)
    parser.add_option("-h", type="string", action="store", dest="host", default="localhost",
            help="The host that the Autobus server is running on. Without this "
            "option, localhost will be used.")
    parser.add_option("-s", action="store_const", const=True, dest="state_change",
            default=False, help="If present, all state changes (instead of just "
            "when the timer beeps) will cause a notification to be shown.")
    parser.add_option("-?", "--help", action="help")
    
    options, command_line_args = parser.parse_args()
    
    bus = AutobusConnection(host=options.host)
    def beeping_listener(timer):
        pynotify.Notification("Timer " + str(timer), "is beeping.").show()
    
    def state_change_listener(timer, state):
        state_string = {1: "counting up", 2: "counting down", 3: "stopped"}[state]
        pynotify.Notification("Timer " + str(timer), "is now " + state_string + 
                ".").show()
    
    bus.add_event_listener("timer", "beeping", beeping_listener)
    if options.state_change:
        bus.add_event_listener("timer", "manual_state_change", state_change_listener)
    
    bus.connect()
    
    try:
        while True:
            sleep(1)
    except KeyboardInterrupt:
        print "Interrupted, shutting down"
    finally:
        bus.shutdown()
示例#2
0
        continue
    arguments.append(value)    
    

from libautobus import AutobusConnection, NotConnectedException
bus = AutobusConnection(**connect_options)

# We've got everything set up thus far. Now we'll look up the mode and figure
# out what we need to do before we connect to the Autobus server.

if mode == "event":
    def event_function(*arguments):
        if len(arguments) < 0:
            print "Function fired with no arguments."
        print str(arguments)
    bus.add_event_listener(interface_name, item_name, event_function)

if mode == "object":
    printed = False
    def object_function(new_value):
        global printed
        if printed:
            return
        printed = True
        print str(type(new_value))
        print str(new_value)
        bus.shutdown()
    bus.add_object_watch(interface_name, item_name, object_function)
elif mode == "watch":
    def object_function(new_value):
        print str(type(new_value))