| Total Complexity | 9 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | * PyDMXControl: A Python 3 module to control DMX using OpenDMX or uDMX. |
||
| 3 | * Featuring fixture profiles, built-in effects and a web control panel. |
||
| 4 | * <https://github.com/MattIPv4/PyDMXControl/> |
||
| 5 | * Copyright (C) 2021 Matt Cowley (MattIPv4) ([email protected]) |
||
| 6 | """ |
||
| 7 | |||
| 8 | from typing import List |
||
| 9 | |||
| 10 | |||
| 11 | class Effect: |
||
| 12 | |||
| 13 | def __init__(self, fixture: 'Fixture', speed: float, *, delay: float = 0, offset: float = 0): |
||
| 14 | # The fixture effect is applied to |
||
| 15 | self.fixture = fixture |
||
| 16 | |||
| 17 | # Speed for effect to complete |
||
| 18 | self.speed = speed |
||
| 19 | |||
| 20 | # Delay & offset to allow effect stacking across fixtures |
||
| 21 | self.delay = delay / 100 |
||
| 22 | self.offset = offset / 100 |
||
| 23 | |||
| 24 | # Animating flag for ticket |
||
| 25 | self.__animating = False |
||
| 26 | |||
| 27 | def __callback(self): |
||
| 28 | if self.__animating: |
||
| 29 | self.callback() |
||
| 30 | |||
| 31 | def callback(self): |
||
| 32 | pass |
||
| 33 | |||
| 34 | def pause(self) -> bool: |
||
| 35 | self.__animating = not self.__animating |
||
| 36 | return self.__animating |
||
| 37 | |||
| 38 | def stop(self): |
||
| 39 | self.__animating = False |
||
| 40 | self.fixture.controller.ticker.remove_callback(self.__callback) |
||
| 41 | |||
| 42 | def start(self): |
||
| 43 | self.__animating = True |
||
| 44 | self.fixture.controller.ticker.add_callback(self.__callback, 0) |
||
| 45 | |||
| 46 | @classmethod |
||
| 47 | def group_apply(cls, fixtures: List['Fixture'], speed: float, *args, **kwargs): |
||
| 48 | # Position |
||
| 49 | index = 0 |
||
| 50 | total = len(fixtures) - 1 |
||
| 51 | |||
| 52 | # Iterate over each |
||
| 53 | for fixture in fixtures: |
||
| 54 | fixture.add_effect(cls, speed, delay=total * 100, offset=index * 100, *args, **kwargs) |
||
| 55 | index += 1 |
||
| 56 |