event.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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__ = ["name", "params"]
  11. name: str # solely used for pretty printing
  12. params: List[Any]
  13. def __str__(self):
  14. s = "Event("+self.name
  15. if self.params:
  16. s += str(self.params)
  17. s += ")"
  18. return termcolor.colored(s, 'yellow')
  19. __repr__ = __str__
  20. @dataclass
  21. class OutputEvent:
  22. __slots__ = ["name", "params"]
  23. # port: str
  24. name: str
  25. params: List[Any]
  26. # Compare by value
  27. def __eq__(self, other):
  28. # return self.port == other.port and self.name == other.name and self.params == other.params
  29. return self.name == other.name and self.params == other.params
  30. def __str__(self):
  31. s = "OutputEvent("+self.name
  32. if self.params:
  33. s += str(self.params)
  34. s += ")"
  35. return termcolor.colored(s, 'yellow')
  36. __repr__ = __str__