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.

155 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.gui.pubsub import pub
  8. from gooey.gui.lang import i18n
  9. from gooey.gui import imageutil, image_repository, events
  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.buttons = None
  26. self.layouts = {}
  27. self._init_components()
  28. self._init_pages()
  29. self._do_layout()
  30. pub.subscribe(self.load_view, events.WINDOW_CHANGE)
  31. def _init_components(self):
  32. self.cancel_button = self.button(i18n._('cancel'), wx.ID_CANCEL, event_id=int(events.WINDOW_CANCEL))
  33. self.stop_button = self.button(i18n._('stop'), wx.ID_OK, event_id=int(events.WINDOW_STOP))
  34. self.start_button = self.button(i18n._('start'), wx.ID_OK, event_id=int(events.WINDOW_START))
  35. self.close_button = self.button(i18n._("close"), wx.ID_OK, event_id=int(events.WINDOW_CLOSE))
  36. self.restart_button = self.button(i18n._('restart'), wx.ID_OK, event_id=int(events.WINDOW_RESTART))
  37. self.edit_button = self.button(i18n._('edit'), wx.ID_OK, event_id=int(events.WINDOW_EDIT))
  38. self.running_animation = wx.animate.GIFAnimationCtrl(self, -1, image_repository.loader)
  39. self.buttons = [self.cancel_button, self.start_button, self.stop_button, self.close_button, self.restart_button, self.edit_button]
  40. def _init_pages(self):
  41. def config():
  42. self.hide_all_buttons()
  43. self.cancel_button.Show()
  44. self.start_button.Show()
  45. self.running_animation.Stop()
  46. self.Layout()
  47. def running():
  48. self.hide_all_buttons()
  49. self.running_animation.Show()
  50. self.running_animation.Play()
  51. self.Layout()
  52. def success():
  53. self.hide_all_buttons()
  54. self.running_animation.Stop()
  55. self.running_animation.Hide()
  56. self.edit_button.Show()
  57. self.restart_button.Show()
  58. self.close_button.Show()
  59. self.Layout()
  60. def error():
  61. success()
  62. self.layouts = locals()
  63. def load_view(self, view_name=None):
  64. self.layouts.get(view_name, lambda: None)()
  65. def hide_all_buttons(self):
  66. for button in self.buttons:
  67. button.Hide()
  68. def _do_layout(self):
  69. self.stop_button.Hide()
  70. self.restart_button.Hide()
  71. v_sizer = wx.BoxSizer(wx.VERTICAL)
  72. h_sizer = wx.BoxSizer(wx.HORIZONTAL)
  73. h_sizer.AddStretchSpacer(1)
  74. h_sizer.Add(self.cancel_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  75. h_sizer.Add(self.start_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  76. v_sizer.AddStretchSpacer(1)
  77. v_sizer.Add(h_sizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  78. v_sizer.Add(self.running_animation, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.RIGHT, 20)
  79. self.running_animation.Hide()
  80. h_sizer.Add(self.edit_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
  81. h_sizer.Add(self.restart_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
  82. h_sizer.Add(self.close_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  83. self.edit_button.Hide()
  84. self.restart_button.Hide()
  85. self.close_button.Hide()
  86. v_sizer.AddStretchSpacer(1)
  87. self.SetSizer(v_sizer)
  88. def button(self, label=None, style=None, event_id=-1):
  89. return wx.Button(
  90. parent=self,
  91. id=event_id,
  92. size=(90, 24),
  93. label=label,
  94. style=style)
  95. def RegisterController(self, controller):
  96. if self._controller is None:
  97. self._controller = controller
  98. def _load_image(self, img_path, height=70):
  99. return imageutil.resize_bitmap(self, imageutil._load_image(img_path), height)
  100. class Footer(AbstractFooter):
  101. '''
  102. Footer section used on the configuration
  103. screen of the application
  104. args:
  105. parent: wxPython parent windows
  106. controller: controller class used in delagating all the commands
  107. '''
  108. def __init__(self, parent, **kwargs):
  109. AbstractFooter.__init__(self, parent, **kwargs)
  110. for button in self.buttons:
  111. print button.GetId()
  112. self.Bind(wx.EVT_BUTTON, self.dispatch_click, button)
  113. def dispatch_click(self, event):
  114. pub.send_message(str(event.GetId()))
  115. event.Skip()