1 2 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
| class Form (wx.Dialog):
def __init__(self,parent=None,object=None, conf=None):
self.object = object
self.conf = formConf.FormConfiguration(conf)
wx.Dialog.__init__(self,parent)
#self.SetSize(wx.Size(200,200))
self.initGraphics()
pass
def initGraphics(self):
sizer = wx.GridBagSizer()
i = 1
self.elements = {}
for confElement in self.conf.elements:
attribut=confElement['attribut']
value = ''
if self.object:
value = self.object.__dict__[attribut]
element = formElement.FormElement(self,confElement,value)
self.elements[attribut]=element
sizer.Add(element, (i,0,),(1,1), wx.EXPAND)
i = i+1
tmp = self.createButtonsPanel()
sizer.Add(tmp, (i,0),(1,1), wx.EXPAND)
self.SetSizer(sizer)
pass
def createButtonsPanel(self):
buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
panel = wx.Panel(self)
if self.object:
button = wx.Button(panel,id = wx.ID_APPLY)
else:
button = wx.Button(panel,id = wx.ID_ADD)
print "ids button = ",wx.ID_ADD,wx.ID_APPLY,wx.ID_CANCEL,button.GetId()
self.Bind(wx.EVT_BUTTON,self.OnAddModify,button)
buttonSizer.Add(button, 0, wx.GROW|wx.ALIGN_LEFT|wx.ALL, 5)
button = wx.Button(panel,id = wx.ID_CANCEL)
buttonSizer.Add(button, 0, wx.GROW|wx.ALIGN_LEFT|wx.ALL, 5)
panel.SetSizer(buttonSizer)
return panel
def OnAddModify(self, event):
print "Form.py.OnAddModify"
for attribut in self.elements:
print "self.",object.__class__.__name__,".__dict__[",attribut,"]=",self.elements[attribut].getValue()
self.object.__dict__[attribut]=self.elements[attribut].getValue()
print "Form.py.OnAddModify return code : ",self.GetReturnCode()
res = self.Close()
print "Form.py.OnAddModify return code : ",res |