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.

158 lines
4.5 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.stop_button = None
  24. self.restart_button = None
  25. self._init_components()
  26. self._init_pages()
  27. self._do_layout()
  28. def _init_components(self):
  29. '''
  30. initialize all of the gui used in the footer
  31. TODO:
  32. Add Checkmark image for when the program has finished running.
  33. Refactor image tools into their own module. The resize code is
  34. getting spread around a bit.
  35. '''
  36. self.cancel_button = self._Button(i18n.translate('cancel'), wx.ID_CANCEL)
  37. self.start_button = self._Button(i18n.translate('start'), wx.ID_OK)
  38. self.running_animation = wx.animate.GIFAnimationCtrl(self, -1, image_repository.loader)
  39. self.close_button = self._Button(i18n.translate("close"), wx.ID_OK)
  40. self.stop_button = self._Button('Stop', wx.ID_OK) # TODO: i18n
  41. self.restart_button = self._Button('Restart', wx.ID_OK) # TODO: i18n
  42. def _init_pages(self):
  43. if self.restart_button.IsShown(): self.restart_button.Hide()
  44. if self.close_button.IsShown(): self.close_button.Hide()
  45. def PageOne():
  46. self.cancel_button.Hide()
  47. self.start_button.Hide()
  48. self.running_animation.Show()
  49. self.running_animation.Play()
  50. self.Layout()
  51. def PageTwo():
  52. self.running_animation.Stop()
  53. self.running_animation.Hide()
  54. self.restart_button.Show()
  55. self.close_button.Show()
  56. self.restart_button.Show()
  57. self.Layout()
  58. self._pages = iter([PageOne, PageTwo])
  59. def _do_layout(self):
  60. self.stop_button.Hide()
  61. self.restart_button.Hide()
  62. v_sizer = wx.BoxSizer(wx.VERTICAL)
  63. h_sizer = wx.BoxSizer(wx.HORIZONTAL)
  64. h_sizer.AddStretchSpacer(1)
  65. h_sizer.Add(self.cancel_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  66. h_sizer.Add(self.start_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  67. v_sizer.AddStretchSpacer(1)
  68. v_sizer.Add(h_sizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  69. v_sizer.Add(self.running_animation, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20)
  70. self.running_animation.Hide()
  71. v_sizer.Add(self.restart_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20)
  72. v_sizer.Add(self.close_button, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20)
  73. self.restart_button.Hide()
  74. self.close_button.Hide()
  75. v_sizer.AddStretchSpacer(1)
  76. self.SetSizer(v_sizer)
  77. def _Button(self, label=None, style=None):
  78. return wx.Button(
  79. parent=self,
  80. id=-1,
  81. size=(90, 24),
  82. label=label,
  83. style=style)
  84. def RegisterController(self, controller):
  85. if self._controller is None:
  86. self._controller = controller
  87. def NextPage(self):
  88. try:
  89. next(self._pages)()
  90. except:
  91. self._init_pages()
  92. next(self._pages)()
  93. def _load_image(self, img_path, height=70):
  94. return imageutil.resize_bitmap(
  95. self,
  96. imageutil._load_image(img_path),
  97. height)
  98. class Footer(AbstractFooter):
  99. '''
  100. Footer section used on the configuration
  101. screen of the application
  102. args:
  103. parent: wxPython parent window
  104. controller: controller class used in delagating all the commands
  105. '''
  106. def __init__(self, parent, controller, **kwargs):
  107. AbstractFooter.__init__(self, parent, **kwargs)
  108. self.Bind(wx.EVT_BUTTON, self.OnCancelButton, self.cancel_button)
  109. self.Bind(wx.EVT_BUTTON, self.OnStartButton, self.start_button)
  110. self.Bind(wx.EVT_BUTTON, self.OnCloseButton, self.close_button)
  111. self.Bind(wx.EVT_BUTTON, self.OnRestartButton, self.restart_button)
  112. def OnCancelButton(self, event):
  113. self._controller.OnCancelButton(self, event)
  114. event.Skip()
  115. def OnCloseButton(self, event):
  116. self._controller.OnCloseButton(self, event)
  117. event.Skip()
  118. def OnStartButton(self, event):
  119. self._controller.OnStartButton(event, self)
  120. event.Skip()
  121. def OnRestartButton(self, event):
  122. self._controller.OnStartButton(event, self)
  123. event.Skip()