Example #1
0
import interval_event, event, time
import sys

def foo():
    print ("foo")

event.add("/foo" , foo)

def foo2():
    print "end event"

event.add("/foo2" , foo2)

# set callback event and event for end
ie = interval_event.IntervalEvent("/foo" , "/foo2")

try:
    ie.setDaemon(True)
    ie.start()
    ie.test()
    ie.test()
    ie.set(0.5, 10)
    time.sleep(2)
    ie.set (0.05, 10)
    time.sleep(2)
    # Do finalize to avoid error in RPI
    ie.stop()
    sys.exit()

except KeyboardInterrupt:
    print "ED"
Example #2
0
import event
import sl_metro

metro = sl_metro.Metro(1.0)
metro2 = sl_metro.Metro(1.0)
metro3 = sl_metro.Metro(1.5)


# Make callback functions
def foo():
    while True:
        if metro3.update():
            print "    [foo()::EVENT LOOP]:"


def bar(val1, val2):
    while True:
        if metro2.update():
            print "    [bar()::EVENT LOOP]:", val1, " , ", val2


# Connect events and callbacks
event.add("/foo", foo)
event.add("/bar", bar)

tev.bang("/foo")
tev.bang("/bar", 137, 1.38)
while True:
    if metro.update():
        print "[MAIN LOOP]"
Example #3
0
#make callback function


def call1(val1, val2):
    print "[Call1] args=", val1, ",", val2, "2sec"


def call2():
    print "[Call2] 4SEC", "4sec"
    timer.end()
    suicide.run()


#add the function as event
event.add("/call1", call1)
event.add("/call2", call2)

#Create Metro
metro = sl_metro.Metro(0.5)

#create timer with event name and args
timer = timer_event.Timer_event(2.0, "/call1", 137, 13.8)
timer2 = timer_event.Timer_event(
    4.0, "/call2")  #a event without argments is also ok.

#start waiting the involing the event
print "Set timer event named call1 after 2sec and call2 after 4sec."
try:
    while True:
        if metro.update():
Example #4
0
import event


def foo():
    print("foo1 was invoked")


def foo2(num):
    print("foo2 is {0}".format(num))


event.add("foo1", foo)
event.add("foo2", foo2)
event.bang("foo1")
event.bang("foo2", 137)  #add arg
Example #5
0
# if you want to use this library from outside of sonilab folder, should import as follows,
# from sonilab import sl_metro, sl_osc_send, osc_receive, event
# enjoy !!

import sl_metro, sl_osc_send, osc_receive, event

metro = sl_metro.Metro(1.0)
sender = sl_osc_send.slOscSend("127.0.0.1" , 57137)
receiver = osc_receive.OscReceive(57137)


def osc_received (vals):
    print "OSC RECEIVED :: arg[0] = " + str(vals[0]) + " | arg[1] = "  + str(vals[1])

event.add("/test" , osc_received)
receiver.setup("/foo")


try :
    while True:
        if metro.update():
            print "OK"
            sender.send("/test", 137, 1.37)

except KeyboardInterrupt :
    receiver.terminate()
Example #6
0
print('\r\n\r\nTello Python3 Demo.\r\n')

print(
    'Tello: command takeoff land flip forward back left right \r\n       up down cw ccw speed speed?\r\n'
)

print('end -- quit demo.\r\n')

#recvThread create
recvThread = threading.Thread(target=recv)
recvThread.start()

# end from tello3.py

event.add("/foo", foo)
receiver.setup("/foo")

# Hotai add >>tello command<<

t.send_addr(tello_address)
t.send_obj(sock, receiver)

event.add("/command", t.command)
receiver.setup("/command")

event.add("/Setspeed", t.Setspeed)
receiver.setup("/Setspeed")

event.add("/takeoff", t.takeoff)
receiver.setup("/takeoff")
Example #7
0
import event


def foo():
    print("foo1 was invoked")


def foo2(num):
    print("foo2 is {0}".format(num))


event.add("foo1", foo)
event.add("foo2", foo2)
event.bang("foo1")
event.bang("foo2", 137)  # add arg
Example #8
0
FOO_GATE_TIME = 0.5
BAR_GATE_TIME = 0.2

invoking_count = 0
invoking_count2 = 0
invoking_count3 = 0

do_test = True


def test_start():
    global do_test
    do_test = True


event.add("/test_start", test_start)


def test_end():
    global do_test
    do_test = False


event.add("/test_end", test_end)


def foo(val1):
    global invoking_count
    print "foo: ", val1
    invoking_count += 1
Example #9
0
import interval_event, event


def beacon():
    print "beacon"


def finish():
    print "interval event was finished."


event.add("/beacon", beacon)
event.add("/finish", finish)

timer = interval_event.IntervalEvent("/beacon", "/finish")
timer.setDaemon(True)
timer.start()

#bang looped events
print "CTRL+C to finish"
timer.set(0.5, 3)

try:
    while True:
        pass
except KeyboardInterrupt:
    print "Test Finished."
    try:
        return int(input("Please select an option "))
    except ValueError:
        print("Please enter valid Integer.")
        return choice()


print("Welcome to the event management system")
enter()
event.notification()
x = -1
while x != 7:
    options()
    x = choice()
    if x == 1:
        event.add()
        enter()

    if x == 2:
        event.edit()
        enter()

    if x == 3:
        event.delete()
        enter()

    if x == 4:
        event.name_search()
        enter()

    if x == 5:
Example #11
0
def update(ms, adr, flg):
    global queue
    count = 0
    for param in queue:
        if param[0] == adr:
            queue[count] = (adr, ms, flg)
            return True
        count += 1
    #if could not find .. return none
    print "timer_gate :: not found " , adr
    return False


def update_with_true(ms, adr):
    update(ms, adr, True)
ev.add("/update_with_true", update_with_true)


def update_with_false(ms, adr):
    update(ms, adr, False)
ev.add("/update_with_false", update_with_false)


def bang(adr, *args):
    obj = seek(adr) #get stored data
    ms = obj[1]
    state = obj[2]
    if state:
        ev.bang(adr, *args)
        ev.bang("/update_with_false", ms, adr)
        delay.bang(ms, "/update_with_true" , ms, adr)
Example #12
0
import osc_receive, event
receiver = osc_receive.OscReceive(54321)


def foo(vals):
  for val in vals:
    print val

event.add("/foo",foo)
receiver.setup("/foo")


try:
    while True:
        pass

except KeyboardInterrupt :
    receiver.terminate()
Example #13
0
import event_cue, event

#Event cue uses deque. It is thread safe. You can control event with it.


def first(val1, str1, val2):
    print val1, str1, val2


event.add("/first", first)


def second(str1):
    print str1


event.add("/second", second)

evcue = event_cue.EventCue()
evcue.add("/first", 1, 'ehehe', 0.2)

mystr = "ahaha!"
evcue.add("/second", mystr)

evcue.dump()
print("OK")