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.

119 lines
3.9 KiB

  1. '''
  2. Created on Dec 23, 2013
  3. @author: Chris
  4. '''
  5. import wx
  6. from gooey.gui import imageutil, image_repository
  7. from gooey.gui.util import wx_util
  8. from gooey.gui.three_to_four import bitmapFromImage
  9. from gooey.util.functional import getin
  10. from gooey.gui.components.mouse import notifyMouseEvent
  11. PAD_SIZE = 10
  12. class FrameHeader(wx.Panel):
  13. def __init__(self, parent, buildSpec, **kwargs):
  14. wx.Panel.__init__(self, parent, **kwargs)
  15. self.SetDoubleBuffered(True)
  16. self.buildSpec = buildSpec
  17. self._header = None
  18. self._subheader = None
  19. self.settings_img = None
  20. self.running_img = None
  21. self.check_mark = None
  22. self.error_symbol = None
  23. self.images = []
  24. self.layoutComponent()
  25. self.bindMouseEvents()
  26. def setTitle(self, title):
  27. self._header.SetLabel(title)
  28. def setSubtitle(self, subtitle):
  29. self._subheader.SetLabel(subtitle)
  30. def setImage(self, image):
  31. for img in self.images:
  32. img.Show(False)
  33. getattr(self, image).Show(True)
  34. self.Layout()
  35. def layoutComponent(self):
  36. self.SetBackgroundColour(self.buildSpec['header_bg_color'])
  37. self.SetSize((30, self.buildSpec['header_height']))
  38. self.SetMinSize((120, self.buildSpec['header_height']))
  39. self._header = wx_util.h1(self, label=self.buildSpec['program_name'])
  40. self._subheader = wx.StaticText(self, label=self.buildSpec['program_description'])
  41. images = self.buildSpec['images']
  42. targetHeight = self.buildSpec['header_height'] - 10
  43. self.settings_img = self._load_image(images['configIcon'], targetHeight)
  44. self.running_img = self._load_image(images['runningIcon'], targetHeight)
  45. self.check_mark = self._load_image(images['successIcon'], targetHeight)
  46. self.error_symbol = self._load_image(images['errorIcon'], targetHeight)
  47. self.images = [
  48. self.settings_img,
  49. self.running_img,
  50. self.check_mark,
  51. self.error_symbol
  52. ]
  53. vsizer = wx.BoxSizer(wx.VERTICAL)
  54. sizer = wx.BoxSizer(wx.HORIZONTAL)
  55. headings_sizer = self.build_heading_sizer()
  56. sizer.Add(headings_sizer, 1,
  57. wx.ALIGN_LEFT | wx.EXPAND | wx.LEFT,
  58. PAD_SIZE)
  59. sizer.Add(self.settings_img, 0, wx.EXPAND | wx.RIGHT, PAD_SIZE)
  60. sizer.Add(self.running_img, 0, wx.EXPAND | wx.RIGHT, PAD_SIZE)
  61. sizer.Add(self.check_mark, 0, wx.EXPAND | wx.RIGHT, PAD_SIZE)
  62. sizer.Add(self.error_symbol, 0, wx.EXPAND | wx.RIGHT, PAD_SIZE)
  63. self.running_img.Hide()
  64. self.check_mark.Hide()
  65. self.error_symbol.Hide()
  66. vsizer.Add(sizer, 1, wx.EXPAND)
  67. self.SetSizer(vsizer)
  68. def _load_image(self, imgPath, targetHeight):
  69. rawImage = imageutil.loadImage(imgPath)
  70. sizedImage = imageutil.resizeImage(rawImage, targetHeight)
  71. return imageutil.wrapBitmap(sizedImage, self)
  72. def build_heading_sizer(self):
  73. sizer = wx.BoxSizer(wx.VERTICAL)
  74. sizer.AddStretchSpacer(1)
  75. if self.buildSpec['header_show_title']:
  76. sizer.Add(self._header, 0)
  77. else:
  78. self._header.Hide()
  79. if self.buildSpec['header_show_subtitle']:
  80. sizer.Add(self._subheader, 0)
  81. else:
  82. self._subheader.Hide()
  83. sizer.AddStretchSpacer(1)
  84. return sizer
  85. def bindMouseEvents(self):
  86. """
  87. Manually binding all LEFT_DOWN events.
  88. See: gooey.gui.mouse for background.
  89. """
  90. self.Bind(wx.EVT_LEFT_DOWN, notifyMouseEvent)
  91. self._header.Bind(wx.EVT_LEFT_DOWN, notifyMouseEvent)
  92. self._subheader.Bind(wx.EVT_LEFT_DOWN, notifyMouseEvent)
  93. for image in self.images:
  94. image.Bind(wx.EVT_LEFT_DOWN, notifyMouseEvent)