TransferFromWindow problem

I am banging my head against a wall on this today!

I have a dialog with a panel, on the dialog are two controls and on the panel another two.

When I call dialog.InitDialog() the controls get filled with data, when I call dialog.panel.InitDialog again the controls get filled, so far so good.

But now when I call dialog.panel.TransferDataFromWindow() nothing happens, I don't have the problem for the controls directly on the dialog.

Debugging the code I can see that validator.Clone is done for all controls, which is kind of proven by the above as the TransferToWindow works for all controls.

Any hints which could help me to figure out why the TransferFromWindow does not work for the controls on the panel would be very appreciated.

See you
Werner

Werner F. Bruhin wrote:

I am banging my head against a wall on this today!

I have a dialog with a panel, on the dialog are two controls and on the panel another two.

When I call dialog.InitDialog() the controls get filled with data, when I call dialog.panel.InitDialog again the controls get filled, so far so good.

But now when I call dialog.panel.TransferDataFromWindow() nothing happens, I don't have the problem for the controls directly on the dialog.

Debugging the code I can see that validator.Clone is done for all controls, which is kind of proven by the above as the TransferToWindow works for all controls.

Any hints which could help me to figure out why the TransferFromWindow does not work for the controls on the panel would be very appreciated.

Please make a small sample that shows the problem that I can play with.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Robin,

Robin Dunn wrote:

Werner F. Bruhin wrote:

I am banging my head against a wall on this today!

I have a dialog with a panel, on the dialog are two controls and on the panel another two.

When I call dialog.InitDialog() the controls get filled with data, when I call dialog.panel.InitDialog again the controls get filled, so far so good.

But now when I call dialog.panel.TransferDataFromWindow() nothing happens, I don't have the problem for the controls directly on the dialog.

Debugging the code I can see that validator.Clone is done for all controls, which is kind of proven by the above as the TransferToWindow works for all controls.

Any hints which could help me to figure out why the TransferFromWindow does not work for the controls on the panel would be very appreciated.

Please make a small sample that shows the problem that I can play with.

Put a small sample together (removed all the db stuff out, and the listctrl), but guess what it works there. So, back to debugging the real thing and comparing with the small test sample.

So to debug, I put "print 'name'" before calling SetValidator, then a print self in the validator.Clone and a print self.control.GetValidator().

In the sample, where things work I get this:

name
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c1a0_wxPyValidator_p>
shortname
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c270_wxPyValidator_p>
nametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c340_wxPyValidator_p>
shortnametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c410_wxPyValidator_p>

But in the real thing, where TransferFromWindow (for dialog and panel) does not work for nametrans and shortnametrans I get this:

name
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0620_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0688_wxPyValidator_p>
shortname
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0620_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0df8_wxPyValidator_p>
nametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _1338f78_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d8570_wxPyValidator_p>
shortnametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _1338f78_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d9bc8_wxPyValidator_p>

Can you explain why I get a different instance on print self in clone for the last two?

Following are the SetValidator lines for the four controls.
        print 'name'
        self.name.SetValidator(validators.valTC(dbParent = self.dbParent,
                                                dbItemName = 'dbMainItem',
                                                dbCol = 'name'))
        # shortName
        print 'shortname'
        self.shortName.SetValidator(validators.valTC(dbParent = self.dbParent,
                                                dbItemName = 'dbMainItem',
                                                dbCol = 'shortname'))

        print 'nametrans'
        self.nameTrans.SetValidator(validators.valTC(dbParent = self.dbParent,
                                                dbItemName = 'dbT1Item',
                                                dbCol = 'name'))

        print 'shortnametrans'
        self.shortNameTrans.SetValidator(validators.valTC(dbParent = self.dbParent,
                                                dbItemName = 'dbT1Item',
                                                dbCol = 'shortname'))

As always any hints a really appreciated.
Werner

Hi Robin,

Found out some more.

Werner F. Bruhin wrote:

Hi Robin,

Robin Dunn wrote:

Werner F. Bruhin wrote:

I am banging my head against a wall on this today!

I have a dialog with a panel, on the dialog are two controls and on the panel another two.

When I call dialog.InitDialog() the controls get filled with data, when I call dialog.panel.InitDialog again the controls get filled, so far so good.

But now when I call dialog.panel.TransferDataFromWindow() nothing happens, I don't have the problem for the controls directly on the dialog.

Debugging the code I can see that validator.Clone is done for all controls, which is kind of proven by the above as the TransferToWindow works for all controls.

Any hints which could help me to figure out why the TransferFromWindow does not work for the controls on the panel would be very appreciated.

Please make a small sample that shows the problem that I can play with.

Put a small sample together (removed all the db stuff out, and the listctrl), but guess what it works there. So, back to debugging the real thing and comparing with the small test sample.

So to debug, I put "print 'name'" before calling SetValidator, then a print self in the validator.Clone and a print self.control.GetValidator().

In the sample, where things work I get this:

name
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c1a0_wxPyValidator_p>
shortname
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c270_wxPyValidator_p>
nametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c340_wxPyValidator_p>
shortnametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c410_wxPyValidator_p>

But in the real thing, where TransferFromWindow (for dialog and panel) does not work for nametrans and shortnametrans I get this:

name
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0620_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0688_wxPyValidator_p>
shortname
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0620_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0df8_wxPyValidator_p>
nametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _1338f78_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d8570_wxPyValidator_p>
shortnametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _1338f78_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d9bc8_wxPyValidator_p>

Can you explain why I get a different instance on print self in clone for the last two?

Following are the SetValidator lines for the four controls.
       print 'name'
       self.name.SetValidator(validators.valTC(dbParent = self.dbParent,
                                               dbItemName = 'dbMainItem',
                                               dbCol = 'name'))
       # shortName
       print 'shortname'
       self.shortName.SetValidator(validators.valTC(dbParent = self.dbParent,
                                               dbItemName = 'dbMainItem',
                                               dbCol = 'shortname'))

       print 'nametrans'
       self.nameTrans.SetValidator(validators.valTC(dbParent = self.dbParent,
                                               dbItemName = 'dbT1Item',
                                               dbCol = 'name'))

       print 'shortnametrans'
       self.shortNameTrans.SetValidator(validators.valTC(dbParent = self.dbParent,
                                               dbItemName = 'dbT1Item',
                                               dbCol = 'shortname'))

As always any hints a really appreciated.
Werner

In the application I actually have a combobox inbetween the 2 sets of 2 controls. It also uses a validator (validator.valCB), when I move the code for this combobox to below the four other controls then the validator instance in validator.Clone is the same for all four, but TransferFromWindow still does not work for the last two controls.

Now when I disable all of the combobox code and hardcode the selection then TransferFromWindow does work. I obviously do something in that code to "deactivate" TransferFromWindow for two controls, but I have no clue what or even how I could do this.

Hopefully above is helpful in pointing me in the right direction.

See you
Werner

I think I found it, see below.

Werner F. Bruhin wrote:

Hi Robin,

Found out some more.

Werner F. Bruhin wrote:

<>Hi Robin,

Robin Dunn wrote:

Werner F. Bruhin wrote:

I am banging my head against a wall on this today!

I have a dialog with a panel, on the dialog are two controls and on the panel another two.

When I call dialog.InitDialog() the controls get filled with data, when I call dialog.panel.InitDialog again the controls get filled, so far so good.

But now when I call dialog.panel.TransferDataFromWindow() nothing happens, I don't have the problem for the controls directly on the dialog.

Debugging the code I can see that validator.Clone is done for all controls, which is kind of proven by the above as the TransferToWindow works for all controls.

Any hints which could help me to figure out why the TransferFromWindow does not work for the controls on the panel would be very appreciated.

Please make a small sample that shows the problem that I can play with.

Put a small sample together (removed all the db stuff out, and the listctrl), but guess what it works there. So, back to debugging the real thing and comparing with the small test sample.

So to debug, I put "print 'name'" before calling SetValidator, then a print self in the validator.Clone and a print self.control.GetValidator().

In the sample, where things work I get this:

name
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c1a0_wxPyValidator_p>
shortname
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c270_wxPyValidator_p>
nametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c340_wxPyValidator_p>
shortnametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c410_wxPyValidator_p>

But in the real thing, where TransferFromWindow (for dialog and panel) does not work for nametrans and shortnametrans I get this:

name
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0620_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0688_wxPyValidator_p>
shortname
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0620_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0df8_wxPyValidator_p>
nametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _1338f78_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d8570_wxPyValidator_p>
shortnametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _1338f78_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d9bc8_wxPyValidator_p>

Can you explain why I get a different instance on print self in clone for the last two?

Following are the SetValidator lines for the four controls.
       print 'name'

<> self.name.SetValidator(validators.valTC(dbParent = self.dbParent,
                                               dbItemName = 'dbMainItem',
                                               dbCol = 'name'))
       # shortName
       print 'shortname'
       self.shortName.SetValidator(validators.valTC(dbParent = self.dbParent,
                                               dbItemName = 'dbMainItem',
                                               dbCol = 'shortname'))

       print 'nametrans'
       self.nameTrans.SetValidator(validators.valTC(dbParent = self.dbParent,
                                               dbItemName = 'dbT1Item',
                                               dbCol = 'name'))

       print 'shortnametrans'
       self.shortNameTrans.SetValidator(validators.valTC(dbParent = self.dbParent,
                                               dbItemName = 'dbT1Item',
                                               dbCol = 'shortname'))

As always any hints a really appreciated.
Werner

In the application I actually have a combobox inbetween the 2 sets of 2 controls. It also uses a validator (validator.valCB), when I move the code for this combobox to below the four other controls then the validator instance in validator.Clone is the same for all four, but TransferFromWindow still does not work for the last two controls.

Now when I disable all of the combobox code and hardcode the selection then TransferFromWindow does work. I obviously do something in that code to "deactivate" TransferFromWindow for two controls, but I have no clue what or even how I could do this.

Instead of taking out all of the combobox I just don't set a validator for this combobox and all works as intented (as the choices need to change in this case). What I don't understand is that I use the same code in at least four other places (only difference I am aware of is that they are on a wxFrame and not a wxDialog) and I don't have a problem there.

        self.translation1.SetValidator(validators.valCB(dbParent = self.dbParent,
                                                     dbCol = self.translation1.dbCol))

I looked again at valCB code but can't see anything, there is little code so I just included it below. The combobox.LoadChoices() is the only thing I haven't ripped appart as it is kind of all or nothing. It gets values from the database and loads it into the choices.

While writing this I looked again at valCB and finally noticed that it did NOT have a TransferFromWindow, so just adding it with just Return True makes it all work, at leaset it does not that way.

See you and thanks for having asked for a sample, I am sure this would have taken even longer otherwise.

Werner

Hopefully above is helpful in pointing me in the right direction.

See you
Werner

class valCB(wxPyValidator):
    """Validator for a "stand alone" combobox (a selection list), which means that there
    is is NO foreign key column in a related table to get data from an ORM
    datasource to the Window.
    """
    def __init__(self, dbParent, dbItemName = '', dbCol=None):
        """dbParent = has to have a dbItem attribute which is a
        ORM select item (a class in beans.py)
        dbItemName is an optional string with an alternative dbItem
        dbCol = database column name
        """
        wxPyValidator.__init__(self)

        self.dbParent = dbParent
        self.dbItemName = dbItemName
        self.dbCol = dbCol

    def Clone(self):
        """Clone function, as the name implies creates a clone of this
        validator for each instance, make sure to pass the appropriate
        parameters.
        """
        return valCB(self.dbParent, self.dbItemName, self.dbCol)

    def TransferToWindow(self):
        """This gets the data from ORM.beans and writes it to the Window

        Note: dbCol might contain just a column name 'columnname', or
        it could contain a relation 'tablename.columnname'.
        """
        comboBox = self.GetWindow()
        comboBox.LoadChoices() # ensure correct choices are loaded
        return True

Werner F. Bruhin wrote:

Hi Robin,

Robin Dunn wrote:

Please make a small sample that shows the problem that I can play with.

Put a small sample together (removed all the db stuff out, and the listctrl), but guess what it works there. So, back to debugging the real thing and comparing with the small test sample.

This is why I always ask people to make a sample.

So to debug, I put "print 'name'" before calling SetValidator, then a print self in the validator.Clone and a print self.control.GetValidator().

In the sample, where things work I get this:

name
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c1a0_wxPyValidator_p>
shortname
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c270_wxPyValidator_p>
nametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c340_wxPyValidator_p>
shortnametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c138_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _128c410_wxPyValidator_p>

But in the real thing, where TransferFromWindow (for dialog and panel) does not work for nametrans and shortnametrans I get this:

name
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0620_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0688_wxPyValidator_p>
shortname
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0620_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d0df8_wxPyValidator_p>
nametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _1338f78_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d8570_wxPyValidator_p>
shortnametrans
<validators.valTC instance; proxy of C++ wxPyValidator instance at _1338f78_wxPyValidator_p>
<validators.valTC instance; proxy of C++ wxPyValidator instance at _13d9bc8_wxPyValidator_p>

Can you explain why I get a different instance on print self in clone for the last two?

It doesn't matter. Those hex numbers represent the address that the object lives at in memory. So your prints show that in your first example the same address was getting reused each time because there wasn't any other allocation between the time it released the one before and allocating the next. In your second example there must have been some other objects created before the last two validators were created so the original memory address was no longer available.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Werner F. Bruhin wrote:

Instead of taking out all of the combobox I just don't set a validator for this combobox and all works as intented (as the choices need to change in this case). What I don't understand is that I use the same code in at least four other places (only difference I am aware of is that they are on a wxFrame and not a wxDialog) and I don't have a problem there.

Dialogs have some built-in code for dealing with validators and frames don't. Perhaps the failure of the (missing) transfer function affects them differently.

       self.translation1.SetValidator(validators.valCB(dbParent = self.dbParent,
                                                    dbCol = self.translation1.dbCol))

I looked again at valCB code but can't see anything, there is little code so I just included it below. The combobox.LoadChoices() is the only thing I haven't ripped appart as it is kind of all or nothing. It gets values from the database and loads it into the choices.

While writing this I looked again at valCB and finally noticed that it did NOT have a TransferFromWindow, so just adding it with just Return True makes it all work, at leaset it does not that way.

By default the TransferData* fucntions return False (failure).

See you and thanks for having asked for a sample, I am sure this would have taken even longer otherwise.

Yep.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!