def combobox(dtype, options, title): from seamless import reactor pinparams = { "value": { "pin": "edit", "dtype": dtype, "must_be_defined": False }, "options": { "pin": "input", "dtype": "json", }, "title": { "pin": "input", "dtype": "str", }, } rc = reactor(pinparams) rc.options.cell().set(options) rc.title.cell().set(title) rc.code_start.cell().fromfile("cell-combobox.py") rc.code_stop.cell().set('widget.destroy()') c_up = rc.code_update.cell(True) c_up.fromfile("cell-combobox_UPDATE.py") return rc
def filehash(ctx, filepath): from seamless import reactor, pythoncell ctx.cell_filehash = pythoncell().fromfile("cell-filehash-start.py") reactor_params = { "filepath": { "pin": "input", "dtype": "str", }, "latency": { "pin": "input", "dtype": "float", }, "filehash": { "pin": "output", "dtype": "str", }, } rc = ctx.rc = reactor(reactor_params) ctx.cell_filehash.connect(rc.code_start) rc.filepath.cell().set(filepath) rc.latency.cell().set(1) rc.code_update.cell().set("") rc.code_stop.cell().set('terminate.set(); t.join()') ctx.export(rc, ["filehash"])
def combobox(dtype, options, title): from seamless import reactor pinparams = { "value": { "pin": "edit", "dtype": dtype, "must_be_defined": False }, "options": { "pin": "input", "dtype": "json", }, "title": { "pin": "input", "dtype": "str", }, } rc = reactor(pinparams) rc.options.cell().set(options) rc.title.cell().set(title) rc.code_start.cell().fromfile("cell-combobox.py") rc.code_stop.cell().set('widget.destroy()') c_up = rc.code_update.cell(True) c_up.fromfile("cell-combobox_UPDATE.py") return rc
def load_display_numpy(): global first ctx.array = cell("array") ctx.title = cell("str").set("Numpy array") ctx.aspect_layout = pythoncell().fromfile("AspectLayout.py") if first: ctx.registrar.python.register( ctx.aspect_layout ) #TODO: should be harmless to register same item twice ctx.display_numpy = reactor({ "array": { "pin": "input", "dtype": "array" }, "title": { "pin": "input", "dtype": "str" }, }) ctx.registrar.python.connect("AspectLayout", ctx.display_numpy) ctx.array.connect(ctx.display_numpy.array) ctx.title.connect(ctx.display_numpy.title) ctx.display_numpy.code_update.set("update()") ctx.display_numpy.code_stop.set("destroy()") ctx.code = pythoncell() ctx.code.connect(ctx.display_numpy.code_start) ctx.code.fromfile("cell-display-numpy.py") first = False
def filehash(ctx, filepath): from seamless import reactor, pythoncell ctx.cell_filehash = pythoncell().fromfile("cell-filehash-start.py") reactor_params = { "filepath": { "pin": "input", "dtype": "str", }, "latency": { "pin": "input", "dtype": "float", }, "filehash": { "pin": "output", "dtype": "str", }, } rc = ctx.rc = reactor(reactor_params) ctx.cell_filehash.connect(rc.code_start) rc.filepath.cell().set(filepath) rc.latency.cell().set(1) rc.code_update.cell().set("") rc.code_stop.cell().set('terminate.set(); t.join()') ctx.export(rc, ["filehash"])
def init(): from seamless import reactor rc = reactor({ "trigger": {"pin": "output", "dtype": "signal"} }) rc.code_start.cell().set("PINS.trigger.set()") rc.code_update.cell().set("") rc.code_stop.cell().set("") return rc
def dynamic_html(ctx, params): from seamless import reactor from collections import OrderedDict params2 = { "vars": OrderedDict(), "html": OrderedDict(), "evals": OrderedDict() } ed_params = { "DYNAMIC_HTML_PARAMS": { "pin": "input", "dtype": "json" }, "DYNAMIC_HTML_TEMPLATE": { "pin": "input", "dtype": "text" }, "dynamic_html": { "pin": "output", "dtype": ("text", "html") } } assert "dynamic_html" not in params for k, v in params.items(): assert isinstance(v, dict), k ed_param = {"pin": "input"} type_ = v["type"] assert type_ in ("var", "html", "eval"), type_ if type_ == "var": dtype = v.get("dtype") evals = v.get("evals", []) var = v.get("var", k) params2["vars"][k] = (var, evals) ed_param["dtype"] = dtype elif type_ == "html": id_ = v.get("id", k) params2["html"][k] = id_ ed_param["dtype"] = ("text", "html") else: #type_ = "eval" on_start = v.get("on_start", None) params2["evals"][k] = on_start ed_param["dtype"] = "text" ed_params[k] = ed_param for k, v in params2["vars"].items(): var, evals = v for e in evals: assert e in params2["evals"], (k, e, list(params2["evals"].keys())) rc = ctx.rc = reactor(ed_params) rc.code_start.cell().fromfile("cell-dynamic-html-start.py") rc.code_update.cell().set("update(on_start=False)") rc.code_stop.cell().set("") rc.DYNAMIC_HTML_PARAMS.cell().set(params2) rc.DYNAMIC_HTML_TEMPLATE.cell().fromfile("dynamic-html.jinja") ctx.export(rc)
def m(ctx, identifier): from seamless import cell, reactor ctx.identifier = cell("str").set(identifier) ctx.rc = reactor({ "text": {"pin": "input", "dtype": "str"}, "identifier": {"pin": "input", "dtype": "str"}, }) ctx.identifier.connect(ctx.rc.identifier) ctx.rc.code_start.cell().set("") ctx.rc.code_update.cell().set("print('M,', PINS.identifier.value, ',' , PINS.text.value)") ctx.rc.code_stop.cell().set("") ctx.export(ctx.rc)
def make_text_editor(eparams): from seamless import cell, reactor rc = reactor(eparams) rc.code_start.cell().fromfile("test-editor_pycell2.py") rc.code_stop.cell().set('w.destroy()') rc.code_update.cell().set(""" if PINS.value.updated: b.setText(PINS.value.get()) if PINS.title.updated: w.setWindowTitle(PINS.title.get()) """) return rc
def dynamic_html(ctx, params): from seamless import reactor from collections import OrderedDict params2 = { "vars": OrderedDict(), "html": OrderedDict(), "evals": OrderedDict() } ed_params = { "DYNAMIC_HTML_PARAMS": { "pin": "input", "dtype": "json" }, "DYNAMIC_HTML_TEMPLATE": { "pin": "input", "dtype": "text" }, "dynamic_html": { "pin": "output", "dtype": ("text", "html") } } assert "dynamic_html" not in params for k,v in params.items(): assert isinstance(v,dict), k ed_param = {"pin": "input"} type_ = v["type"] assert type_ in ("var", "html", "eval"), type_ if type_ == "var": dtype = v.get("dtype") evals = v.get("evals", []) var = v.get("var", k) params2["vars"][k] = (var, evals) ed_param["dtype"] = dtype elif type_ == "html": id_ = v.get("id", k) params2["html"][k] = id_ ed_param["dtype"] = ("text", "html") else: #type_ = "eval" on_start = v.get("on_start", None) params2["evals"][k] = on_start ed_param["dtype"] = "text" ed_params[k] = ed_param for k,v in params2["vars"].items(): var, evals = v for e in evals: assert e in params2["evals"], (k, e, list(params2["evals"].keys())) rc = ctx.rc = reactor(ed_params) rc.code_start.cell().fromfile("cell-dynamic-html-start.py") rc.code_update.cell().set("update(on_start=False)") rc.code_stop.cell().set("") rc.DYNAMIC_HTML_PARAMS.cell().set(params2) rc.DYNAMIC_HTML_TEMPLATE.cell().fromfile("dynamic-html.jinja") ctx.export(rc)
def timer(period): from seamless import reactor timer = reactor({ "period": {"pin": "input", "dtype": "float"}, "trigger": {"pin": "output", "dtype": "signal"} }) timer.code_start.cell().fromfile("cell-timer.py") timer.code_update.cell().set("") timer.code_stop.cell().set("t.cancel(); dead = True") if period > 0: timer.period.cell().set(period) return timer
def itransformer(ctx, params): from seamless import reactor from seamless.core.worker import ExportedInputPin params2 = params.copy() params2["code"] = {"pin": "input", "dtype": ("text", "code", "ipython")} params2["transformer_params"] = {"pin": "input", "dtype": "json"} params2["@shell"] = ".namespace" rc = ctx.rc = reactor(params2) rc.transformer_params.cell().set(params) rc.code_start.cell().fromfile("cell-itransformer.py") rc.code_update.cell().set("do_update()") rc.code_stop.cell().set("") ctx.export(ctx.rc)
def glwindow(title, size, position): from seamless import reactor pinparams = { "title": { "pin": "input", "dtype": "str" }, "geometry": { "pin": "input", "dtype": "json" }, "update": { "pin": "input", "dtype": "signal" }, "camera": { "pin": "edit", "dtype": "json", "must_be_defined": False }, "init": { "pin": "output", "dtype": "signal", }, "paint": { "pin": "output", "dtype": "signal", }, "painted": { "pin": "output", "dtype": "signal" }, "last_key": { "pin": "output", "dtype": "str" } } rc = reactor(pinparams) rc.title.cell().set(title) geometry = list(position) + list(size) assert len(geometry) == 4, geometry rc.geometry.cell().set(geometry) rc.code_start.cell().fromfile("cell-glwindow.py") rc.code_update.cell().set('do_update()') rc.code_stop.cell().set('widget.destroy()') return rc
def glwindow(title, size, position): from seamless import reactor pinparams = { "title": { "pin": "input", "dtype": "str" }, "geometry": { "pin": "input", "dtype": "json" }, "update": { "pin": "input", "dtype": "signal" }, "camera": { "pin": "edit", "dtype": "json", "must_be_defined": False }, "init": { "pin": "output", "dtype": "signal", }, "paint": { "pin": "output", "dtype": "signal", }, "painted": { "pin": "output", "dtype": "signal" }, "last_key": { "pin": "output", "dtype": "str" } } rc = reactor(pinparams) rc.title.cell().set(title) geometry = list(position) + list(size) assert len(geometry) == 4, geometry rc.geometry.cell().set(geometry) rc.code_start.cell().fromfile("cell-glwindow.py") rc.code_update.cell().set('do_update()') rc.code_stop.cell().set('widget.destroy()') return rc
def playcontrol(ctx, title): from seamless import reactor ctx.playcontrol = reactor({ "min": {"pin": "input", "dtype": "int"}, "max": {"pin": "input", "dtype": "int"}, "rate": {"pin": "input", "dtype": "int"}, "value": {"pin": "edit", "dtype": "int"}, "loop": {"pin": "edit", "dtype": "bool"}, "title": {"pin": "input", "dtype": "str"}, }) ctx.playcontrol.code_start.cell().fromfile("cell-playcontrol.py") ctx.playcontrol.code_update.cell().set("do_update()") ctx.playcontrol.code_stop.cell().set("widget.destroy()") ctx.playcontrol.title.cell().set(title) ctx.playcontrol.min.cell().set(1) ctx.playcontrol.rate.cell().set(2) ctx.playcontrol.loop.cell().set(True) ctx.export(ctx.playcontrol, forced=["min", "rate", "loop"])
def browser(ctx, dtype, title): from seamless import reactor assert dtype[:2] == ("text", "html") #for now... pinparams = { "value": { "pin": "edit", "dtype": dtype }, "title": { "pin": "input", "dtype": "str", }, } rc = ctx.rc = reactor(pinparams) rc.title.cell().set(title) rc.code_start.cell().fromfile("cell-browser.py") rc.code_stop.cell().set('widget.destroy()') c_up = rc.code_update.cell(True) c_up.fromfile("cell-browser_UPDATE.py") ctx.export(rc, forced=["title"])
def templateer(ctx, template_definition, output_type): from seamless import cell, reactor templates = template_definition["templates"] assert isinstance(templates, list) environment = template_definition["environment"] ed_params = {} for t in templates: assert t not in ed_params, t ed_params[t] = {"pin": "input", "dtype": "text"} for k,v in environment.items(): assert k not in ed_params, k ed_params[k] = {"pin": "input", "dtype": v} ed_params["TEMPLATE_DEFINITION"] = {"pin": "input", "dtype": "json"} ed_params["RESULT"] = {"pin": "output", "dtype": output_type} ctx.rc = reactor(ed_params) ctx.rc.TEMPLATE_DEFINITION.cell().set(template_definition) ctx.rc.code_start.cell().fromfile("cell-templateer.py") ctx.rc.code_update.cell().set("make_template()") ctx.rc.code_stop.cell().set("") ctx.export(ctx.rc)
def load_display_numpy(): global first ctx.array = cell("array") ctx.title = cell("str").set("Numpy array") ctx.aspect_layout = pythoncell().fromfile("AspectLayout.py") if first: ctx.registrar.python.register(ctx.aspect_layout) #TODO: should be harmless to register same item twice ctx.display_numpy = reactor({ "array": {"pin": "input", "dtype": "array"}, "title": {"pin": "input", "dtype": "str"}, }) ctx.registrar.python.connect("AspectLayout", ctx.display_numpy) ctx.array.connect(ctx.display_numpy.array) ctx.title.connect(ctx.display_numpy.title) ctx.display_numpy.code_update.set("update()") ctx.display_numpy.code_stop.set("destroy()") ctx.code = pythoncell() ctx.code.connect(ctx.display_numpy.code_start) ctx.code.fromfile("cell-display-numpy.py") first = False
def filelink(ctx, cell_type): cell_filelink_start = "cell-filelink-start.py" #repeat for inline from seamless import reactor pinparams = { "value": { "pin": "edit", "dtype": cell_type, "must_be_defined": False }, "filepath" : { "pin": "input", "dtype": "str" }, "latency" : { "pin": "input", "dtype": "float" }, } rc = ctx.rc = reactor(pinparams) rc.code_start.cell().fromfile(cell_filelink_start) rc.code_update.cell().set("write_file(PINS.filepath.get())") rc.code_stop.cell().set('terminate.set(); t.join()') ctx.export(rc)
def filelink(ctx, cell_type): cell_filelink_start = "cell-filelink-start.py" #repeat for inline from seamless import reactor pinparams = { "value": { "pin": "edit", "dtype": cell_type, "must_be_defined": False }, "filepath": { "pin": "input", "dtype": "str" }, "latency": { "pin": "input", "dtype": "float" }, } rc = ctx.rc = reactor(pinparams) rc.code_start.cell().fromfile(cell_filelink_start) rc.code_update.cell().set("write_file(PINS.filepath.get())") rc.code_stop.cell().set('terminate.set(); t.join()') ctx.export(rc)
def playcontrol(ctx, title): from seamless import reactor ctx.playcontrol = reactor({ "min": { "pin": "input", "dtype": "int" }, "max": { "pin": "input", "dtype": "int" }, "rate": { "pin": "input", "dtype": "int" }, "value": { "pin": "edit", "dtype": "int" }, "loop": { "pin": "edit", "dtype": "bool" }, "title": { "pin": "input", "dtype": "str" }, }) ctx.playcontrol.code_start.cell().fromfile("cell-playcontrol.py") ctx.playcontrol.code_update.cell().set("do_update()") ctx.playcontrol.code_stop.cell().set("widget.destroy()") ctx.playcontrol.title.cell().set(title) ctx.playcontrol.min.cell().set(1) ctx.playcontrol.rate.cell().set(2) ctx.playcontrol.loop.cell().set(True) ctx.export(ctx.playcontrol, forced=["min", "rate", "loop"])
ctx.tex_filename = ctx.gen_texture.filename.cell() ctx.tex_filename.set("") ctx.gen_texture.as_float.cell().set(True) ctx.gen_texture.output.connect(ctx.texture) ctx.texture.connect(p.array_s_texture) # Ugly piece of code to display a numpy array texture c = ctx.display_texture = context() c.title = cell("str").set("Texture") c.aspect_layout = pythoncell().fromfile("AspectLayout.py") c.registrar.python.register(c.aspect_layout) c.display_numpy = reactor({ "array": { "pin": "input", "dtype": "array" }, "title": { "pin": "input", "dtype": "str" }, }) c.registrar.python.connect("AspectLayout", c.display_numpy) ctx.texture.connect(c.display_numpy.array) c.title.connect(c.display_numpy.title) c.display_numpy.code_update.set("update()") c.display_numpy.code_stop.set("destroy()") c.code = pythoncell() c.code.connect(c.display_numpy.code_start) c.code.fromfile("cell-display-numpy.py") # /Ugly piece of code to display a texture #Uniforms
import numpy as np from scipy.spatial.distance import cdist ctx = context() ctx.params = context() ctx.links = context() ctx.code = context() file_dominant = True #for now, gen_sphere must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.gen_sphere = cell(("cson", "seamless", "reactor_params")) ctx.links.params_gen_sphere = link(c, ".", "params-gen-sphere.cson", file_dominant=file_dominant) rc = ctx.gen_sphere = reactor(c) c = ctx.code.gen_sphere = cell(("text", "code", "python")) ctx.links.code_gen_sphere = link(c, ".", "cell-gen-sphere.py", file_dominant=file_dominant) rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") do_scale_params = { "input":{"pin": "input", "dtype": "array"}, "scale":{"pin": "input", "dtype": "float"}, "output":{"pin": "output", "dtype": "array"} } ctx.subdivisions = cell("int").set(3) ctx.minimizations = cell("int").set(20) ctx.scale = cell("float").set(3.5) ctx.coordinates = cell("array").set_store("GL")
b.setValue(PINS.value.get()) if PINS.title.updated: w.setWindowTitle(PINS.title.get()) """) def make_text_editor(ed): ed.code_start.cell().fromfile(editor_pycell2) ed.code_stop.cell().set('w.destroy()') ed.code_update.cell().set(""" if PINS.value.updated: b.setText(PINS.value.get()) if PINS.title.updated: w.setWindowTitle(PINS.title.get()) """) ed1 = ctx.ed1 = reactor(eparams) ed2 = ctx.ed2 = reactor(eparams) ed1.title.cell().set("Editor #1") ed2.title.cell().set("Editor #2") make_editor(ed1) make_editor(ed2) c_data.connect(ed1.value) c_output.connect(ed2.value) #ted1 = ctx.ted1 = reactor(teparams) ted1 = ctx.ted1 = reactor(teparams2) ted1.title.cell().set("Formula editor") make_text_editor(ted1) #c = ed1.title.cell() c = c_code #v = ted1.value.cell()
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")
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": {
def ngl(ctx, molnames, remote_ngl): """ Sets up dynamic HTML code to view molecules using the NGL viewer Generates a context with the following pins: Inputs: data_X (where X is each molname): A text pin for the molecule data. As of seamless 0.1, only text is supported transformation_X: A JSON cell for the molecule rotation+translation matrix. Must be a 4x4 matrix in JSON format (list of lists) Default: identity matrix representations: A JSON pin containing the molecular representations The representations are a list of dicts, with each dict containing the following keys: repr: the representation, as understood by NGL. Examples: "cartoon", "spacefill", "ball+stick", "licorice" See http://arose.github.io/ngl/api/manual/usage/molecular-representations.html obj: Optional. A molname of list of molnames to which the representation applies. Default: all molnames All other keys are passed directly to NGL.Stage.addRepresentation() Examples of keys: color, colorScheme: Examples: color: "red", colorScheme: "bfactor" / "element" See: http://arose.github.io/ngl/api/manual/usage/coloring.html sele: Examples: "73-77", ":A", "LYS" See: http://arose.github.io/ngl/api/manual/usage/selection-language.html Output: html: output pin containing the generated dynamic HTML, to be visualized As of seamless 0.1, requires that a copy or link to ngl.js is present in the current directory TODO: remote_ngl Macro arguments: molnames: is either a list of molecule names in PDB format, or a dict of (moleculename, dataformat) items, where dataformat is any format understood by NGL.Stage.loadFile() See: http://arose.github.io/ngl/api/manual/usage/file-formats.html http://arose.github.io/ngl/api/Stage.html """ from seamless import cell, transformer, reactor from seamless.lib.dynamic_html import dynamic_html from seamless.lib.templateer import templateer from seamless.core.worker import ExportedInputPin, ExportedOutputPin ctx.tmpl = cell("text").fromfile("ngl-html.jinja") if isinstance(molnames, list): molnames = {name: "pdb" for name in molnames} params = {"update_": {"type": "eval"}} for molname, dataformat in molnames.items(): newparams = { "data_" + molname: { "type": "var", "var": "update.data_" + molname, "dtype": "text", "evals": ["update_"] }, "dataformat_" + molname: { "type": "var", "var": "update.dataformat_" + molname, "dtype": "text", "evals": ["update_"] }, "representations_" + molname: { "type": "var", "var": "update.representations_" + molname, "dtype": "json", "evals": ["update_"] }, "transformation_" + molname: { "type": "var", "var": "update.transformation_" + molname, "dtype": "json", "evals": ["update_"] }, } params.update(newparams) ctx.dynamic = dynamic_html(params) ctx.templateer = templateer({ "templates": ["tmpl"], "environment": { "dynamic": ("text", "html"), "ngl_dir": "text" } }) ngl_dir = "https://cdn.rawgit.com/arose/ngl/v0.10.3/dist/" if remote_ngl else "" ctx.templateer.ngl_dir.cell().set(ngl_dir) ctx.tmpl.connect(ctx.templateer.tmpl) ctx.dynamic.dynamic_html.cell().connect(ctx.templateer.dynamic) ctx.update_ = cell("text") ctx.update_.set("do_update()") ctx.update_.connect(ctx.dynamic.update_) transformer_params = { "molnames": { "pin": "input", "dtype": "json" }, "representations": { "pin": "input", "dtype": "json" } } for molname, dataformat in molnames.items(): pinname = "dataformat_" + molname pin = getattr(ctx.dynamic, pinname) pin.cell().set(dataformat) pinname = "transformation_" + molname c = cell("json").set([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) setattr(ctx, "cell_transformation_" + molname, c) c.connect(getattr(ctx.dynamic, pinname)) setattr(ctx, "transformation_" + molname, ExportedInputPin(c)) pinname = "representations_" + molname transformer_params[pinname] = {"pin": "output", "dtype": "json"} # As of seamless 0.1, this has to be a reactor due to multiple outputs t = ctx.transform_representations = reactor(transformer_params) t.molnames.set(list(molnames.keys())) t.code_start.cell().set("") t.code_update.cell().fromfile("cell-transform-representations.py") t.code_stop.cell().set("") for molname, dataformat in molnames.items(): pinname = "representations_" + molname source = getattr(t, pinname).cell() target = getattr(ctx.dynamic, pinname) source.connect(target) ctx.representations = ExportedInputPin(t.representations) ctx.export(ctx.dynamic) ctx.html = ExportedOutputPin(ctx.templateer.RESULT)
del ctx.edit.minimizations del ctx.gen_sphere del ctx.params.gen_sphere del ctx.links.params_gen_sphere del ctx.links.code_gen_sphere ctx.texture_coords = cell("array").set_store("GL") ctx.triangle_texture_coords = cell("array").set_store("GL") #for now, load-ply must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.load_ply = cell(("cson", "seamless", "reactor_params")) ctx.links.params_load_ply = link(c, ".", "params-load-ply.cson") rc = ctx.load_ply = reactor(c) c = ctx.code.load_ply = cell(("text", "code", "python")) ctx.links.code_load_ply = link(c, ".", "cell-load-ply2.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.load_ply.coordinates.connect(ctx.coordinates_prescale) ctx.load_ply.normals.connect(ctx.normals) ctx.load_ply.edges.connect(ctx.edges) ctx.load_ply.triangle_indices.connect(ctx.triangle_indices) ctx.load_ply.triangle_coordinates.connect(ctx.triangle_coordinates_prescale) ctx.load_ply.triangle_normals.connect(ctx.triangle_normals) ctx.load_ply.texture_coords.connect(ctx.texture_coords) ctx.load_ply.triangle_texture_coords.connect(ctx.triangle_texture_coords) ctx.filename = cell("str")
def __init__(self, a, b, c): self.a = a self.b = b self.c = c def __str__(self): return "MyClass: {0} {1} {2}".format(self.a, self.b, self.c) """) ro = ctx.registrar.python.register(ctx.code) # Repeated registration v = ctx.code.value #ctx.code.destroy() # Should not be necessary #ro.destroy() # Should not be necessary ctx.code = pythoncell().set(v) ctx.registrar.python.register(ctx.code) ctx.equilibrate() rc = ctx.rc = reactor({}) ctx.registrar.python.connect("MyClass", rc) rc.code_start.cell().set("print( 'start', MyClass(1,2,3) )") rc.code_update.cell().set("print( 'update', MyClass(1,2,3) )") rc.code_stop.cell().set("print('stop')") tf = ctx.tf = transformer({}) ctx.registrar.python.connect("MyClass", tf) tf.code.cell().set("print( 'transform', MyClass(1,2,3) ); return") ctx.equilibrate() ctx.code.set(ctx.code.value + " ") ctx.equilibrate()
def basic_editor(ctx, editor_type, title): from seamless import reactor _editors = { "int": { "code": "cell-basic_editor_int.py", "update": "cell-basic_editor_int_UPDATE.py", }, "float": { "code": "cell-basic_editor_float.py", "update": "cell-basic_editor_UPDATE.py", }, "str": { "code": "cell-basic_editor_str.py", "update": "cell-basic_editor_str_UPDATE.py", }, "text": { "code": "cell-basic_editor_text.py", "update": "cell-basic_editor_text_UPDATE.py", }, "json": { "code": "cell-basic_editor_json.py", "update": "cell-basic_editor_json_UPDATE.py", }, } _editors["cson"] = _editors["text"] def _match_type(type, typelist): typelist = list(typelist) type2 = type if isinstance(type, str): type2 = (type, ) typelist2 = [] for t in typelist: if isinstance(t, str): typelist2.append((t, )) else: typelist2.append(t) matches = [] for n in range(len(typelist)): ltype = typelist2[n] k = min(len(type2), len(ltype)) if type2[:k] == ltype[:k]: matches.append((n, k)) if not len(matches): raise TypeError( "Cannot find editor for cell type '{0}'".format(type)) matches.sort(key=lambda v: -v[1]) bestmatch = matches[0][0] return typelist[bestmatch] editor_type = _match_type(editor_type, _editors.keys()) pinparams = { "value": { "pin": "edit", "dtype": editor_type, "must_be_defined": False }, "title": { "pin": "input", "dtype": "str", }, } if editor_type == "int": pinparams["maximum"] = {"pin": "input", "dtype": "int"} rc = ctx.rc = reactor(pinparams) rc.title.cell().set(title) forced = ["title"] if editor_type == "int": rc.maximum.set(9999999) forced.append("maximum") rc.code_start.cell().fromfile(_editors[editor_type]["code"]) rc.code_stop.cell().set('w.destroy()') upfile = _editors[editor_type]["update"] c_up = rc.code_update.cell(True) if upfile is not None: c_up.fromfile(upfile) else: c_up.set("") ctx.export(rc, forced=forced)
"dtype": "array" }, "a3": { "pin": "output", "dtype": "array" } }) ctx.array1.connect(ctx.tf.a1) ctx.array2.connect(ctx.tf.a2) ctx.tf.code.cell().set( "print('RUN');import numpy as np; return np.concatenate((a1,a2))") ctx.equilibrate() print(ctx.tf.a3.cell().value) ctx.array1.set_store("GL") ctx.rc = reactor({"a1": {"pin": "input", "dtype": "array"}}) ctx.array1.connect(ctx.rc.a1) ctx.rc.code_start.cell().set("") ctx.rc.code_stop.cell().set("") ctx.rc.code_update.cell().set(""" store = PINS.a1.store print("We won't get an actual OpenGL ID since there is no OpenGL context... error message:") store.bind() #print("OpenGL ID", store.opengl_id, "State", store._state, store.shape) #print(PINS.a1.get()) #print("OK") """) ctx.equilibrate(0.5) ctx.array1.set(np.ones(12)) ctx.equilibrate(0.5)
ctx.tex_radius.set(32) ctx.tex_filename = ctx.gen_texture.filename.cell() ctx.tex_filename.set("") ctx.gen_texture.as_float.cell().set(True) ctx.gen_texture.output.connect(ctx.texture) ctx.texture.connect(p.array_s_texture) #Uniforms ctx.uniforms = cell("json") ctx.uniforms.connect(p.uniforms) ctx.params_gen_uniforms = cell(("json", "seamless", "reactor_params")) ctx.link_params_gen_uniforms = link(ctx.params_gen_uniforms, ".", "params_gen_uniforms.json", file_dominant=file_dominant) ctx.equilibrate() ctx.gen_uniforms = reactor(ctx.params_gen_uniforms) ctx.gravity = ctx.gen_uniforms.gravity.cell().set(1) ctx.pointsize = ctx.gen_uniforms.pointsize.cell().set(40) ctx.shrink_with_age = ctx.gen_uniforms.shrink_with_age.cell().set(True) ctx.N.connect(ctx.gen_uniforms.N) ctx.link_gen_uniforms_start = link( ctx.gen_uniforms.code_start.cell(), ".", "cell-gen-uniforms-start.py", file_dominant=file_dominant ) ctx.link_gen_uniforms_update = link( ctx.gen_uniforms.code_update.cell(), ".", "cell-gen-uniforms-update.py", file_dominant=file_dominant )
def ngl(ctx, molnames): """ Sets up dynamic HTML code to view molecules using the NGL viewer Generates a context with the following pins: Inputs: data_X (where X is each molname): A text pin for the molecule data. As of seamless 0.1, only text is supported transformation_X: A JSON cell for the molecule rotation+translation matrix. Must be a 4x4 matrix in JSON format (list of lists) Default: identity matrix representations: A JSON pin containing the molecular representations The representations are a list of dicts, with each dict containing the following keys: repr: the representation, as understood by NGL. Examples: "cartoon", "spacefill", "ball+stick", "licorice" See http://arose.github.io/ngl/api/manual/usage/molecular-representations.html obj: Optional. A molname of list of molnames to which the representation applies. Default: all molnames All other keys are passed directly to NGL.Stage.addRepresentation() Examples of keys: color, colorScheme: Examples: color: "red", colorScheme: "bfactor" / "element" See: http://arose.github.io/ngl/api/manual/usage/coloring.html sele: Examples: "73-77", ":A", "LYS" See: http://arose.github.io/ngl/api/manual/usage/selection-language.html Output: html: output pin containing the generated dynamic HTML, to be visualized As of seamless 0.1, requires that a copy or link to ngl.js is present in the current directory Macro arguments: molnames: is either a list of molecule names in PDB format, or a dict of (moleculename, dataformat) items, where dataformat is any format understood by NGL.Stage.loadFile() See: http://arose.github.io/ngl/api/manual/usage/file-formats.html http://arose.github.io/ngl/api/Stage.html """ from seamless import cell, transformer, reactor from seamless.lib.dynamic_html import dynamic_html from seamless.lib.templateer import templateer from seamless.core.worker import ExportedInputPin, ExportedOutputPin ctx.tmpl = cell("text").fromfile("ngl-html.jinja") if isinstance(molnames, list): molnames = {name:"pdb" for name in molnames} params = { "update_": { "type": "eval" } } for molname, dataformat in molnames.items(): newparams = { "data_" + molname: { "type": "var", "var": "update.data_" + molname, "dtype": "text", "evals": ["update_"] }, "dataformat_" + molname: { "type": "var", "var": "update.dataformat_" + molname, "dtype": "text", "evals": ["update_"] }, "representations_" + molname: { "type": "var", "var": "update.representations_" + molname, "dtype": "json", "evals": ["update_"] }, "transformation_" + molname: { "type": "var", "var": "update.transformation_" + molname, "dtype": "json", "evals": ["update_"] }, } params.update(newparams) ctx.dynamic = dynamic_html(params) ctx.templateer = templateer({"templates": ["tmpl"], "environment": {"dynamic": ("text", "html")}}) ctx.tmpl.connect(ctx.templateer.tmpl) ctx.dynamic.dynamic_html.cell().connect(ctx.templateer.dynamic) ctx.update_ = cell("text") ctx.update_.set("do_update()"); ctx.update_.connect(ctx.dynamic.update_) transformer_params = { "molnames": {"pin": "input", "dtype": "json"}, "representations": {"pin": "input", "dtype": "json"} } for molname, dataformat in molnames.items(): pinname = "dataformat_" + molname pin = getattr(ctx.dynamic, pinname) pin.cell().set(dataformat) pinname = "transformation_" + molname c = cell("json").set([[1,0,0,0],[0,1,0,0], [0,0,1,0], [0,0,0,1]]) setattr(ctx, "cell_transformation_" + molname, c) c.connect(getattr(ctx.dynamic, pinname)) setattr(ctx, "transformation_" + molname, ExportedInputPin(c)) pinname = "representations_" + molname transformer_params[pinname] = {"pin": "output", "dtype": "json"} # As of seamless 0.1, this has to be a reactor due to multiple outputs t = ctx.transform_representations = reactor(transformer_params) t.molnames.set(list(molnames.keys())) t.code_start.cell().set("") t.code_update.cell().fromfile("cell-transform-representations.py") t.code_stop.cell().set("") for molname, dataformat in molnames.items(): pinname = "representations_" + molname source = getattr(t, pinname).cell() target = getattr(ctx.dynamic, pinname) source.connect(target) ctx.representations = ExportedInputPin(t.representations) ctx.export(ctx.dynamic) ctx.html = ExportedOutputPin(ctx.templateer.RESULT)
from seamless import context, cell, transformer, reactor from seamless.lib import edit, display, link from seamless.lib.gui.gl import glprogram, glwindow import numpy as np ctx = context() ctx.params = context() ctx.links = context() ctx.code = context() #for now, gen_sphere must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.gen_sphere = cell(("cson", "seamless", "reactor_params")) ctx.links.params_gen_sphere = link(c, ".", "params-gen-sphere.cson") rc = ctx.gen_sphere = reactor(c) c = ctx.code.gen_sphere = cell(("text", "code", "python")) ctx.links.code_gen_sphere = link(c, ".", "cell-gen-sphere.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.subdivisions = cell("int").set(3) ctx.minimizations = cell("int").set(20) ctx.coordinates = cell("array").set_store("GL") ctx.normals = cell("array").set_store("GL") ctx.edges = cell("array").set_store("GL") ctx.triangle_indices = cell("array").set_store("GL") ctx.triangle_normals = cell("array").set_store("GL") ctx.triangle_coordinates = cell("array").set_store("GL")
".", "cell-gen-texture.py", file_dominant=file_dominant) ctx.tex_radius = ctx.gen_texture.radius.cell() ctx.tex_radius.set(32) ctx.tex_filename = ctx.gen_texture.filename.cell() ctx.tex_filename.set("") ctx.gen_texture.as_float.cell().set(True) ctx.gen_texture.output.connect(ctx.texture) ctx.texture.connect(p.array_s_texture) # Ugly piece of code to display a numpy array texture c = ctx.display_texture = context() c.title = cell("str").set("Texture") c.aspect_layout = pythoncell().fromfile("AspectLayout.py") c.registrar.python.register(c.aspect_layout) c.display_numpy = reactor({ "array": {"pin": "input", "dtype": "array"}, "title": {"pin": "input", "dtype": "str"}, }) c.registrar.python.connect("AspectLayout", c.display_numpy) ctx.texture.connect(c.display_numpy.array) c.title.connect(c.display_numpy.title) c.display_numpy.code_update.set("update()") c.display_numpy.code_stop.set("destroy()") c.code = pythoncell() c.code.connect(c.display_numpy.code_start) c.code.fromfile("cell-display-numpy.py") # /Ugly piece of code to display a texture #Uniforms ctx.uniforms = cell("json") ctx.uniforms.connect(p.uniforms)
def basic_display(ctx, display_type, title): from seamless import reactor _displays = { "int": { "code": "cell-basic_display_int.py", "update": "cell-basic_display_UPDATE.py", }, "float": { "code": "cell-basic_display_float.py", "update": "cell-basic_display_UPDATE.py", }, "text": { "code": "cell-basic_display_text.py", "update": "cell-basic_display_text_UPDATE.py", }, "str": { "code": "cell-basic_display_text.py", "update": "cell-basic_display_text_UPDATE.py", }, ("text", "html"): { "code": "cell-basic_display_html.py", "update": "cell-basic_display_html_UPDATE.py", }, "json": { "code": "cell-basic_display_json.py", "update": "cell-basic_display_json_UPDATE.py", }, } def _match_type(type, typelist): typelist = list(typelist) type2 = type if isinstance(type, str): type2 = (type,) typelist2 = [] for t in typelist: if isinstance(t, str): typelist2.append((t,)) else: typelist2.append(t) matches = [] for n in range(len(typelist)): ltype = typelist2[n] k = min(len(type2), len(ltype)) if type2[:k] == ltype[:k]: matches.append((n, k)) if not len(matches): raise TypeError("Cannot find display for cell type '{0}'".format(type)) matches.sort(key=lambda v: -v[1]) bestmatch = matches[0][0] return typelist[bestmatch] display_type = _match_type(display_type, _displays.keys()) pinparams = { "value": { "pin": "input", "dtype": display_type }, "title": { "pin": "input", "dtype": "str", }, } d = ctx.display = reactor(pinparams) d.title.cell().set(title) d.code_start.cell().fromfile(_displays[display_type]["code"]) d.code_stop.cell().set('w.destroy()') upfile = _displays[display_type]["update"] c_up = d.code_update.cell() if upfile is not None: c_up.fromfile(upfile) else: c_up.set("") ctx.export(d, forced=["title"])
export(tf.code) print(tf.status()) tf.code.set("return inp + 42") print(tf.status()) tf.inp.set(0) print(tf.status()) ctx.equilibrate() print(tf.status()) ctx.inp.disconnect(tf.inp) print(tf.status()) rc = ctx.rc = reactor({ "inp2": { "pin": "input", "dtype": "int" }, "outp2": { "pin": "output", "dtype": "int" }, }) rc.code_start.cell().set("") rc.code_stop.cell().set("") rc.code_update.cell().set("PINS.outp2.set(PINS.inp2.get()+42)") export(rc.outp2) print(rc.status()) print(ctx.status()) export(rc.inp2) ctx.inp.connect(tf.inp) print(ctx.status()) ctx.inp2.set(12) print(ctx.status())
def glprogram(ctx, program, with_window, window_title): from seamless import cell, reactor, macro from seamless.core.worker import ExportedInputPin, ExportedOutputPin, \ ExportedEditPin from seamless.lib.gui.gl.glwindow import glwindow arrays = program["arrays"] textures = program.get("textures", []) rcparams = { #signals "init": { "pin": "input", "dtype": "signal", }, "paint": { "pin": "input", "dtype": "signal", }, "repaint": { "pin": "output", "dtype": "signal", }, #shaders "vertex_shader": { "pin": "input", "dtype": ("text", "code", "vertexshader"), }, "fragment_shader": { "pin": "input", "dtype": ("text", "code", "fragmentshader"), }, #program "program": { "pin": "input", "dtype": "json", }, #uniforms "uniforms" : { "pin": "input", "dtype": "json" } } for ar in arrays: rcparams["array_" + ar] = {"pin": "input","dtype": "array"} for ar in textures: assert ar not in program["arrays"], ar rcparams["array_" + ar] = {"pin": "input","dtype": "array"} ctx.rcparams = cell("json").set(rcparams) ctx.rc = reactor(ctx.rcparams) ctx.rc.code_start.cell().fromfile("cell-glprogram.py") ctx.rc.code_update.cell().set("do_update()") ctx.rc.code_stop.cell().set("") ctx.rc.program.cell().set(program) if with_window: ctx.glwindow = glwindow(window_title) ctx.glwindow.init.cell().connect(ctx.rc.init) ctx.glwindow.paint.cell().connect(ctx.rc.paint) ctx.rc.repaint.cell().connect(ctx.glwindow.update) ctx.update = ExportedInputPin(ctx.glwindow.update) ctx.painted = ExportedOutputPin(ctx.glwindow.painted) ctx.camera = ExportedEditPin(ctx.glwindow.camera) ctx.last_key = ExportedOutputPin(ctx.glwindow.last_key) ctx.export(ctx.rc)
del ctx.edit.minimizations del ctx.gen_sphere del ctx.params.gen_sphere del ctx.links.params_gen_sphere del ctx.links.code_gen_sphere ctx.texture_coords = cell("array").set_store("GL") ctx.triangle_texture_coords = cell("array").set_store("GL") #for now, load-ply must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.load_ply = cell(("cson", "seamless", "reactor_params")) ctx.links.params_load_ply = link(c, ".", "params-load-ply.cson") rc = ctx.load_ply = reactor(c) c = ctx.code.load_ply = cell(("text", "code", "python")) ctx.links.code_load_ply = link(c, ".", "cell-load-ply2.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.load_ply.coordinates.connect(ctx.coordinates_prescale) ctx.load_ply.normals.connect(ctx.normals) ctx.load_ply.edges.connect(ctx.edges) ctx.load_ply.triangle_indices.connect(ctx.triangle_indices) ctx.load_ply.triangle_coordinates.connect(ctx.triangle_coordinates_prescale) ctx.load_ply.triangle_normals.connect(ctx.triangle_normals) ctx.load_ply.texture_coords.connect(ctx.texture_coords) ctx.load_ply.triangle_texture_coords.connect(ctx.triangle_texture_coords) ctx.filename = cell("str")
def basic_editor(ctx, editor_type, title): from seamless import reactor _editors = { "int": { "code": "cell-basic_editor_int.py", "update": "cell-basic_editor_int_UPDATE.py", }, "float": { "code": "cell-basic_editor_float.py", "update": "cell-basic_editor_UPDATE.py", }, "str": { "code": "cell-basic_editor_str.py", "update": "cell-basic_editor_str_UPDATE.py", }, "text": { "code": "cell-basic_editor_text.py", "update": "cell-basic_editor_text_UPDATE.py", }, "json": { "code": "cell-basic_editor_json.py", "update": "cell-basic_editor_json_UPDATE.py", }, } _editors["cson"] = _editors["text"] def _match_type(type, typelist): typelist = list(typelist) type2 = type if isinstance(type, str): type2 = (type,) typelist2 = [] for t in typelist: if isinstance(t, str): typelist2.append((t,)) else: typelist2.append(t) matches = [] for n in range(len(typelist)): ltype = typelist2[n] k = min(len(type2), len(ltype)) if type2[:k] == ltype[:k]: matches.append((n, k)) if not len(matches): raise TypeError("Cannot find editor for cell type '{0}'".format(type)) matches.sort(key=lambda v: -v[1]) bestmatch = matches[0][0] return typelist[bestmatch] editor_type = _match_type(editor_type, _editors.keys()) pinparams = { "value": { "pin": "edit", "dtype": editor_type, "must_be_defined": False }, "title": { "pin": "input", "dtype": "str", }, } if editor_type == "int": pinparams["maximum"] = {"pin": "input", "dtype": "int"} rc = ctx.rc = reactor(pinparams) rc.title.cell().set(title) forced = ["title"] if editor_type == "int": rc.maximum.set(9999999) forced.append("maximum") rc.code_start.cell().fromfile(_editors[editor_type]["code"]) rc.code_stop.cell().set('w.destroy()') upfile = _editors[editor_type]["update"] c_up = rc.code_update.cell(True) if upfile is not None: c_up.fromfile(upfile) else: c_up.set("") ctx.export(rc, forced=forced)
del ctx.edit.subdivisions del ctx.minimizations del ctx.edit.minimizations del ctx.gen_sphere del ctx.params.gen_sphere del ctx.links.params_gen_sphere del ctx.links.code_gen_sphere ctx.texture_coords = cell("array").set_store("GL") ctx.triangle_texture_coords = cell("array").set_store("GL") #for now, load-ply must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.load_ply = cell(("cson", "seamless", "reactor_params")) ctx.links.params_load_ply = link(c, ".", "params-load-ply.cson") rc = ctx.load_ply = reactor(c) c = ctx.code.load_ply = cell(("text", "code", "python")) ctx.links.code_load_ply = link(c, ".", "cell-load-ply2.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.load_ply.coordinates.connect(ctx.coordinates_prescale) ctx.load_ply.normals.connect(ctx.normals) ctx.load_ply.edges.connect(ctx.edges) ctx.load_ply.triangle_indices.connect(ctx.triangle_indices) ctx.load_ply.triangle_coordinates.connect(ctx.triangle_coordinates_prescale) ctx.load_ply.triangle_normals.connect(ctx.triangle_normals) ctx.load_ply.texture_coords.connect(ctx.texture_coords) ctx.load_ply.triangle_texture_coords.connect(ctx.triangle_texture_coords) ctx.filename = cell("str")
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)
def basic_display(ctx, display_type, title): from seamless import reactor _displays = { "int": { "code": "cell-basic_display_int.py", "update": "cell-basic_display_UPDATE.py", }, "float": { "code": "cell-basic_display_float.py", "update": "cell-basic_display_UPDATE.py", }, "text": { "code": "cell-basic_display_text.py", "update": "cell-basic_display_text_UPDATE.py", }, "str": { "code": "cell-basic_display_text.py", "update": "cell-basic_display_text_UPDATE.py", }, ("text", "html"): { "code": "cell-basic_display_html.py", "update": "cell-basic_display_html_UPDATE.py", }, "json": { "code": "cell-basic_display_json.py", "update": "cell-basic_display_json_UPDATE.py", }, } _displays["cson"] = _displays["text"] def _match_type(type, typelist): typelist = list(typelist) type2 = type if isinstance(type, str): type2 = (type, ) typelist2 = [] for t in typelist: if isinstance(t, str): typelist2.append((t, )) else: typelist2.append(t) matches = [] for n in range(len(typelist)): ltype = typelist2[n] k = min(len(type2), len(ltype)) if type2[:k] == ltype[:k]: matches.append((n, k)) if not len(matches): raise TypeError( "Cannot find display for cell type '{0}'".format(type)) matches.sort(key=lambda v: -v[1]) bestmatch = matches[0][0] return typelist[bestmatch] display_type = _match_type(display_type, _displays.keys()) pinparams = { "value": { "pin": "input", "dtype": display_type }, "title": { "pin": "input", "dtype": "str", }, } d = ctx.display = reactor(pinparams) d.title.cell().set(title) d.code_start.cell().fromfile(_displays[display_type]["code"]) d.code_stop.cell().set('w.destroy()') upfile = _displays[display_type]["update"] c_up = d.code_update.cell() if upfile is not None: c_up.fromfile(upfile) else: c_up.set("") ctx.export(d, forced=["title"])
from seamless import context, cell, transformer, reactor from seamless.lib import edit, display, link from seamless.lib.gui.gl import glprogram, glwindow import numpy as np ctx = context() ctx.params = context() ctx.links = context() ctx.code = context() #for now, gen_sphere must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.gen_sphere = cell(("cson", "seamless", "reactor_params")) ctx.links.params_gen_sphere = link(c, ".", "params-gen-sphere.cson") rc = ctx.gen_sphere = reactor(c) c = ctx.code.gen_sphere = cell(("text", "code", "python")) ctx.links.code_gen_sphere = link(c, ".", "cell-gen-sphere.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.subdivisions = cell("int").set(3) ctx.minimizations = cell("int").set(20) ctx.coordinates = cell("array").set_store("GL") ctx.normals = cell("array").set_store("GL") ctx.edges = cell("array").set_store("GL") ctx.triangle_indices = cell("array").set_store("GL") ctx.triangle_normals = cell("array").set_store("GL") ctx.triangle_coordinates = cell("array").set_store("GL")
del ctx.edit.subdivisions del ctx.minimizations del ctx.edit.minimizations del ctx.gen_sphere del ctx.params.gen_sphere del ctx.links.params_gen_sphere del ctx.links.code_gen_sphere ctx.texture_coords = cell("array").set_store("GL") ctx.triangle_texture_coords = cell("array").set_store("GL") #for now, load-ply must be a reactor, because it has multiple outputs #TODO: make it a transformer in a future version of seamless c = ctx.params.load_ply = cell(("cson", "seamless", "reactor_params")) ctx.links.params_load_ply = link(c, ".", "params-load-ply.cson") rc = ctx.load_ply = reactor(c) c = ctx.code.load_ply = cell(("text", "code", "python")) ctx.links.code_load_ply = link(c, ".", "cell-load-ply2.py") rc.code_start.cell().set("") c.connect(rc.code_update) rc.code_stop.cell().set("") ctx.load_ply.coordinates.connect(ctx.coordinates_prescale) ctx.load_ply.normals.connect(ctx.normals) ctx.load_ply.edges.connect(ctx.edges) ctx.load_ply.triangle_indices.connect(ctx.triangle_indices) ctx.load_ply.triangle_coordinates.connect(ctx.triangle_coordinates_prescale) ctx.load_ply.triangle_normals.connect(ctx.triangle_normals) ctx.load_ply.texture_coords.connect(ctx.texture_coords) ctx.load_ply.triangle_texture_coords.connect(ctx.triangle_texture_coords) ctx.filename = cell("str")
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": {