event.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import termcolor
  2. from dataclasses import *
  3. from abc import *
  4. from typing import *
  5. from sccd.util.duration import *
  6. # An event that can cause transitions to happen.
  7. # Input events are internal events too.
  8. @dataclass
  9. class InternalEvent:
  10. __slots__ = ["id", "name", "params"]
  11. id: int
  12. name: str # solely used for pretty printing
  13. params: List[Any]
  14. def __str__(self):
  15. s = "Event("+self.name
  16. if self.params:
  17. s += str(self.params)
  18. s += ")"
  19. return termcolor.colored(s, 'yellow')
  20. __repr__ = __str__
  21. @dataclass
  22. class OutputEvent:
  23. __slots__ = ["port", "name", "params"]
  24. port: str
  25. name: str
  26. params: List[Any]
  27. # Compare by value
  28. def __eq__(self, other):
  29. return self.port == other.port and self.name == other.name and self.params == other.params
  30. def __str__(self):
  31. s = "OutputEvent("+self.port+"."+self.name
  32. if self.params:
  33. s += str(self.params)
  34. s += ")"
  35. return termcolor.colored(s, 'yellow')
  36. __repr__ = __str__