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.

47 lines
1.2 KiB

  1. import wx
  2. from gooey.gui.pubsub import pub
  3. from gooey.gui import events
  4. from gooey.gui.util import wx_util
  5. class Sidebar(wx.Panel):
  6. def __init__(self, parent, *args, **kwargs):
  7. self.contents = kwargs.pop('contents', [])
  8. super(Sidebar, self).__init__(parent, *args, **kwargs)
  9. self.SetDoubleBuffered(True)
  10. self._parent = parent
  11. self._controller = None
  12. self._init_components()
  13. self._do_layout()
  14. def _init_components(self):
  15. pass
  16. def _do_layout(self):
  17. self.SetDoubleBuffered(True)
  18. self.SetBackgroundColour('#f2f2f2')
  19. self.SetSize((180, 0))
  20. self.SetMinSize((180, 0))
  21. STD_LAYOUT = (0, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
  22. container = wx.BoxSizer(wx.VERTICAL)
  23. container.AddSpacer(15)
  24. container.Add(wx_util.h1(self, 'Actions'), *STD_LAYOUT)
  25. container.AddSpacer(5)
  26. thing = wx.ListBox(self, -1, choices=self.contents)
  27. container.Add(thing, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
  28. container.AddSpacer(20)
  29. self.SetSizer(container)
  30. thing.SetSelection(0)
  31. self.Bind(wx.EVT_LISTBOX, self.onClick, thing)
  32. def onClick(self, evt):
  33. pub.send_message(events.PANEL_CHANGE, view_name=evt.GetString())
  34. evt.Skip()