text.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import constants
  2. import modes
  3. import positions
  4. from packet import Packet
  5. class Text(object):
  6. def __init__(self, msg=None, label=None, size=None, position=None, mode=None):
  7. if label is None:
  8. label = "A"
  9. if size is None:
  10. size = 64
  11. if len(msg) > size:
  12. size = len(msg)
  13. if size > 125:
  14. size = 125
  15. if size < 1:
  16. size = 1
  17. if position is None:
  18. position = positions.MIDDLE_LINE
  19. if mode is None:
  20. mode = modes.ROTATE
  21. self.label = label
  22. self.size = size
  23. self.msg = msg
  24. self.position = position
  25. self.mode = mode
  26. def __str__(self):
  27. # [WRITE_TEXT][File Label][ESC][Display Position][Mode Code]
  28. # [Special Specifier][ASCII Message]
  29. packet = Packet("%s%s%s%s%s%s" % (constants.WRITE_TEXT, self.label,
  30. constants.ESC,
  31. self.position,
  32. self.mode,
  33. self.msg))
  34. return str(packet)
  35. def __repr__(self):
  36. return repr(self.__str__())