[wxPython-users] Can anybody explain how to use
TransferDataToWindow/TransferDataFromWindow?
Werner F. Bruhin
werner.bruhin at free.fr
Tue Jan 2 08:57:21 PST 2007
Hi Thomas,
Thomas Weholt wrote:
> Ok, thanks for the example but I still got to set the value of each
> control and get the value in the TransferFromWindow? Is there any
> automagic-stuff going on anywhere? I don't see what the big hoopla
> about Transfer[To|From]Window is, but it seems like it's the way
> everybody does it anyway.
I don't have a stand alone example but hopefully this will be useful anyhow.
I use them like this:
- wineName is the control
- valTC is a validator for textCtrl
- dbParent is who holds the database info
- dbItem is a database class instance (I use ORM -
http://orm.nongnu.org/ - also still version 1)
- dbCol is the column name, it can contain relations e.g.
'childtable.columnname'
self.wineName.SetValidator(validators.valTC(dbParent = self,
dbitem='dbItem', dbCol = 'winename'))
In the TransferToWindow I then do this (snippet only):
textCtrl = self.GetWindow()
if self.dbItem in ['NORECORD', None]:
textCtrl.Clear()
return True
try:
newAttr = self.dbItem
components = self.dbCol.split('.')
for comp in components:
newAttr = getattr(newAttr, comp, None) # None default
can hide an error?!!!
if newAttr == None:
textCtrl.Clear() # just set it blank
textCtrl.Refresh()
else:
tempAttr = newAttr
textCtrl.SetValue(tempAttr.strip())
textCtrl.Refresh()
# override insertion point possition
# problem only shows with some controls
vl = len(tempAttr.strip())
wx.CallAfter(textCtrl._SetInsertionPoint, vl)
return True
I have validators for textCtrl, numCtrl, listCtrl, comboBox, and
treeCtrl, they each know how to "read" the dbItem and put the value into
the control.
In the code when I user selects a new item from e.g. a listCtrl I just
load the dbItem with the row/record from the database and then call
InitDialog or TransferToWindow and all controls on the panel all filled
with the appropriate value.
You do then similar things just the "other way round" in the
TransferFromWindow method.
I should clean up all my validator code, but it works and I have other
things higher on the list. One thing with 2.8 I will change is to
replace SetValue with ChangeValue so I don't get the change event which
enables my Save button which I then need to disable.
Werner
More information about the wxpython-users
mailing list