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.

101 lines
3.3 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. PAD_SIZE = 10
  11. class FrameHeader(wx.Panel):
  12. def __init__(self, parent, buildSpec, **kwargs):
  13. wx.Panel.__init__(self, parent, **kwargs)
  14. self.SetDoubleBuffered(True)
  15. self.buildSpec = buildSpec
  16. self._header = None
  17. self._subheader = None
  18. self.settings_img = None
  19. self.running_img = None
  20. self.check_mark = None
  21. self.error_symbol = None
  22. self.images = []
  23. self.layoutComponent()
  24. def setTitle(self, title):
  25. self._header.SetLabel(title)
  26. def setSubtitle(self, subtitle):
  27. self._subheader.SetLabel(subtitle)
  28. def setImage(self, image):
  29. for img in self.images:
  30. img.Show(False)
  31. getattr(self, image).Show(True)
  32. self.Layout()
  33. def layoutComponent(self):
  34. self.SetBackgroundColour(self.buildSpec['header_bg_color'])
  35. self.SetSize((30, self.buildSpec['header_height']))
  36. self.SetMinSize((120, self.buildSpec['header_height']))
  37. self._header = wx_util.h1(self, label=self.buildSpec['program_name'])
  38. self._subheader = wx.StaticText(self, label=self.buildSpec['program_description'])
  39. images = self.buildSpec['images']
  40. targetHeight = self.buildSpec['header_height'] - 10
  41. self.settings_img = self._load_image(images['configIcon'], targetHeight)
  42. self.running_img = self._load_image(images['runningIcon'], targetHeight)
  43. self.check_mark = self._load_image(images['successIcon'], targetHeight)
  44. self.error_symbol = self._load_image(images['errorIcon'], targetHeight)
  45. self.images = [
  46. self.settings_img,
  47. self.running_img,
  48. self.check_mark,
  49. self.error_symbol
  50. ]
  51. vsizer = wx.BoxSizer(wx.VERTICAL)
  52. sizer = wx.BoxSizer(wx.HORIZONTAL)
  53. headings_sizer = self.build_heading_sizer()
  54. sizer.Add(headings_sizer, 1,
  55. wx.ALIGN_LEFT | wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND | wx.LEFT,
  56. PAD_SIZE)
  57. sizer.Add(self.settings_img, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
  58. sizer.Add(self.running_img, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
  59. sizer.Add(self.check_mark, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
  60. sizer.Add(self.error_symbol, 0, wx.ALIGN_RIGHT | wx.EXPAND | wx.RIGHT, PAD_SIZE)
  61. self.running_img.Hide()
  62. self.check_mark.Hide()
  63. self.error_symbol.Hide()
  64. vsizer.Add(sizer, 1, wx.EXPAND)
  65. self.SetSizer(vsizer)
  66. def _load_image(self, imgPath, targetHeight):
  67. rawImage = imageutil.loadImage(imgPath)
  68. sizedImage = imageutil.resizeImage(rawImage, targetHeight)
  69. return imageutil.wrapBitmap(sizedImage, self)
  70. def build_heading_sizer(self):
  71. sizer = wx.BoxSizer(wx.VERTICAL)
  72. sizer.AddStretchSpacer(1)
  73. sizer.Add(self._header, 0)
  74. sizer.Add(self._subheader, 0)
  75. sizer.AddStretchSpacer(1)
  76. return sizer