controller
- class trame_server.controller.Controller(server)
Controller acts as a container for function proxies
It allows functions to be passed around that are not yet defined, and can be defined or re-defined later. For example:
>>> ctrl.trigger_name(fn) trigger__12
>>> f = ctrl.hello_func # function is currently undefined >>> ctrl.hello_func = lambda: print("Hello, world!") >>> f() Hello, world!
>>> ctrl.hello_func = lambda: print("Hello again!") >>> f() Hello again!
>>> ctrl.on_data_change.add(lambda: print("Update pipeline!")) >>> ctrl.on_data_change.add(lambda: print("Update view!")) >>> ctrl.on_data_change.add(lambda: print("Wow that is pretty cool!")) >>> ctrl.on_data_change() "Update pipeline!" "Wow that is pretty cool!" "Update view!" >>> ctrl.on_data_change.clear(set_only=True) # add, remove, discard, clear
- add(name, clear=False)
Use as decorator @ctrl.add(name) so the decorated function will be added to a given controller name
- Parameters:
name (str) – Controller method name to be added to
ctrl = server.controller @ctr.add("on_server_ready") def on_ready(**state): pass # or ctrl.on_server_ready.add(on_ready)
You can also make sure when the method get registered we clear any previous content.
ctrl = server.controller @ctr.add("on_server_ready", clear=True) def on_ready(**state): pass # or ctrl.on_server_ready.clear() ctrl.on_server_ready.add(on_ready)
- once(name)
Use as decorator @ctrl.once(name) so the decorated function will be added to a given controller name and will only execute once.
- Parameters:
name (str) – Controller method name to be added to
ctrl = server.controller @ctr.once("on_server_ready") def on_ready(**state): pass # or ctrl.on_server_ready.once(on_ready)
- add_task(name, clear=False)
Use as decorator @ctrl.add_task(name) so the decorated function will be added to a given controller name
- Parameters:
name (str) – Controller method name to be added to
ctrl = server.controller @ctr.add_task("on_server_ready") async def on_ready(**state): pass # or ctrl.on_server_ready.add_task(on_ready)
You can also make sure when the method get registered we clear any previous content.
ctrl = server.controller @ctr.add_task("on_server_ready", clear=True) async def on_ready(**state): pass # or ctrl.on_server_ready.clear() ctrl.on_server_ready.add_task(on_ready)
- set(name, clear=False)
Use as decorator @ctrl.set(name) so the decorated function will be added to a given controller name
- Parameters:
name (str) – Controller method name to be set to
ctrl = server.controller @ctr.set("on_server_ready") def on_ready(**state): pass # or ctrl.on_server_ready = on_ready
You can also make sure when the method get registered we clear any previous content.
ctrl = server.controller @ctr.set("on_server_ready", clear=True) def on_ready(**state): pass # or ctrl.on_server_ready.clear() ctrl.on_server_ready = on_ready
- class trame_server.controller.ControllerFunction(controller, name, func=None)
Controller functions are callable function proxy objects
Any calls are forwarded to the internal function, which may be undefined or dynamically changed. If a call is made when the internal function is undefined, a FunctionNotImplementedError is raised.
- once(func)
Add function to the set of functions to be called when the current ControllerFunction is called. After first execution, the function will automatically be removed.
- Parameters:
func – Function to add
- add(func)
Add function to the set of functions to be called when the current ControllerFunction is called.
- Parameters:
func – Function to add
- add_task(func)
Add task to the set of coroutine to be called when the current ControllerFunction is called.
- Parameters:
func – Function to add
- discard(func)
Discard function to the set of functions to be called when the current ControllerFunction is called.
- Parameters:
func – Function to discard
- remove(func)
Remove function to the set of functions to be called when the current ControllerFunction is called.
- Parameters:
func – Function to remove
- remove_task(func)
Remove task function to the set of functions to be called when the current ControllerFunction is called.
- Parameters:
func – Function to remove
- clear(set_only=False)
Clear all the functions registered to the current ControllerFunction.
- Parameters:
set_only – (default: False) If true only the “added” one will be removed.
- exists()
Check if at least a function was registered to the current ControllerFunction.
- Returns:
True if either a function was set or added