Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/example_animated.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

# Animation frames per second to attempt to display on the StreamDeck devices.
FRAMES_PER_SECOND = 30
closed_event = threading.Event()


# Loads in a source image, extracts out the individual animation frames (if
Expand Down Expand Up @@ -60,12 +61,14 @@ def create_animation_frames(deck, image_filename):
def key_change_callback(deck, key, state):
# Use a scoped-with on the deck to ensure we're the only thread using it
# right now.
with deck:
# Reset deck, clearing all button images.
deck.reset()
if state:
closed_event.set()
with deck:
# Reset deck, clearing all button images.
deck.reset()

# Close deck handle, terminating internal worker threads.
deck.close()
# Close deck handle, terminating internal worker threads.
deck.close()


if __name__ == "__main__":
Expand Down Expand Up @@ -124,7 +127,7 @@ def animate(fps):

# Periodic loop that will render every frame at the set FPS until
# the StreamDeck device we're using is closed.
while deck.is_open():
while not closed_event.is_set() and deck.is_open():
try:
# Use a scoped-with on the deck to ensure we're the only
# thread using it right now.
Expand Down