Zunbeltz Izaola wrote:
The values of the vaialbes (parent.Gerator... ) are displayed correctly in
de dialog, but when I change it and close the dialog with an wxID_OK
button the variables have the initial values, no waht i have put
String objects in Python are immutable. That means that when you do
self.data = self.GetWindow().GetValue()
self.data is now a reference to a *new* string, and the original string is still refered to by the original variable. (In C++ data objects are not immutable and so they can be changed in place, which is why the validator concept works better there.)
One way to work around this is to make a data holder class, and pass instances of this class to your validator.
class DataHolder:
def __init__(self, value=None):
self.data = value
class GainValidator(wx.PyValidator):
def __init__(self, holder):
wx.PyValidator.__init__(self)
self.holder = holder
def Clone(self):
return GainValidator(self.holder)
def Validate(self, event):
return True
def TransferToWindow(self):
self.GetWindow().SetValue(self.holder.data)
print self.data
return True
def TransferFromWindow(self):
self.holder.data = self.GetWindow().GetValue()
print self.data
return True
Now, since the self.holder is not being reassigned (so it still refers to the original object) then the change of data in the validator will still be accessible via the original parent.GeneratorVoltage instance of the holder.
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!