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.

112 lines
3.3 KiB

8 years ago
  1. '''
  2. Created on Dec 23, 2013
  3. @author: Chris
  4. '''
  5. import wx
  6. from gooey.gui.pubsub import pub
  7. from gooey.gui.lang import i18n
  8. from gooey.gui import imageutil, events
  9. class Footer(wx.Panel):
  10. '''
  11. Footer section used on the configuration
  12. screen of the application
  13. args:
  14. parent: wxPython parent windows
  15. controller: controller class used in delagating all the commands
  16. '''
  17. def __init__(self, parent, **kwargs):
  18. wx.Panel.__init__(self, parent, **kwargs)
  19. self.SetMinSize((30, 53))
  20. # components
  21. self.cancel_button = None
  22. self.start_button = None
  23. self.progress_bar = None
  24. self.close_button = None
  25. self.stop_button = None
  26. self.restart_button = None
  27. self.buttons = None
  28. self.layouts = {}
  29. self._init_components()
  30. self._do_layout()
  31. for button in self.buttons:
  32. self.Bind(wx.EVT_BUTTON, self.dispatch_click, button)
  33. def _init_components(self):
  34. self.cancel_button = self.button(i18n._('cancel'), wx.ID_CANCEL, event_id=int(events.WINDOW_CANCEL))
  35. self.stop_button = self.button(i18n._('stop'), wx.ID_OK, event_id=int(events.WINDOW_STOP))
  36. self.start_button = self.button(i18n._('start'), wx.ID_OK, event_id=int(events.WINDOW_START))
  37. self.close_button = self.button(i18n._("close"), wx.ID_OK, event_id=int(events.WINDOW_CLOSE))
  38. self.restart_button = self.button(i18n._('restart'), wx.ID_OK, event_id=int(events.WINDOW_RESTART))
  39. self.edit_button = self.button(i18n._('edit'), wx.ID_OK, event_id=int(events.WINDOW_EDIT))
  40. self.progress_bar = wx.Gauge(self, range=100)
  41. self.buttons = [self.cancel_button, self.start_button,
  42. self.stop_button, self.close_button,
  43. self.restart_button, self.edit_button]
  44. def _do_layout(self):
  45. self.stop_button.Hide()
  46. self.restart_button.Hide()
  47. v_sizer = wx.BoxSizer(wx.VERTICAL)
  48. h_sizer = wx.BoxSizer(wx.HORIZONTAL)
  49. h_sizer.Add(self.progress_bar, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 20)
  50. self.progress_bar.Hide()
  51. h_sizer.AddStretchSpacer(1)
  52. h_sizer.Add(self.cancel_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  53. h_sizer.Add(self.start_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  54. h_sizer.Add(self.stop_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  55. v_sizer.AddStretchSpacer(1)
  56. v_sizer.Add(h_sizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  57. h_sizer.Add(self.edit_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
  58. h_sizer.Add(self.restart_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
  59. h_sizer.Add(self.close_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  60. self.edit_button.Hide()
  61. self.restart_button.Hide()
  62. self.close_button.Hide()
  63. v_sizer.AddStretchSpacer(1)
  64. self.SetSizer(v_sizer)
  65. def button(self, label=None, style=None, event_id=-1):
  66. return wx.Button(
  67. parent=self,
  68. id=event_id,
  69. size=(90, 24),
  70. label=label,
  71. style=style)
  72. def dispatch_click(self, event):
  73. pub.send_message(str(event.GetId()))
  74. event.Skip()
  75. def hide_all_buttons(self):
  76. for button in self.buttons:
  77. button.Hide()
  78. def _load_image(self, img_path, height=70):
  79. return imageutil.resize_bitmap(self, imageutil._load_image(img_path), height)