Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import wx.combo
- class CustomPopup(wx.combo.ComboPopup):
- def Create(self, parent):
- # Create the popup with a bunch of radiobuttons
- self.panel = wx.Panel(parent)
- sizer = wx.GridSizer(cols=2)
- for x in range(10):
- r = wx.RadioButton(self.panel, label="Element "+str(x))
- r.Bind(wx.EVT_RADIOBUTTON, self.on_selection)
- sizer.Add(r)
- self.panel.SetSizer(sizer)
- # Handle keyevents
- self.panel.Bind(wx.EVT_KEY_UP, self.on_key)
- def GetControl(self):
- return self.panel
- def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
- return wx.Size(200, 150)
- def on_key(self, evt):
- if evt.GetEventObject() is self.panel:
- # Trying to redirect the key event to the combo.. But this always returns false :(
- print self.GetCombo().GetTextCtrl().GetEventHandler().ProcessEvent(evt)
- evt.Skip()
- def on_selection(self, evt):
- self.Dismiss()
- wx.MessageBox("Selection made")
- class CustomFrame(wx.Frame):
- def __init__(self):
- # Toolbar-shaped frame with a ComboCtrl
- wx.Frame.__init__(self, None, -1, "Test", size=(800,50))
- combo = wx.combo.ComboCtrl(self)
- popup = CustomPopup()
- combo.SetPopupControl(popup)
- sizer = wx.BoxSizer(wx.VERTICAL)
- sizer.Add(combo, 0)
- self.SetSizer(sizer)
- self.Layout()
- if __name__ == '__main__':
- app = wx.PySimpleApp()
- CustomFrame().Show()
- app.MainLoop()
Add Comment
Please, Sign In to add comment