Hi Werner,
Mmm.... you are right.
Then should I call TransferDataToWindow or InitDialog? They seem to do
about the same.
Thanks,
Javier
Werner F. Bruhin wrote:
Hi Javier,
Took the code you posted some days ago, changed all "container" to
"contenador", then used a simple string to SetValue, then call
InitDialog when pressing the DataToWindow button and to me it looks like
it works.
I get the following output after I close your test program:
TransferValidator: Cargando ''.
TransferValidator: Retrieving data.
TransferValidator: Got 'some text'.
Leí: ['some text']
Changed code is attached.
See you
Werner
Javier Ruere wrote:
After trying out this function, I noticed it doesn't work in my app!
Like in the example I sent in the OP, I'm using a frame, not a dialog
so I still have to call TransferDataToWindow explicitly.
Regards,
Javier
Javier Ruere wrote:
I didn't notice that function, will start using it, thanks.
The problem was, as Robin Dunn mentioned, that the method of the
validator were called 'TransferDataFromWindow' instead of
'TransferFromWindow'.
Anyway, calling 'InitDialog' seems as the Right Thing to do.
Thanks,
Javier
PS: This is a great way of handling data load/save! I hope I had known
about it before.
Werner F. Bruhin wrote:
Javier,
I needed to include the following to make the validators work.
To get TransferToWindow to work I had to use (InitDialog), e.g. get the
SQL data, load some comboboxes and when all data is ready call
InitDialog for your panel.
def loadData(self, pkey):
"""Get the SQL data used by this page and do InitDialog.
"""
self.dbItem = self.ds.selectByPrimaryKey(beans.cellarbook, pkey)
loadRegionCbList(self, self.regionCB, 'Reload')
loadSubRegionCbList(self, self.subregionCB, 'Reload')
self.InitDialog() # needed for "TransferToWindow" in validator
when sitting on a panel
If I correctly understand it, InitDialog will call the
validator.TransferToWindow function of each control on the panel.
And to get TransferFromWindow to work I needed to do the following
on my
SaveData button.
def OnSavebutButton(self, event):
self.Validate()
self.TransferDataFromWindow()
self.ds.commit()
Hope this helps, see you
Werner
------------------------------------------------------------------------
from wxPython.wx import *
class MainFrame(wxFrame):
def __init__(self, parent):
wxFrame.__init__(self, parent, -1, 'Test')
Panel(self)
class Panel(wxPanel):
def __init__(self, parent):
wxPanel.__init__(self,parent,-1)
#,style=wxWS_EX_VALIDATE_RECURSIVELY)
self.SetAutoLayout(True)
self.contenedor = [ '' ]
self.__createWidgets()
def __createWidgets(self):
sizer = wxBoxSizer(wxVERTICAL)
self.SetSizer(sizer)
self.text = wxTextCtrl(
self, -1, validator=TransferValidator(self.contenedor, 0))
self.buttonTo = wxButton(self, -1, "DataToWindow")
self.buttonFrom = wxButton(self, -1, "DataFromWindow")
sizer.Add(self.text)
sizer.Add(self.buttonTo)
sizer.Add(self.buttonFrom)
EVT_BUTTON(self.buttonTo, self.buttonTo.GetId(),
self.DataToWindow)
EVT_BUTTON(self.buttonFrom, self.buttonFrom.GetId(),
self.DataFromWindow)
def DataToWindow(self, event):
self.InitDialog()
def DataFromWindow(self, event):
self.TransferDataFromWindow()
print "Leí:", self.contenedor
class TransferValidator(wxPyValidator):
def __init__(self, contenedor, index):
wxPyValidator.__init__(self)
self.contenedor = contenedor
self.index = index
def Clone(self): return TransferValidator(self.contenedor, self.index)
def Validate(self, win): return True
def TransferFromWindow(self):
print "TransferValidator: Retrieving data."
self.contenedor[self.index] = self.GetWindow().GetValue()
print "TransferValidator: Got '%s'." % self.contenedor[self.index]
return True
def TransferToWindow(self):
print "TransferValidator: Cargando '%s'." %
self.contenedor[self.index]
self.GetWindow().SetValue('some text')
return True
class BoaApp(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
self.main = MainFrame(None)
self.main.Show()
self.SetTopWindow(self.main)
return True
def main():
application = BoaApp(0)
application.MainLoop()
if __name__ == '__main__':
main()
- --
Q: How many IBM CPU's does it take to execute a job?
···
A: Four; three to hold it down, and one to rip its head off.