Passed
Push — master ( ad3e94...bc3893 )
by Matt
01:29
created

Effect.__callback()   A

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
"""
2
 *  PyDMXControl: A Python 3 module to control DMX using 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