API Reference
Decks and Slides
spiel.Deck
dataclass
Represents a "deck" of "slides": a presentation.
name: str
instance-attribute
The name of the Deck
, which will be displayed in the footer.
default_transition: Type[Transition] | None = Swipe
class-attribute
instance-attribute
The default slide transition animation;
used if the slide being moved to does not specify its own transition.
Defaults to the Swipe
transition.
Set to None
for no transition animation.
slide(title='', bindings=None, transition=None)
A decorator that creates a new slide in the deck,
with the decorated function as the Slide.content
.
PARAMETER | DESCRIPTION |
---|---|
title |
The title to display for the slide.
TYPE:
|
bindings |
A mapping of keys to callables to be executed when those keys are pressed, when on this slide.
TYPE:
|
transition |
The transition animation to use when moving to this slide.
Set to
TYPE:
|
add_slides(*slides)
Add Slide
s to a Deck
.
This function is primarily useful when adding multiple slides at once,
probably generated programmatically.
If adding a single slide, prefer the Deck.slide
decorator.
PARAMETER | DESCRIPTION |
---|---|
*slides |
The
TYPE:
|
spiel.Slide
dataclass
Represents a single slide in the presentation.
title: str = ''
class-attribute
instance-attribute
The title of the Slide
, which will be displayed in the footer.
content: Content = Text
class-attribute
instance-attribute
A callable that is invoked by Spiel to display the slide's content.
The function may optionally take arguments with these names:
trigger
: The currentTrigger
state, for use in animations.
bindings: Mapping[str, Callable[..., None]] = field(default_factory=dict)
class-attribute
instance-attribute
A mapping of keys to callables to be executed when those keys are pressed, when on this slide.
transition: Type[Transition] | None = Swipe
class-attribute
instance-attribute
The transition animation to use when moving to this slide.
Set to None
to use the
Deck.default_transition
of the deck this slide is in.
Rendering Content
spiel.Triggers
dataclass
Provides information to Slide.content
about the current slide's "trigger state".
Triggers
is a Sequence
of times
(produced by time.monotonic
)
that the current slide was triggered at.
Note that the slide will be triggered once when it starts being displayed,
so the first trigger time will be the time when the slide started being displayed.
now: float
instance-attribute
The time that the slide content is being rendered at. Use this is as a single consistent value to base relative times on.
time_since_last_trigger: float
cached
property
The elapsed time since the most recent trigger.
time_since_first_trigger: float
cached
property
The elapsed time since the first trigger, which is equivalent to the time since the slide started being displayed.
triggered: bool
cached
property
Returns whether the slide has been manually triggered (i.e., this ignores the initial trigger from when the slide starts being displayed).
take(iter, offset=1)
Takes elements from the iterable iter
equal to the number of times in the Triggers
minus the offset.
PARAMETER | DESCRIPTION |
---|---|
iter |
The iterable to take elements from.
TYPE:
|
offset |
This
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Iterator[T]
|
An iterator over the first |
Transitions
spiel.Direction
Bases: Enum
An enumeration that describes which direction a slide transition animation should move in: whether we're going to the next slide, or to the previous slide.
Next = 'next'
class-attribute
instance-attribute
Indicates that the transition should handle going to the next slide.
Previous = 'previous'
class-attribute
instance-attribute
Indicates that the transition should handle going to the previous slide.
spiel.Transition
Bases: Protocol
A protocol that describes how to implement a transition animation.
See Writing Custom Transitions for more details on how to implement the protocol.
initialize(from_widget, to_widget, direction)
A hook function to set up any CSS that should be present at the start of the transition.
PARAMETER | DESCRIPTION |
---|---|
from_widget |
The widget showing the slide that we are leaving.
TYPE:
|
to_widget |
The widget showing the slide that we are entering.
TYPE:
|
direction |
The desired direction of the transition animation.
TYPE:
|
progress(from_widget, to_widget, direction, progress)
A hook function that is called each time the progress
of the transition animation updates.
PARAMETER | DESCRIPTION |
---|---|
from_widget |
The widget showing the slide that we are leaving.
TYPE:
|
to_widget |
The widget showing the slide that we are entering.
TYPE:
|
direction |
The desired direction of the transition animation.
TYPE:
|
progress |
The progress of the animation, as a percentage
(e.g., initial state is
TYPE:
|
spiel.Swipe
Bases: Transition
A transition where the current and incoming slide are placed side-by-side and gradually slide across the screen, with the current slide leaving and the incoming slide entering.
Presenting Decks
spiel.present(deck_path, watch_path=None)
Present the deck defined in the given deck_path
.
PARAMETER | DESCRIPTION |
---|---|
deck_path |
The file to look for a deck in. |
watch_path |
When filesystem changes are detected below this path (recursively), reload the deck from the |