示例#1
0
from pyreact.Reactive import Reactive
from pyreact.RxVar import RxVar
from pyreact.RxFunc import RxFunc

r = Reactive()
a = RxVar(10)
b1 = RxVar()
b2 = RxVar()
c = RxVar()

r.connect(b1, [a], lambda : a.get())
r.connect(b2, [a], lambda : a.get() / 10)
r.connect(c, [b1, b2], lambda : b1.get() + b2.get())

print "Output: " + str(c.get())

a.set(5)

print "Output: " + str(c.get())

示例#2
0
文件: test.py 项目: forbesk/pyreact
from pyreact.Reactive import Reactive
from pyreact.RxVar import RxVar
from pyreact.RxFunc import RxFunc

r = Reactive()
x = RxVar(10)
y = RxVar(20)
sum = RxVar()
prod = RxVar()

def sumxy():
    return x.get() + y.get()

r.connect(sum, [x, y], sumxy)
r.connect(prod, [x, y], lambda : x.get() * y.get())

print "Sum is " + str(sum.get())
print "Prod is " + str(prod.get())

x.set(5)
y.set(7)

print "Sum is " + str(sum.get())
print "Prod is " + str(prod.get())
示例#3
0
文件: utils.py 项目: forbesk/pyreact
from pyreact.Reactive import Reactive
from pyreact.RxVar import RxVar
from pyreact.RxUtils import RxUtils
import time
import math

r = Reactive()
x = RxVar(0.0)
integral = RxVar()
derivative = RxVar()

r.connect(integral, [x], RxUtils(x).integrate)
r.connect(derivative, [x], RxUtils(x).differentiate)

sin = math.pi/2.0

while(True):
    x.set(math.sin(sin))
    print str(x.get()) + "\t" + str(integral.get()) + "\t" + str(derivative.get())
    time.sleep(0.1)
    sin += 0.1