

print('at some point Alt+f4 while on frame b')
print('then on frame a click reshow to reopen it')
print('try alt+f4 on other frames to see what happens')

import wx
#from wx.lib.mixins.inspection import InspectableApp

SIZER_FLAGS = wx.SizerFlags(1).Expand().Border(0)

def OnButton(event):
	global frameB

	'''An event handler for wx.EVT_BUTTON; a callback.
	Acts as a window manager. In this example we bind
	to the wx.App object to the wx.EVT_BUTTON event.
	'''

	#event.Skip() # pass to parent widget or wx.App
	obj = event.GetEventObject()
	name = (None if not hasattr(obj,'GetName') else obj.GetName())
	#print('OnButton({})'.format(name))

	if name == 'Exit':
		print('SHAZAM!')
		quit()

	elif name == 'Switch to A':
		if frameA:
			frameA.SetFocus()
		else:
			obj.Disable()
	elif name == 'Switch to B':
		if frameB:
			frameB.SetFocus()
		else:
			obj.Disable()
	elif name == 'Reshow B':
		if frameB:
			frameB.SetFocus()
		else:
			frameB = create_frameB()
			frameB.SetFocus()
	elif name == 'Switch to C':
		if frameC:
			frameC.SetFocus()
		else:
			obj.Disable()
	else:
		'''Unnamed button. Ignoring here so button event 
		should be handled elsewhere.'''
		event.Skip()


def add_button(parent, label):
	return wx.Button(parent, label=label, name=label)


def create_frame(title):
	'''Allow the first top frame to "Rule them all."'''
	parent = (wx.GetTopLevelWindows()[0] if wx.GetTopLevelWindows() else None)
	if parent:
		#size = parent.GetSize()
		size = (320, 240)
		pos = parent.GetPosition()
	else:
		#size = wx.DefaultSize
		size = (320, 240)
		pos = wx.DefaultPosition
	frame = wx.Frame(parent, title=title, name=title, 
		style=0, size=size, pos=pos)
	return frame


def create_frameA(title='Frame A'):
	frame = create_frame(title)

	bSwitchToB = add_button(frame, 'Switch to B')
	bReshowB = add_button(frame, 'Reshow B')
	bSwitchToC = add_button(frame, 'Switch to C')
	bExit = add_button(frame, 'Exit')
	st = wx.StaticText(frame, label='Your widgets here', 
		size=(280,200), name='Wigettize',
		style= wx.ALIGN_CENTRE_HORIZONTAL | wx.ST_NO_AUTORESIZE | wx.ALIGN_CENTRE_VERTICAL)

	frame.Bind(wx.EVT_BUTTON, OnButton, bSwitchToB)
	frame.Bind(wx.EVT_BUTTON, OnButton, bReshowB)
	frame.Bind(wx.EVT_BUTTON, OnButton, bSwitchToC)
	frame.Bind(wx.EVT_BUTTON, quit, bExit)

	sizer = wx.BoxSizer(wx.VERTICAL)

	sizer.Add(bSwitchToB, SIZER_FLAGS)
	sizer.Add(bReshowB, SIZER_FLAGS)
	sizer.Add(bSwitchToC, SIZER_FLAGS)
	sizer.Add(bExit, SIZER_FLAGS)
	sizer.Add(st, SIZER_FLAGS)

	frame.SetSizer(sizer)
	frame.Layout()
	frame.Show()

	return frame


def create_frameB(title='Frame B'):
	frame = create_frame(title)

	bSwitchToA = add_button(frame, 'Switch to A')
	bSwitchToC = add_button(frame, 'Switch to C')

	frame.Bind(wx.EVT_BUTTON, OnButton, bSwitchToA)
	frame.Bind(wx.EVT_BUTTON, OnButton, bSwitchToC)

	sizer = wx.BoxSizer(wx.VERTICAL)

	sizer.Add(bSwitchToA, SIZER_FLAGS)
	sizer.Add(bSwitchToC, SIZER_FLAGS)

	frame.SetSizer(sizer)
	frame.Layout()
	frame.Show()
	return frame


def create_frameC(title='Frame C'):
	frame = create_frame(title)

	bSwitchToA = add_button(frame, 'Switch to A')
	bSwitchToB = add_button(frame, 'Switch to B')
	bExit = add_button(frame, 'Exit')

	frame.Bind(wx.EVT_BUTTON, OnButton)

	sizer = wx.BoxSizer(wx.HORIZONTAL)

	sizer.Add(bSwitchToA, SIZER_FLAGS)
	sizer.Add(bSwitchToB, SIZER_FLAGS)
	sizer.Add( bExit, SIZER_FLAGS )

	frame.SetSizer(sizer)
	frame.Layout()
	frame.Show()

	return frame


if __name__ == "__main__":
	app = wx.App()
	frameA = create_frameA()
	frameB = create_frameB()
	frameC = create_frameC()
	app.MainLoop()
