SourceClass talon.Module
from talon import Moduleclass ModuleCreating a Module:
from talon import Module
mod = Module()
Attributes
apps§
apps: AppNamespaceMethods
action_class§
def action_class(self, cls: Class) -> ActionClassProxy@mod.action_class
class Actions:
def action_name():
"Description of the action"
def second_action(arg1: int, arg2: str='') -> str:
"Action with arguments, return type, and body"
return 'test'
action§
def action(self, func: DecoratedT) -> ActionDecl[DecoratedT]@mod.action
def action_name():
"Description of the action"
capture§
def capture(self, *, rule: str) -> DecoratorTypedef capture(self, func: DecoratedT) -> DecoratedTYou can declare a capture on a Module by writing @mod.capture(rule=rule), where rule is the capture rule, and then a function for the capture that has a documentation string. If you want to provide an implementation for a capture, provide a function definition deciding what to convert the spoken input to. The spoken input can be parsed as a list of words, but you can also use the names of lists and captures used as attributes on the input. You define the rule using the same syntax that you use for command spoken forms in a .talon file.
@mod.capture
def capture_name() -> str:
"Description of the capture"
scope§
def scope(self, func: ScopeFunc) -> ScopeDeclA scope is a highly flexible abstraction for context matching. You declare a scope on a Module by writing @mod.scope followed by a function that returns a dictionary mapping the name of the scope to its value. You then call .update() on that function to update the value of the scope.
@mod.scope
def scope():
return {
"key": "value",
}
# call scope.update() at any time to force a scope update
setting§
def setting[T](self, name: str, type: type[T], default: T | SettingDecl.NoValueType = ..., desc: str | None = None) -> SettingDecl[T]You declare a setting on a module by calling mod.setting(). You can access a setting value in Python code by calling settings.get() with the setting name. Example:
mod.setting("setting_name", int, default=0, desc="an example integer setting")
mod.setting("setting_name_2", str, default='', desc="an example string setting")
list§
def list(self, name: str, desc: str | None = None) -> NameDeclYou declare a list on a Module by calling mod.list() with the name of the list and a description. Example:
mod.list("list_name", desc="list description")
mode§
def mode(self, name: str, desc: str | None = None) -> NameDeclYou declare a mode on a Module by calling mod.mode() with the name of the mode and a description. Example:
mod.mode("mode_name", desc="mode description")
tag§
def tag(self, name: str, desc: str | None = None) -> NameDeclYou can define a tag on a Module by calling mod.tag() with the name of the tag and a description. Example:
mod.tag("tag_name", desc="tag description")