text.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import constants
  2. import modes
  3. import positions
  4. from packet import Packet
  5. class Text(object):
  6. """Class representing a TEXT file."""
  7. def __init__(self, data=None, label=None, size=None,
  8. position=None, mode=None):
  9. """
  10. :param data: initial string to insert into object
  11. :param label: file label: (default: "A")
  12. :param size: amount of bytes to allocate for object on sign (default: 64)
  13. :param position: constant from :mod:`alphasign.positions`
  14. :param mode: constant from :mod:`alphasign.modes`
  15. """
  16. if data is None:
  17. data = ""
  18. if label is None:
  19. label = "A"
  20. if size is None:
  21. size = 64
  22. if len(data) > size:
  23. size = len(data)
  24. if size > 125:
  25. size = 125
  26. if size < 1:
  27. size = 1
  28. if position is None:
  29. position = positions.MIDDLE_LINE
  30. if mode is None:
  31. mode = modes.ROTATE
  32. self.label = label
  33. self.size = size
  34. self.data = data
  35. self.position = position
  36. self.mode = mode
  37. def __str__(self):
  38. # [WRITE_TEXT][File Label][ESC][Display Position][Mode Code]
  39. # [Special Specifier][ASCII Message]
  40. packet = Packet("%s%s%s%s%s%s" % (constants.WRITE_TEXT, self.label,
  41. constants.ESC,
  42. self.position,
  43. self.mode,
  44. self.data))
  45. return str(packet)
  46. def __repr__(self):
  47. return repr(self.__str__())