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.

135 lines
4.6 KiB

  1. import sys
  2. import wx
  3. from gooey.gui import events
  4. from gooey.gui.lang.i18n import _
  5. from gooey.gui.pubsub import pub
  6. class Footer(wx.Panel):
  7. '''
  8. Footer section used on the configuration
  9. screen of the application
  10. '''
  11. def __init__(self, parent, buildSpec, **kwargs):
  12. wx.Panel.__init__(self, parent, **kwargs)
  13. self.buildSpec = buildSpec
  14. self.SetMinSize((30, 53))
  15. # components
  16. self.cancel_button = None
  17. self.start_button = None
  18. self.progress_bar = None
  19. self.close_button = None
  20. self.stop_button = None
  21. self.restart_button = None
  22. self.edit_button = None
  23. self.buttons = []
  24. self.layouts = {}
  25. self._init_components()
  26. self._do_layout()
  27. for button in self.buttons:
  28. self.Bind(wx.EVT_BUTTON, self.dispatch_click, button)
  29. def updateProgressBar(self, *args, **kwargs):
  30. '''
  31. value, disable_animation=False
  32. :param args:
  33. :param kwargs:
  34. :return:
  35. '''
  36. value = kwargs.get('progress')
  37. pb = self.progress_bar
  38. if value is None:
  39. return
  40. if value < 0:
  41. pb.Pulse()
  42. else:
  43. value = min(int(value), pb.GetRange())
  44. if pb.GetValue() != value:
  45. # Windows 7 progress bar animation hack
  46. # http://stackoverflow.com/questions/5332616/disabling-net-progressbar-animation-when-changing-value
  47. if self.buildSpec['disable_progress_bar_animation'] \
  48. and sys.platform.startswith("win"):
  49. if pb.GetRange() == value:
  50. pb.SetValue(value)
  51. pb.SetValue(value - 1)
  52. else:
  53. pb.SetValue(value + 1)
  54. pb.SetValue(value)
  55. def showButtons(self, *buttonsToShow):
  56. for button in self.buttons:
  57. button.Show(False)
  58. for button in buttonsToShow:
  59. getattr(self, button).Show(True)
  60. self.Layout()
  61. def _init_components(self):
  62. self.cancel_button = self.button(_('cancel'), wx.ID_CANCEL, event_id=events.WINDOW_CANCEL)
  63. self.stop_button = self.button(_('stop'), wx.ID_OK, event_id=events.WINDOW_STOP)
  64. self.start_button = self.button(_('start'), wx.ID_OK, event_id=int(events.WINDOW_START))
  65. self.close_button = self.button(_("close"), wx.ID_OK, event_id=int(events.WINDOW_CLOSE))
  66. self.restart_button = self.button(_('restart'), wx.ID_OK, event_id=int(events.WINDOW_RESTART))
  67. self.edit_button = self.button(_('edit'), wx.ID_OK, event_id=int(events.WINDOW_EDIT))
  68. self.progress_bar = wx.Gauge(self, range=100)
  69. self.buttons = [self.cancel_button, self.start_button,
  70. self.stop_button, self.close_button,
  71. self.restart_button, self.edit_button]
  72. if self.buildSpec['disable_stop_button']:
  73. self.stop_button.Enable(False)
  74. def _do_layout(self):
  75. self.SetBackgroundColour(self.buildSpec['footer_bg_color'])
  76. self.stop_button.Hide()
  77. self.restart_button.Hide()
  78. v_sizer = wx.BoxSizer(wx.VERTICAL)
  79. h_sizer = wx.BoxSizer(wx.HORIZONTAL)
  80. h_sizer.Add(self.progress_bar, 1,
  81. wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 20)
  82. self.progress_bar.Hide()
  83. h_sizer.AddStretchSpacer(1)
  84. h_sizer.Add(self.cancel_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  85. h_sizer.Add(self.start_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  86. h_sizer.Add(self.stop_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  87. v_sizer.AddStretchSpacer(1)
  88. v_sizer.Add(h_sizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  89. h_sizer.Add(self.edit_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
  90. h_sizer.Add(self.restart_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
  91. h_sizer.Add(self.close_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  92. self.edit_button.Hide()
  93. self.restart_button.Hide()
  94. self.close_button.Hide()
  95. v_sizer.AddStretchSpacer(1)
  96. self.SetSizer(v_sizer)
  97. def button(self, label=None, style=None, event_id=-1):
  98. return wx.Button(
  99. parent=self,
  100. id=event_id,
  101. size=(90, -1),
  102. label=label,
  103. style=style)
  104. def dispatch_click(self, event):
  105. pub.send_message(event.GetId())
  106. def hide_all_buttons(self):
  107. for button in self.buttons:
  108. button.Hide()