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.

45 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. super(Sidebar, self).__init__(parent, *args, **kwargs)
  8. self.SetDoubleBuffered(True)
  9. self._parent = parent
  10. self._do_layout()
  11. def _do_layout(self):
  12. self.SetDoubleBuffered(True)
  13. self.SetBackgroundColour('#f2f2f2')
  14. self.SetSize((180, 0))
  15. self.SetMinSize((180, 0))
  16. STD_LAYOUT = (0, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
  17. container = wx.BoxSizer(wx.VERTICAL)
  18. container.AddSpacer(15)
  19. container.Add(wx_util.h1(self, 'Actions'), *STD_LAYOUT)
  20. container.AddSpacer(5)
  21. self.listbox = wx.ListBox(self, -1)
  22. container.Add(self.listbox, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)
  23. container.AddSpacer(20)
  24. self.SetSizer(container)
  25. self.Bind(wx.EVT_LISTBOX, self.selection_change, self.listbox)
  26. def set_list_contents(self, contents):
  27. self.listbox.AppendItems(contents)
  28. self.listbox.SetSelection(0)
  29. def selection_change(self, evt):
  30. pub.send_message(
  31. events.LIST_BOX,
  32. selection=self.listbox.GetItems()[self.listbox.GetSelection()])
  33. evt.Skip()