Bonjour à tous,
Je vous écris car je ne comprends plus rien.
Tout d'abord, je débute en python et wxpython.
Dans le cadre de mon projet, je dois à un moment créer un formulaire permettant de saisir différentes données.
J'ai adjoint à ce formulaire deux boutons avec les id wx.ID_APPLY et wx.ID_CANCEL. Malheureusement pour moi et surement par ma faute, que je clique sur l'un ou sur l'autre bouton, c'est toujours ID_CANCEL qui est renvoyé.
Voici une partie de mon code source pour vous fair une idée.
Classe étendant dialog
Appel à la classe
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Et voici à quoiressemble la sortie en appuyant sur le bouton ID_APPLY :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 def OnAdd(self, event): element = Element.Element() confPath = self.facade.computePath(Configuration.Configuration.getInstance('general').getProperty('element.description')) panel = elementPanel.ElementPanel(parent = self.parent,conf=confPath, element = element,facade = self.facade) panel.SetPosition(self.position) result = panel.ShowModal() print result,panel.GetReturnCode(), " (OK : ", wx.ID_OK,", CANCEL = ",wx.ID_CANCEL,")" if result== wx.ID_OK: print panel.element self.desktop.elements.append(panel.element) pass
Merci par avance,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 ids button = 5118 5102 5101 -214 Form.py.OnAddModify self. type .__dict__[ nom ]= aze self. type .__dict__[ commande ]= aze self. type .__dict__[ icone ]= $INSTALL_PATH$\resources\default.gif Form.py.OnAddModify return code : 0 Form.py.OnAddModify return code : True 5101 5101 (OK : 5100 , CANCEL = 5101 )
J'ai effectué quelques recherches, mais je n'arrive pas à trouver le problème.
Partager