| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 
 | import wx import wx.adv
 from sys import modules
 from functools import singledispatch, update_wrapper, partial
 
 def methdispatch(func):
 dispatcher = singledispatch(func)
 def wrapper(_args, **kw):
 return dispatcher.dispatch(args[1].**class**)(_args, **kw)
 wrapper.register = dispatcher.register
 update_wrapper(wrapper, func)
 return wrapper
 
 thisModule = modules[__name__]
 
 setattr(thisModule, 'v1_20', type('v1_20', (object,), {}))
 setattr(thisModule, 'v1_30', type('v1_30', (object,), {}))
 setattr(thisModule, 'v1_40', type('v1_40', (object,), {}))
 setattr(thisModule, 'v1_50', type('v1_50', (object,), {}))
 setattr(thisModule, 'v1_60', type('v1_60', (object,), {}))
 
 
 class ClassDialog(wx.Dialog):
 
 def __init__(self, parent, title="Test Demo", size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE, strVersion="v1_20", name="TestDemo"):
 """
 strVersion, format v1_20
 """
 wx.Dialog.__init__(self, parent, wx.ID_ANY, title,
 size=size,
 pos=pos,
 style=style,
 name=name)
 try:
 self.objVersion = eval(strVersion)()
 except:
 self.objVersion = None
 self.CreateWidgets(self.objVersion)
 
 @methdispatch
 def CreateWidgets(self, objVersion):
 self.panel = wx.Panel(self)
 vBoxSizer = wx.BoxSizer(wx.VERTICAL)
 self.quote = wx.StaticText(self.panel, label="Your quote: Default ", pos=(20, 30))
 vBoxSizer.Add(self.quote, 5)
 self.btn = wx.Button(self.panel, wx.ID_ANY, size=wx.DefaultSize, label="Test")
 vBoxSizer.Add(self.btn, 1)
 self.panel.SetSizer(vBoxSizer)
 self.btn.Bind(wx.EVT_BUTTON, partial(self.OnButtonClicked, self.objVersion))
 
 @CreateWidgets.register(v1_20)
 def _(self, objVersion):
 self.panel = wx.Panel(self)
 vBoxSizer = wx.BoxSizer(wx.VERTICAL)
 self.quote = wx.StaticText(self.panel, label="Your quote: 1.20 ", pos=(20, 30))
 vBoxSizer.Add(self.quote, 5)
 self.btn = wx.Button(self.panel, wx.ID_ANY, size=wx.DefaultSize, label="Test")
 vBoxSizer.Add(self.btn, 1)
 self.panel.SetSizer(vBoxSizer)
 self.btn.Bind(wx.EVT_BUTTON, partial(self.OnButtonClicked, self.objVersion))
 
 @CreateWidgets.register(v1_30)
 def _(self, objVersion):
 self.panel = wx.Panel(self)
 vBoxSizer = wx.BoxSizer(wx.VERTICAL)
 self.quote = wx.StaticText(self.panel, label="Your quote: 1.30 ", pos=(20, 30))
 vBoxSizer.Add(self.quote, 5)
 self.btn = wx.Button(self.panel, wx.ID_ANY, size=wx.DefaultSize, label="Test")
 vBoxSizer.Add(self.btn, 1)
 self.panel.SetSizer(vBoxSizer)
 self.btn.Bind(wx.EVT_BUTTON, partial(self.OnButtonClicked, self.objVersion))
 
 @methdispatch
 def OnButtonClicked(self, objVersion, event):
 print("aaaaa")
 
 @OnButtonClicked.register(v1_20)
 def _(self, objVersion, event):
 print(event.EventObject.Name)
 print("bbbbb")
 
 
 class SubClassDialog(ClassDialog):
 def __init__(self, parent, title="Test Demo", size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE, strVersion="v1_20", name="TestDemo"):
 """
 strVersion, format v1_20
 """
 ClassDialog.__init__(self, parent, title=title, size=size, pos=pos, style=style, strVersion=strVersion, name=name)
 
 @ClassDialog.CreateWidgets.register(v1_40)
 def _(self, objVersion):
 print("1.40")
 
 @ClassDialog.CreateWidgets.register(v1_50)
 def _(self, objVersion):
 print("1.50")
 
 class MyFrame(wx.Frame):
 """ We simply derive a new class of Frame. """
 def __init__(self, parent, title):
 wx.Frame.__init__(self, parent, title=title, size=(200,100))
 dlg=SubClassDialog(self, strVersion="v1_x0")
 res = dlg.ShowModal()
 
 
 def main():
 app = wx.App(False)
 frame = MyFrame(None, 'Small editor')
 app.MainLoop()
 
 if __name__ == '__main__':
 main()
 
 
 |