예제 #1
0
ctx.result.resource.save_policy = 2  #always save hash
ctx.tf = transformer({
    "value": {
        "pin": "input",
        "dtype": "int"
    },
    "result": {
        "pin": "output",
        "dtype": "int"
    },
})
ctx.tf.code.cell().set("""print("evaluate!"); return value""")
ctx.value.connect(ctx.tf.value)
ctx.tf.result.connect(ctx.result)
ctx.value.set(42)
ctx.link_value = link(ctx.value, ".", "hashcache-value.txt")
ctx.link_result = link(ctx.result,
                       ".",
                       "hashcache-result.txt",
                       file_dominant=True)
ctx.equilibrate()
ctx.tofile("test-hashcache.seamless", backup=False)
ctx = seamless.fromfile("test-hashcache.seamless")
ctx.equilibrate()
print(ctx.result.value)
print("LOAD 1")
ctx.destroy()
ctx = seamless.fromfile("test-hashcache.seamless")
ctx.equilibrate()
print(ctx.result.value)  #42, and no "evaluate!""
print("Changing result to 99...")
예제 #2
0
ctx.result.resource.save_policy = 2 #always save hash
ctx.tf = transformer({
    "value": {
        "pin": "input",
        "dtype": "int"
    },
    "result": {
        "pin": "output",
        "dtype": "int"
    },
})
ctx.tf.code.cell().set("""print("evaluate!"); return value""")
ctx.value.connect(ctx.tf.value)
ctx.tf.result.connect(ctx.result)
ctx.value.set(42)
ctx.link_value = link(ctx.value, ".", "hashcache-value.txt")
ctx.link_result = link(ctx.result, ".", "hashcache-result.txt", file_dominant=True)
ctx.equilibrate()
ctx.tofile("test-hashcache.seamless",backup=False)
ctx = seamless.fromfile("test-hashcache.seamless")
ctx.equilibrate()
print(ctx.result.value)
print("LOAD 1")
ctx.destroy()
ctx = seamless.fromfile("test-hashcache.seamless")
ctx.equilibrate()
print(ctx.result.value) #42, and no "evaluate!""
print("Changing result to 99...")
ctx.destroy()
open("hashcache-result.txt", "w").write("99")
print("LOAD 2")
예제 #3
0
import seamless
from seamless import context, cell, reactor, transformer
from seamless.lib.filelink import link
ctx = context()

ctx.server = reactor({"socket": {"pin": "output", "dtype": "int"}})
ctx.servercode = ctx.server.code_start.cell()
link(ctx.servercode, ".", "test-websockets-lib_pycell.py")
ctx.server.code_update.cell().set("")
ctx.server.code_stop.cell().set("""server.close()""")

from seamless.lib.gui.browser import browse


ctx.client_template = cell("text")
link(ctx.client_template, ".", "test-websockets_client.jinja")

tf_params = {"inp":{"pin": "input", "dtype": "text"},
             "identifier":{"pin": "input", "dtype": "text"},
             "socket":{"pin": "input", "dtype": "int"},
             "outp":{"pin": "output", "dtype": ("text", "html")} }
tf_code = """
import jinja2
d = dict(IDENTIFIER=identifier, socket=socket)
return jinja2.Template(inp).render(d)
"""

ctx.client1 = cell(("text", "html"))
ctx.tf_client1 = transformer(tf_params)
ctx.server.socket.cell().connect(ctx.tf_client1.socket)
ctx.client_template.connect(ctx.tf_client1.inp)
예제 #4
0
파일: test.py 프로젝트: agoose77/seamless
@export pdbsplit
@export headatoms
@export resatoms
"""

from seamless import context, cell
from seamless.slash import slash0
from seamless.lib.filelink import link
from seamless.lib.gui.basic_editor import edit

ctx = context()
ctx.code = cell(("text", "code", "slash-0")).set(code)
ctx.headatoms = cell("text")
ctx.resatoms = cell("text")

ctx.link_headatoms = link(ctx.headatoms, ".", "headatoms.pdb")
ctx.link_resatoms = link(ctx.resatoms, ".", "resatoms.pdb")
ctx.link_code = link(ctx.code, ".", "code.slash")

ctx.slash0 = slash0(ctx.code)
ctx.pdb = cell("text").fromfile("1AVXA.pdb")
ctx.pdb.connect(ctx.slash0.pdb)
ctx.pdbsplit = cell("json")
ctx.slash0.pdbsplit.connect(ctx.pdbsplit)
ctx.slash0.headatoms.connect(ctx.headatoms)
ctx.slash0.resatoms.connect(ctx.resatoms)


ctx.atom = cell("str").set("CA")
ctx.atom.connect(ctx.slash0.atom)
ctx.res = cell("str").set("GLN")
예제 #5
0
import seamless
from seamless import context, reactor, cell
from seamless.lib.filelink import link
ctx = context()
ctx.sender = reactor({"outp": {"pin": "output", "dtype": "signal"},
                       "outp2": {"pin": "output", "dtype": "int"}})
ctx.code = ctx.sender.code_start.cell()
link(ctx.code, ".", "test-signal_pycell.py")
ctx.sender.code_update.cell().set("")
ctx.sender.code_stop.cell().set("""
try:
    widget.destroy()
except Exception:
    pass
""")
ctx.signal = ctx.sender.outp.cell()
ctx.value = ctx.sender.outp2.cell()
ctx.receiver = reactor({"inp": {"pin": "input", "dtype": "signal"},
                       "inp2": {"pin": "input", "dtype": "int"}})
ctx.signal.connect(ctx.receiver.inp)
ctx.value.connect(ctx.receiver.inp2)
ctx.receiver.code_start.cell().set("")
ctx.receiver.code_update.cell().set("""
if PINS.inp.updated:
    print('Receiver: signal received')
if PINS.inp2.updated:
    print("Receiver: secondary input was updated")
""")
ctx.receiver.code_stop.cell().set("")
ctx.value.set(0)
print("START")
예제 #6
0
from seamless import context
from seamless.lib.filelink import link
from seamless.lib.itransformer import itransformer
from seamless.lib.gui.basic_display import display
from seamless.lib.gui.basic_editor import edit
ctx = context()
ctx.itf = itransformer({
    "i": {"pin": "input", "dtype": "int"},
    "outp": {"pin": "output", "dtype": "json"},
})
link(ctx.itf.code.cell(), ".", "cell-test-itransformer.ipy")
link(ctx.itf.rc.code_start.cell())
display(ctx.itf.outp.cell())
edit(ctx.itf.i.cell().set(100))
예제 #7
0
import seamless
from seamless import context, cell
ctx = context()
ctx.value = cell("int")
from seamless.lib.gui.combobox import combobox
ctx.combobox = combobox("int", [10, 20, 30])
from seamless.lib.filelink import link
link(ctx.combobox.code_start.cell())
link(ctx.combobox.code_update.cell())
ctx.combobox.value.connect(ctx.value)
예제 #8
0
from seamless import context, cell, pythoncell, reactor, transformer
from seamless.lib.filelink import link
from seamless.lib.gui.basic_display import display
from seamless.lib.gui.browser import browse
from seamless.lib.gui.basic_editor import edit

ctx = context()
reg = ctx.registrar.ipython
ctx.code = cell(("text", "code", "ipython"))
link(ctx.code, ".", "cell-test-ipython-registrar.ipy")
reg.register(ctx.code)

tf = ctx.get_func_html = transformer({
    "outp": {
        "pin": "output",
        "dtype": ("text", "html")
    },
})
tf.code.cell().set("return func_html")
reg.connect("func_html", tf)
browse(tf.outp.cell())

tf = ctx.run_func = transformer({
    "i": {
        "pin": "input",
        "dtype": "int"
    },
    "outp": {
        "pin": "output",
        "dtype": "float"
    },
예제 #9
0
from seamless.lib.filelink import link
from seamless.lib.gui.basic_editor import edit

import tempfile, shutil

ctx = context()

#tmpdir = tempfile.mkdtemp()
tmpdir = tempfile.gettempdir()

msg = "Edit {0}: directory {1}, file {2}"

ctx.number = cell("int").set(1)
file_number = "number.txt"
title_number = "Number"
ctx.fl_number = link(ctx.number, tmpdir, file_number)
ctx.ed_number = edit(ctx.number, title_number)
print(msg.format(title_number, tmpdir, file_number))

ctx.text = cell("text").set("Lorem ipsum")
file_text = "text.txt"
title_text = "Text"
ctx.fl_text = link(ctx.text, tmpdir, file_text)
ctx.ed_text = edit(ctx.text, title_text)
print(msg.format(title_text, tmpdir, file_text))


### #shutil.rmtree(tmpdir) #TODO: make exit hook

import os
ctx.tofile(os.path.splitext(__file__)[0] + ".seamless", backup=False)
예제 #10
0
@export pdbsplit
@export headatoms
@export resatoms
"""

from seamless import context, cell
from seamless.slash import slash0
from seamless.lib.filelink import link
from seamless.lib.gui.basic_editor import edit

ctx = context()
ctx.code = cell(("text", "code", "slash-0")).set(code)
ctx.headatoms = cell("text")
ctx.resatoms = cell("text")

ctx.link_headatoms = link(ctx.headatoms, ".", "headatoms.pdb")
ctx.link_resatoms = link(ctx.resatoms, ".", "resatoms.pdb")
ctx.link_code = link(ctx.code, ".", "code.slash")

ctx.slash0 = slash0(ctx.code)
ctx.pdb = cell("text").fromfile("1AVXA.pdb")
ctx.pdb.connect(ctx.slash0.pdb)
ctx.pdbsplit = cell("json")
ctx.slash0.pdbsplit.connect(ctx.pdbsplit)
ctx.slash0.headatoms.connect(ctx.headatoms)
ctx.slash0.resatoms.connect(ctx.resatoms)

ctx.atom = cell("str").set("CA")
ctx.atom.connect(ctx.slash0.atom)
ctx.res = cell("str").set("GLN")
ctx.res.connect(ctx.slash0.res)
예제 #11
0
import seamless
from seamless import context, transformer, cell
from seamless.lib.filelink import link
ctx = context()
ctx.cson = cell("cson")
ctx.cson_link = link(ctx.cson, ".", "test-cson.cson")
ctx.json = cell("json")
ctx.json_link = link(ctx.json, ".", "test-cson.json")
tparams = {
    "inp": {"pin": "input", "dtype": "json"},
    "outp": {"pin": "output", "dtype": "json"}
}
ctx.tf = transformer(tparams)
ctx.cson.connect(ctx.tf.inp)
ctx.tf.outp.connect(ctx.json)
ctx.tf.code.cell().set("""
return inp
""")

import os
ctx.tofile(os.path.splitext(__file__)[0] + ".seamless", backup=False)

#if not seamless.ipython:
#    seamless.mainloop()
예제 #12
0
import seamless
from seamless import context, cell, reactor, transformer
from seamless.lib.filelink import link

ctx = context()

ctx.server = reactor({"socket": {"pin": "output", "dtype": "int"}})
ctx.servercode = ctx.server.code_start.cell()
link(ctx.servercode, ".", "test-websockets-lib_pycell.py")
ctx.server.code_update.cell().set("")
ctx.server.code_stop.cell().set("""server.close()""")

from seamless.lib.gui.browser import browse

ctx.client_template = cell("text")
link(ctx.client_template, ".", "test-websockets_client.jinja")

tf_params = {
    "inp": {
        "pin": "input",
        "dtype": "text"
    },
    "identifier": {
        "pin": "input",
        "dtype": "text"
    },
    "socket": {
        "pin": "input",
        "dtype": "int"
    },
    "outp": {
예제 #13
0
import seamless
from seamless import context, reactor, cell
from seamless.lib.filelink import link
ctx = context()
ctx.sender = reactor({
    "outp": {
        "pin": "output",
        "dtype": "signal"
    },
    "outp2": {
        "pin": "output",
        "dtype": "int"
    }
})
ctx.code = ctx.sender.code_start.cell()
link(ctx.code, ".", "test-signal_pycell.py")
ctx.sender.code_update.cell().set("")
ctx.sender.code_stop.cell().set("""
try:
    widget.destroy()
except Exception:
    pass
""")
ctx.signal = ctx.sender.outp.cell()
ctx.value = ctx.sender.outp2.cell()
ctx.receiver = reactor({
    "inp": {
        "pin": "input",
        "dtype": "signal"
    },
    "inp2": {