1 | """ |
||
2 | Enarksh |
||
3 | |||
4 | Copyright 2013-2016 Set Based IT Consultancy |
||
5 | |||
6 | Licence MIT |
||
7 | """ |
||
8 | import abc |
||
9 | |||
10 | from enarksh.event.Event import Event |
||
11 | from enarksh.event.EventActor import EventActor |
||
12 | |||
13 | |||
14 | class StateChange(EventActor, metaclass=abc.ABCMeta): |
||
0 ignored issues
–
show
|
|||
15 | # ------------------------------------------------------------------------------------------------------------------ |
||
16 | def __init__(self): |
||
17 | """ |
||
18 | Object constructor. |
||
19 | """ |
||
20 | EventActor.__init__(self) |
||
21 | |||
22 | self.event_state_change = Event(self) |
||
23 | """ |
||
24 | The event that will be fired when the state of this object has changed. |
||
25 | |||
26 | :type: enarksh.event.Event.Event |
||
27 | """ |
||
28 | |||
29 | # ------------------------------------------------------------------------------------------------------------------ |
||
30 | @abc.abstractmethod |
||
31 | def get_state_attributes(self): |
||
0 ignored issues
–
show
This method should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions. ![]() |
|||
32 | raise NotImplementedError() |
||
33 | |||
34 | # ------------------------------------------------------------------------------------------------------------------ |
||
35 | @staticmethod |
||
36 | def wrapper(func): |
||
0 ignored issues
–
show
This method should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions. ![]() |
|||
37 | def inner(*args, **kwargs): |
||
0 ignored issues
–
show
This function should have a docstring.
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods: class SomeClass:
def some_method(self):
"""Do x and return foo."""
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions. ![]() |
|||
38 | obj = args[0] |
||
39 | |||
40 | # Save the old state of the object. |
||
41 | old = obj.get_state_attributes() |
||
42 | |||
43 | # Run the actual method. |
||
44 | ret = func(*args, **kwargs) |
||
45 | |||
46 | # Save the new state of the object. |
||
47 | new = obj.get_state_attributes() |
||
48 | |||
49 | # If state has changed inform all observers. |
||
50 | if old != new: |
||
51 | obj.event_state_change.fire((old, new)) |
||
52 | |||
53 | return ret |
||
54 | |||
55 | return inner |
||
56 | |||
57 | # ---------------------------------------------------------------------------------------------------------------------- |
||
58 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.