animations
All animation-related classes & functions.
The biggest exports are Animation
and its subclasses, as well as Animator
. A
global instance of Animator
is also exported, under the animator
name.
These can be used both within a WindowManager context (where stepping is done
automatically by the pytermgui.window_manager.Compositor
on every frame, or manually,
by calling animator.step
with an elapsed time argument.
You can register animations to the Animator using either its schedule
method, with
an already constructed Animation
subclass, or either Animator.animate_attr
or
Animator.animate_float
for an in-place construction of the animation instance.
animator = Animator()
module-attribute
The global Animator instance used by all of the library.
Animation
dataclass
The baseclass for all animations.
Source code in pytermgui/animations.py
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 |
|
finish()
Finishes and cleans up after the animation.
Called by Animator
after on_step
returns True. Should call on_finish
if it
is not None.
Source code in pytermgui/animations.py
158 159 160 161 162 163 164 165 166 |
|
pause(setting=True)
Pauses the animation.
Source code in pytermgui/animations.py
130 131 132 133 |
|
resume()
Resumes the animation.
Source code in pytermgui/animations.py
135 136 137 138 |
|
step(elapsed)
Updates animation state.
This should call _update_state
, passing in the elapsed value. That call
will update the state
attribute, which can then be used to animate things.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elapsed |
float
|
The time elapsed since last update. |
required |
Source code in pytermgui/animations.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
Animator
The Animator class
This class maintains a list of animations (self._animations), stepping each of them forward as long as they return False. When they return False, the animation is removed from the tracked animations.
This stepping is done when step
is called.
Source code in pytermgui/animations.py
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
is_active: bool
property
Determines whether there are any active animations.
__contains__(item)
Returns whether the item is inside _animations.
Source code in pytermgui/animations.py
264 265 266 267 |
|
__init__()
Initializes an animator.
Source code in pytermgui/animations.py
259 260 261 262 |
|
animate_attr(**animation_args)
Creates and schedules an AttrAnimation.
All arguments are passed to the AttrAnimation
constructor. direction
, if
given as an integer, will be converted to a Direction
before being passed.
Returns:
Type | Description |
---|---|
AttrAnimation
|
The created animation. |
Source code in pytermgui/animations.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
animate_float(**animation_args)
Creates and schedules an Animation.
All arguments are passed to the Animation
constructor. direction
, if
given as an integer, will be converted to a Direction
before being passed.
Returns:
Type | Description |
---|---|
FloatAnimation
|
The created animation. |
Source code in pytermgui/animations.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
schedule(animation)
Starts an animation on the next step.
Source code in pytermgui/animations.py
283 284 285 286 |
|
step(elapsed)
Steps the animation forward by the given elapsed time.
Source code in pytermgui/animations.py
275 276 277 278 279 280 281 |
|
AttrAnimation
dataclass
Bases: Animation
Animates an attribute going from one value to another.
Source code in pytermgui/animations.py
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 |
|
finish()
Deletes __ptg_animated__
flag, calls on_finish
.
Source code in pytermgui/animations.py
242 243 244 245 246 |
|
step(elapsed)
Steps forward in the attribute animation.
Source code in pytermgui/animations.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
Direction
Bases: Enum
Animation directions.
Source code in pytermgui/animations.py
73 74 75 76 77 |
|
FloatAnimation
dataclass
Bases: Animation
Transitions a floating point number from 0.0 to 1.0.
Note that this is just a wrapper over the base class, and provides no extra functionality.
Source code in pytermgui/animations.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
is_animated(target, attribute)
Determines whether the given object.attribute is animated.
This looks for __ptg_animated__
, and whether it contains the given attribute.
Source code in pytermgui/animations.py
59 60 61 62 63 64 65 66 67 68 69 70 |
|