[wxPython] some problems with - Warning: Could not transfer data to window

When I run the attached code, I get a "Warning: Could not transfer data
to window". Can someone else please run it and confirm that this is the
case? What is wrong with this code?

"MyValidator" comes straight from wxValidator.py in the examples.

Thanks,
Hugo van der Merwe

example.py (1.96 KB)

When I run the attached code, I get a "Warning: Could not transfer data
to window". Can someone else please run it and confirm that this is the
case? What is wrong with this code?

"MyValidator" comes straight from wxValidator.py in the examples.

Sorry, forgot to say thanks for the replies I got last time I asked
about this. I played a bit with some of the suggestions, but couldn't
exactly figure them out. The thing that I find odd, is that I use a
direct copy of the validator class from an example that does work, so it
must be some other part of my code that is tripping this thing.

class ExampleDlg(wxDialog):
    def __init__(self, parent):
        wxDialog.__init__(self, parent, -1, "Example dialog",
                          wxDefaultPosition, wxSize(350,200),
                          wxRESIZE_BORDER | wxCAPTION | wxSYSTEM_MENU)
        wxTextCtrl(self, -1, "", validator = MyValidator(DIGIT_ONLY))

Something in one of those last two lines?

I don't think I've done a thorough enough learning of the way wxpython
fits together, trying to get things going based on examples I've seen.
(E.g. wxWindowID's - when must one use wxNewId() and when can one just
use -1? It looked like this ID was just for when you need to identify a
window, this right?)

Thanks,
Hugo van der Merwe

Yes. If you for anstance want to connect an event to a
control, you need to know it's id. If you do:

p.buttonSizer.AddMany([
     (wxButton(p, -1, 'Import file'), 0, 0, 5),
     (wxButton(p, -1, 'Export File'), 0, 0, 5)])

How in the world would you be able to connect the events?
EVT_BUTTON(self, ???, self.OnImportButton)
EVT_BUTTON(self, ???, self.OnExportButton)

So you do:
IMPORT_BUTTON_ID = wxNewId()
EXPORT_BUTTON_ID = wxNewId()
p.buttonSizer.AddMany([
     (wxButton(p, IMPORT_BUTTON_ID, 'Import file'), 0, 0, 5),
     (wxButton(p, EXPORT_BUTTON_ID, 'Export File'), 0, 0, 5)])
EVT_BUTTON(self, IMPORT_BUTTON_ID, self.OnImportButton)
EVT_BUTTON(self, EXPORT_BUTTON_ID, self.OnExportButton)

But on the other hand, if you do:

impBtn = wxButton(p, IMPORT_BUTTON_ID, 'Import file',
                      wxPoint(5, 5))

you can continue with
EVT_BUTTON(self, impBtn.GetId(), self.OnImportButton)

/Magnus

···

At 00:52 2001-11-04 +0200, Hugo van der Merwe wrote:

I don't think I've done a thorough enough learning of the way wxpython
fits together, trying to get things going based on examples I've seen.
(E.g. wxWindowID's - when must one use wxNewId() and when can one just
use -1? It looked like this ID was just for when you need to identify a
window, this right?)

--
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se

Yes. If you for anstance want to connect an event to a
control, you need to know it's id. If you do:

Thanks. So I am right in thinking if you don't need to connect events
... um, eg. with wxStaticText, there is absolutely no need to give it a
unique ID - then you give it a -1?

Hugo van der Merwe

Well... more or less. Look through the demo code and you
will learn a lot.

If you assign the control or window to a variable, you will be
able to get hold of it without knowing an id, and personally I
prefer local variables and objexct attributes to global variables
like these IDs tend to be.

You might want to change the text in a wxStaticText with the
SetLabel(), and if you didn't assign the control to a name,
you might need the ID, and use someWindow.FindWindowById(ID)
to get hold of it. See OOR in "New since last release" in the
demo of the latest version.

But it's all very simple. If you can get away with -1 and without
assigning the window/control to a name, then everything is fine. If
you need to access the control or its ID, then you either need to
assign the control to a sufficiently stable name, a local variable
if that's enough or an object attribute, or give it an explicit ID.
If you can't assign it a name but need to access it, you need to give
it an ID. It's not really relevant what kind of control it is, but
as you suggest, for some types you rarely need a reference, and for
others you usually do.

There is some other magic at play here, like wxFindWindowAtPointer,
but let us leave that for the time being...

/Magnus

···

At 18:17 2001-11-04 +0200, you wrote:

> Yes. If you for anstance want to connect an event to a
> control, you need to know it's id. If you do:

Thanks. So I am right in thinking if you don't need to connect events
... um, eg. with wxStaticText, there is absolutely no need to give it a
unique ID - then you give it a -1?

--
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se

When I run the attached code, I get a "Warning: Could not transfer data
to window". Can someone else please run it and confirm that this is the
case? What is wrong with this code?

My apologies. I did some more reading in the mailing list archives, and
saw more references to TransferFromWindow and TransferToWindow. So I
decided to give that another shot. This time it worked, so last time I
tried it, I must have made a typo or something. argh.

Thanks for the help,
Hugo van der Merwe