Context
TolveraContext
is a shared context or environment for Tolvera
instances.
It is created automatically when a Tolvera
instance is created, if one
does not already exist. It manages the integration of packages for graphics,
computer vision, communications protocols, and more. If multiple Tolvera
instances are created, they must share the same TolveraContext
.
Example
TolveraContext
can be created manually, and shared with multiple Tolvera
instances. Note that only one render
function can be used at a time.
Example
TolveraContext
can also be created automatically, and still shared.
TolveraContext
Context for sharing between multiple Tölvera instances. Context includes Taichi, OSC, IML and CV. All Tölvera instances share the same context and are managed as a dict.
Attributes:
Name | Type | Description |
---|---|---|
kwargs |
dict
|
Keyword arguments for context. |
name |
str
|
Name of context. |
name_clean |
str
|
'Cleaned' name of context. |
i |
int
|
Frame counter. |
x |
int
|
Width of canvas. |
y |
int
|
Height of canvas. |
ti |
Taichi
|
Taichi instance. |
canvas |
Pixels
|
Pixels instance. |
osc |
OSC
|
OSC instance. |
iml |
IML
|
IML instance. |
cv |
CV
|
CV instance. |
_cleanup_fns |
list
|
List of cleanup functions. |
tolveras |
dict
|
Dict of Tölvera instances. |
Source code in src/tolvera/context.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
__init__(**kwargs)
add(tolvera)
Add Tölvera to context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tolvera |
Tolvera
|
Tölvera to add. |
required |
cleanup(f=None)
Decorator for cleanup functions based on iipyper. Make functions run on KeyBoardInterrupt (before exit). Cleanup functions must be defined before render is called!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
Function to cleanup. |
None
|
Returns:
Type | Description |
---|---|
Decorator function if f is None, else decorated function. |
Source code in src/tolvera/context.py
get_by_name(name)
Get Tölvera by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of Tölvera to get. |
required |
Returns:
Name | Type | Description |
---|---|---|
Tölvera |
Tölvera with given name. |
get_names()
Get names of all Tölveras in context.
Returns:
Name | Type | Description |
---|---|---|
list |
List of Tölvera names. |
init(**kwargs)
Initialise wrapped external packages with given keyword arguments. This only happens once when Tölvera is first initialised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
int
|
Width of canvas. Default: 1920. |
required |
y |
int
|
Height of canvas. Default: 1080. |
required |
osc |
bool
|
Enable OSC. Default: False. |
required |
iml |
bool
|
Enable IML. Default: False. |
required |
cv |
bool
|
Enable CV. Default: False. |
required |
Source code in src/tolvera/context.py
remove(name)
Remove Tölvera by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Name of Tölvera to delete. |
required |
render(f=None, **kwargs)
Render Tölvera with given function and keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
function
|
Function to run. Defaults to None. |
None
|
Source code in src/tolvera/context.py
run(f=None, **kwargs)
Run Tölvera with given render function and keyword arguments. This function will run inside a locked thread until KeyboardInterrupt/exit. It runs the render function, updates the OSC map (if enabled), and shows the pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
Function to run. |
None
|
|
**kwargs |
Keyword arguments for function. |
{}
|
Source code in src/tolvera/context.py
stop()
Run cleanup functions and exit.