PMWindow.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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), (self._width, first_row_height + 10))
  34. for param, value in self._dict.iteritems():
  35. title = param.get_name() #+ " (" + param.get_default_unit() + ")"
  36. first_row_ids = ["P60", "P122", "P104"]
  37. if param.get_id() in first_row_ids:
  38. index = first_row_ids.index(param.get_id())
  39. x_offset = (self._width / len(first_row_ids)) * index + 10
  40. titlelbl = self._title_font.render(title, self._font_aa, self._fg_color)
  41. valuelbl = self._value_font.render(value, self._font_aa, self._fg_color)
  42. self._surface.blit(titlelbl, (x_offset + 10, 10))
  43. self._surface.blit(valuelbl, (x_offset + 10, 10 + self._title_font_size))
  44. pygame.draw.line(self._surface, self._fg_color, (x_offset, 0), (x_offset, first_row_height))
  45. second_row_ids = ["P97", "P96"]
  46. if param.get_id() in second_row_ids:
  47. index = second_row_ids.index(param.get_id())
  48. x_offset = (self._width / len(second_row_ids)) * index + 10
  49. titlelbl = self._title_font.render(title, self._font_aa, self._fg_color)
  50. valuelbl = self._value_font.render(value, self._font_aa, self._fg_color)
  51. self._surface.blit(titlelbl, (x_offset + 10, first_row_height + 20))
  52. self._surface.blit(valuelbl, (x_offset + 10, first_row_height + 20 + self._title_font_size))
  53. pygame.draw.line(self._surface, self._fg_color, (x_offset, first_row_height + 20), (x_offset, second_row_height))
  54. x_offset += 10
  55. def get_pids(self):
  56. return self._pids
  57. def set_value(self, param, packet):
  58. self._dict[param] = param.get_value(packet)