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.

134 lines
3.6 KiB

  1. '''
  2. Created on Dec 23, 2013
  3. @author: Chris
  4. '''
  5. import wx
  6. import wx.animate
  7. from gooey import i18n
  8. from gooey.gui import imageutil
  9. from gooey import image_repository
  10. class AbstractFooter(wx.Panel):
  11. '''
  12. Abstract class for the Footer panels.
  13. '''
  14. def __init__(self, parent, **kwargs):
  15. wx.Panel.__init__(self, parent, **kwargs)
  16. self.SetMinSize((30, 53))
  17. self._controller = None
  18. # components
  19. self.cancel_button = None
  20. self.start_button = None
  21. self.running_animation = None
  22. self.close_button = None
  23. self._init_components()
  24. self._init_pages()
  25. self._do_layout()
  26. def _init_components(self):
  27. '''
  28. initialize all of the gui used in the footer
  29. TODO:
  30. Add Checkmark image for when the program has finished running.
  31. Refactor image tools into their own module. The resize code is
  32. getting spread around a bit.
  33. '''
  34. self.cancel_button = self._Button(i18n.translate('cancel'), wx.ID_CANCEL)
  35. self.start_button = self._Button(i18n.translate('start'), wx.ID_OK)
  36. self.running_animation = wx.animate.GIFAnimationCtrl(self, -1, image_repository.loader)
  37. self.close_button = self._Button(i18n.translate("close"), wx.ID_OK)
  38. def _init_pages(self):
  39. def PageOne():
  40. self.cancel_button.Hide()
  41. self.start_button.Hide()
  42. self.running_animation.Show()
  43. self.running_animation.Play()
  44. self.Layout()
  45. def PageTwo():
  46. self.running_animation.Stop()
  47. self.running_animation.Hide()
  48. self.close_button.Show()
  49. self.Layout()
  50. self._pages = iter([PageOne, PageTwo])
  51. def _do_layout(self):
  52. v_sizer = wx.BoxSizer(wx.VERTICAL)
  53. h_sizer = wx.BoxSizer(wx.HORIZONTAL)
  54. h_sizer.AddStretchSpacer(1)
  55. h_sizer.Add(self.cancel_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  56. h_sizer.Add(self.start_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  57. v_sizer.AddStretchSpacer(1)
  58. v_sizer.Add(h_sizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  59. v_sizer.Add(self.running_animation, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20)
  60. self.running_animation.Hide()
  61. v_sizer.Add(self.close_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20)
  62. self.close_button.Hide()
  63. v_sizer.AddStretchSpacer(1)
  64. self.SetSizer(v_sizer)
  65. def _Button(self, label=None, style=None):
  66. return wx.Button(
  67. parent=self,
  68. id=-1,
  69. size=(90, 24),
  70. label=label,
  71. style=style)
  72. def RegisterController(self, controller):
  73. if self._controller is None:
  74. self._controller = controller
  75. def NextPage(self):
  76. next(self._pages)()
  77. def _load_image(self, img_path, height=70):
  78. return imageutil.resize_bitmap(
  79. self,
  80. imageutil._load_image(img_path),
  81. height)
  82. class Footer(AbstractFooter):
  83. '''
  84. Footer section used on the configuration
  85. screen of the application
  86. args:
  87. parent: wxPython parent window
  88. controller: controller class used in delagating all the commands
  89. '''
  90. def __init__(self, parent, controller, **kwargs):
  91. AbstractFooter.__init__(self, parent, **kwargs)
  92. self.Bind(wx.EVT_BUTTON, self.OnCancelButton, self.cancel_button)
  93. self.Bind(wx.EVT_BUTTON, self.OnStartButton, self.start_button)
  94. self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.close_button)
  95. def OnCancelButton(self, event):
  96. self._controller.OnCancelButton(self, event)
  97. event.Skip()
  98. def OnCloseButton(self, event):
  99. self._controller.OnCloseButton(self, event)
  100. event.Skip()
  101. def OnStartButton(self, event):
  102. self._controller.OnStartButton(event, self)
  103. event.Skip()