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
4.6 KiB

  1. import sys
  2. import wx
  3. from gooey.gui import events
  4. from gooey.gui.lang import i18n
  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(i18n._('cancel'), wx.ID_CANCEL, event_id=events.WINDOW_CANCEL)
  63. self.stop_button = self.button(i18n._('stop'), wx.ID_OK, event_id=events.WINDOW_STOP)
  64. self.start_button = self.button(i18n._('start'), wx.ID_OK, event_id=int(events.WINDOW_START))
  65. self.close_button = self.button(i18n._("close"), wx.ID_OK, event_id=int(events.WINDOW_CLOSE))
  66. self.restart_button = self.button(i18n._('restart'), wx.ID_OK, event_id=int(events.WINDOW_RESTART))
  67. self.edit_button = self.button(i18n._('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.stop_button.Hide()
  76. self.restart_button.Hide()
  77. v_sizer = wx.BoxSizer(wx.VERTICAL)
  78. h_sizer = wx.BoxSizer(wx.HORIZONTAL)
  79. h_sizer.Add(self.progress_bar, 1,
  80. wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 20)
  81. self.progress_bar.Hide()
  82. h_sizer.AddStretchSpacer(1)
  83. h_sizer.Add(self.cancel_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  84. h_sizer.Add(self.start_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  85. h_sizer.Add(self.stop_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  86. v_sizer.AddStretchSpacer(1)
  87. v_sizer.Add(h_sizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
  88. h_sizer.Add(self.edit_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
  89. h_sizer.Add(self.restart_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)
  90. h_sizer.Add(self.close_button, 0, wx.ALIGN_RIGHT | wx.RIGHT, 20)
  91. self.edit_button.Hide()
  92. self.restart_button.Hide()
  93. self.close_button.Hide()
  94. v_sizer.AddStretchSpacer(1)
  95. self.SetSizer(v_sizer)
  96. def button(self, label=None, style=None, event_id=-1):
  97. return wx.Button(
  98. parent=self,
  99. id=event_id,
  100. size=(90, 24),
  101. label=i18n._(label),
  102. style=style)
  103. def dispatch_click(self, event):
  104. pub.send_message(event.GetId())
  105. def hide_all_buttons(self):
  106. for button in self.buttons:
  107. button.Hide()