#!/usr/bin/env python

import wx

ID_BUTTON = wx.NewId()
ID_RADIOBUTTON1 = wx.NewId()
ID_RADIOBUTTON2 = wx.NewId()

class MyFrame(wx.Frame):
	def __init__(self, parent=None, id=-1,
		title='My Frame', 
		pos=(-1, -1), 
		size=(-1, -1), 
		style=wx.DEFAULT_FRAME_STYLE):
		wx.Frame.__init__(self, parent, id, title, pos, size, style)

		self.frameSizer = wx.BoxSizer(wx.VERTICAL)
		self.framePanel = MyPanel(self)
		self.frameSizer.Add(self.framePanel, 0, wx.ALIGN_CENTER|wx.ALL, 0)
		self.SetSizerAndFit(self.frameSizer)

class MyPanel(wx.Panel):
	def __init__(self, parent):
		wx.Panel.__init__(self, parent, -1,
			pos = (-1, -1),
			size = (-1, -1))

		self.topSizer = wx.BoxSizer(wx.VERTICAL)
		
		self.button = wx.Button(self, ID_BUTTON, 'A &Button', (-1,-1), (-1,-1))
		self.button.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
		self.topSizer.Add(self.button, 0, wx.ALIGN_CENTER|wx.ALL, 10)

		self.radioButton1 = wx.RadioButton(self, ID_RADIOBUTTON1, '&Radio Button 1', (-1,-1), (-1,-1))
		self.radioButton1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
		self.topSizer.Add(self.radioButton1, 0, wx.ALIGN_CENTER|wx.ALL, 10)

		self.radioButton2 = wx.RadioButton(self, ID_RADIOBUTTON2, 'R&adio Button 2', (-1,-1), (-1,-1))
		self.radioButton2.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
		self.topSizer.Add(self.radioButton2, 0, wx.ALIGN_CENTER|wx.ALL, 10)

		self.SetSizer(self.topSizer)
		self.topSizer.SetSizeHints(self)

		# set button/radiobutton event handlers
		self.Bind(wx.EVT_BUTTON, self.onButton, id = ID_BUTTON)
		self.Bind(wx.EVT_RADIOBUTTON, self.onButton, id = ID_RADIOBUTTON1)
		self.Bind(wx.EVT_RADIOBUTTON, self.onButton, id = ID_RADIOBUTTON2)

		# set menu event handlers for accelerator keys
		self.Bind(wx.EVT_MENU, self.onButton, id = ID_BUTTON)
		self.Bind(wx.EVT_MENU, self.onButton, id = ID_RADIOBUTTON1)
		self.Bind(wx.EVT_MENU, self.onButton, id = ID_RADIOBUTTON2)

		# Create & set accelerator table
		table = wx.AcceleratorTable([
				(wx.ACCEL_ALT, ord('B'), ID_BUTTON),
				(wx.ACCEL_ALT, ord('R'), ID_RADIOBUTTON1),
				(wx.ACCEL_ALT, ord('A'), ID_RADIOBUTTON2)
				])
		self.SetAcceleratorTable(table) 

	def onButton(self, event):
		evtID = event.GetId()
		if evtID == ID_BUTTON:
			print 'got button event'
		elif evtID == ID_RADIOBUTTON1:
			print 'got radio button 1 event'
		elif evtID == ID_RADIOBUTTON2:
			print 'got radio button 2 event'

class MyApp(wx.App):
	def OnInit(self):
		self.frame = None
		return True

def main():
	app = MyApp(0)
	app.frame = MyFrame()
	app.SetTopWindow(app.frame)
	app.frame.Show(True)
	app.MainLoop()

if __name__ == '__main__':
	main()
