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.

125 lines
4.0 KiB

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