PMWindow.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. """
  2. Created on 22-04-2013
  3. @author: citan
  4. """
  5. import pygame
  6. class PMWindow(object):
  7. """
  8. classdocs
  9. """
  10. def __init__(self):
  11. self._fg_color = pygame.Color(255, 255, 255)
  12. self._bg_color = pygame.Color(0, 0, 0)
  13. self._dict = dict()
  14. # P60 Gear position
  15. # P97 Transfer Duty Ratio
  16. # P96 Lock Up Duty Ratio
  17. # P122 Oil Temperature
  18. # P104 ATF Temperature
  19. self._pids = ["P60", "P97", "P96", "P122", "P104"]
  20. def set_surface(self, surface):
  21. self._surface = surface
  22. self._width = self._surface.get_width()
  23. self._height = self._surface.get_height()
  24. self._title_font_size = int(self._surface.get_height() / 16)
  25. self._value_font_size = int(self._surface.get_height() / 3)
  26. self._title_font = pygame.font.SysFont(pygame.font.get_default_font(), self._title_font_size)
  27. self._value_font = pygame.font.SysFont(pygame.font.get_default_font(), self._value_font_size)
  28. self._font_aa = 1
  29. self._value_lbl_width = self._value_font.render("999", self._font_aa, self._fg_color).get_width()
  30. def render(self):
  31. first_row_height = self._title_font_size + self._value_font_size + 10
  32. second_row_height = first_row_height + self._title_font_size + self._value_font_size + 20
  33. pygame.draw.line(self._surface, self._fg_color, (0, first_row_height + 10),
  34. (self._width, first_row_height + 10))
  35. for param, value in self._dict.iteritems():
  36. title = param.get_name() # + " (" + param.get_default_unit() + ")"
  37. first_row_ids = ["P60", "P122", "P104"]
  38. if param.get_id() in first_row_ids:
  39. index = first_row_ids.index(param.get_id())
  40. x_offset = (self._width / len(first_row_ids)) * index + 10
  41. titlelbl = self._title_font.render(title, self._font_aa, self._fg_color)
  42. valuelbl = self._value_font.render(value, self._font_aa, self._fg_color)
  43. self._surface.blit(titlelbl, (x_offset + 10, 10))
  44. self._surface.blit(valuelbl, (x_offset + 10, 10 + self._title_font_size))
  45. pygame.draw.line(self._surface, self._fg_color, (x_offset, 0), (x_offset, first_row_height))
  46. second_row_ids = ["P97", "P96"]
  47. if param.get_id() in second_row_ids:
  48. index = second_row_ids.index(param.get_id())
  49. x_offset = (self._width / len(second_row_ids)) * index + 10
  50. titlelbl = self._title_font.render(title, self._font_aa, self._fg_color)
  51. valuelbl = self._value_font.render(value, self._font_aa, self._fg_color)
  52. self._surface.blit(titlelbl, (x_offset + 10, first_row_height + 20))
  53. self._surface.blit(valuelbl, (x_offset + 10, first_row_height + 20 + self._title_font_size))
  54. pygame.draw.line(self._surface, self._fg_color, (x_offset, first_row_height + 20),
  55. (x_offset, second_row_height))
  56. def get_pids(self):
  57. return self._pids
  58. def set_value(self, param, packet):
  59. self._dict[param] = param.get_value(packet)