You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.8 KiB

9 years ago
9 years ago
  1. '''
  2. Created on Dec 23, 2013
  3. @author: Chris
  4. '''
  5. import wx
  6. from gooey.gui.pubsub import pub
  7. from gooey.gui import imageutil, image_repository, events
  8. from gooey.gui.util import wx_util
  9. from gooey.gui.lang import i18n
  10. PAD_SIZE = 10
  11. class FrameHeader(wx.Panel):
  12. def __init__(self, heading, subheading, **kwargs):
  13. wx.Panel.__init__(self, **kwargs)
  14. self.SetDoubleBuffered(True)
  15. self._controller = None
  16. self.heading_msg = heading
  17. self.subheading_msg = subheading
  18. self._header = None
  19. self._subheader = None
  20. self._settings_img = None
  21. self._running_img = None
  22. self._check_mark = None
  23. self._error_symbol = None
  24. self.layouts = {}
  25. self._init_properties()
  26. self._init_components(heading, subheading)
  27. self._init_pages()
  28. self._do_layout()
  29. pub.subscribe(self.load_view, events.WINDOW_CHANGE)
  30. def _init_properties(self):
  31. self.SetBackgroundColour('#ffffff')
  32. self.SetSize((30, 90))
  33. self.SetMinSize((120, 80))
  34. def _init_components(self, heading, subheading):
  35. self._header = wx_util.h1(self, heading)
  36. self._subheader = wx.StaticText(self, label=subheading)
  37. self._settings_img = self._load_image(image_repository.config_icon, height=79)
  38. self._running_img = self._load_image(image_repository.running_icon, 79)
  39. self._check_mark = self._load_image(image_repository.success_icon, height=75)
  40. self._error_symbol = self._load_image(image_repository.error_icon, height=75)
  41. def _do_layout(self):
  42. vsizer = wx.BoxSizer(wx.VERTICAL)
  43. sizer = wx.BoxSizer(wx.HORIZONTAL)
  44. headings_sizer = self.build_heading_sizer()
  45. sizer.Add(headings_sizer, 1, wx.ALIGN_LEFT | wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND | wx.LEFT, PAD_SIZE)
  46. sizer.Add(self._settings_img, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
  47. sizer.Add(self._running_img, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
  48. sizer.Add(self._check_mark, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
  49. sizer.Add(self._error_symbol, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
  50. self._running_img.Hide()
  51. self._check_mark.Hide()
  52. self._error_symbol.Hide()
  53. vsizer.Add(sizer, 1, wx.EXPAND)
  54. self.SetSizer(vsizer)
  55. def _load_image(self, img_path, height=70):
  56. return imageutil.resize_bitmap(self, imageutil._load_image(img_path), height)
  57. def build_heading_sizer(self):
  58. sizer = wx.BoxSizer(wx.VERTICAL)
  59. sizer.AddStretchSpacer(1)
  60. sizer.Add(self._header, 0)
  61. sizer.Add(self._subheader, 0)
  62. sizer.AddStretchSpacer(1)
  63. return sizer
  64. def RegisterController(self, controller):
  65. if self._controller is None:
  66. self._controller = controller
  67. def _init_pages(self):
  68. def config():
  69. self._header.SetLabel(self.heading_msg)
  70. self._subheader.SetLabel(self.subheading_msg)
  71. self._settings_img.Show()
  72. self._check_mark.Hide()
  73. self._running_img.Hide()
  74. self._error_symbol.Hide()
  75. self.Layout()
  76. def running():
  77. self._header.SetLabel(i18n._("running_title"))
  78. self._subheader.SetLabel(i18n._('running_msg'))
  79. self._check_mark.Hide()
  80. self._settings_img.Hide()
  81. self._running_img.Show()
  82. self._error_symbol.Hide()
  83. self.Layout()
  84. def success():
  85. self._header.SetLabel(i18n._('finished_title'))
  86. self._subheader.SetLabel(i18n._('finished_msg'))
  87. self._running_img.Hide()
  88. self._check_mark.Show()
  89. self.Layout()
  90. def error():
  91. self._header.SetLabel(i18n._('finished_title'))
  92. self._subheader.SetLabel(i18n._('finished_error'))
  93. self._running_img.Hide()
  94. self._error_symbol.Show()
  95. self.Layout()
  96. self.layouts = locals()
  97. def load_view(self, view_name=None):
  98. self.layouts.get(view_name, lambda: None)()