I am trying to get a couple of panels to show up within
one frame. I think I am having trouble with the sizer
stuff and they are writing over each other. Can someone
take a look at the attached code please? I am getting
better at this, and it seems drastically easier than
Tkinter.
How do I call something like func(*int x) from Python?
A few wxPython controls look for _int_p and passing a normal int type from
Python doesn't work.
wxPython does special things with pointer parameters. Often, the underlying wxWindows uses pointer parameters as an output mechanism -- you pass an integer pointer so that func() can tell you what x should be. Since Python doesn't support pointers and pass-by-reference in that manner, wxPython can't do that. Instead, wxPython will return a tuple containing all the output results.
For example, wxWindow.GetSize() is defined in wxWindows as taking parameters of (*int x, *int y), which it loads with the width and height of the window. In wxPython, GetSize() doesn't take any parameters, and it returns a tuple (x, y) instead. (Actually, I believe that GetSize() returns a wxSize object, and GetSizeTuple() is needed to get the tuple, but the same principle remains. This is another artifact of Python and C having different semantics, in this case regarding function overloading.)
In cases where a given parameter in wxWindows is intended for both input and output, wxPython will still have that parameter as input, but it will return the output via a tuple. Thus, that variable will appear in *both* the parameter list and the return list.
I'm not sure whether this applies to the specific case you have in mind, but it seems likely. Most of the wxWindows docs have wxPython notes that will indicate this sort of translation, but if you're using one of the odd corners of wxWindows, the wxPython notes might not be complete.
Jeff Shannon
Technician/Programmer
Credit International
x = 4 # normal python val
xPtr = ptrcreate("int") # allocate new ptr as _int_p type
ptrset(xPtr, 5) # assign val to the new int
my_c_func(xPtr) # pass the *int and do something with it
x = ptrvalue(xPtr) # assign the new value back to x
...a rather useless example, but these functions work like a champ
···
-----Original Message-----
From: Jeff Shannon [mailto:jeff@ccvcorp.com]
Sent: Friday, April 18, 2003 10:37 AM
To: wxPython-users@lists.wxwindows.org
Subject: Re: [wxPython-users] How to pass _int_p from Python?
Ben Allfree wrote:
>How do I call something like func(*int x) from Python?
>
>A few wxPython controls look for _int_p and passing a normal int type
from
>Python doesn't work.
>
wxPython does special things with pointer parameters. Often, the
underlying wxWindows uses pointer parameters as an output mechanism --
you pass an integer pointer so that func() can tell you what x should
be. Since Python doesn't support pointers and pass-by-reference in that
manner, wxPython can't do that. Instead, wxPython will return a tuple
containing all the output results.
For example, wxWindow.GetSize() is defined in wxWindows as taking
parameters of (*int x, *int y), which it loads with the width and height
of the window. In wxPython, GetSize() doesn't take any parameters, and
it returns a tuple (x, y) instead. (Actually, I believe that GetSize()
returns a wxSize object, and GetSizeTuple() is needed to get the tuple,
but the same principle remains. This is another artifact of Python and
C having different semantics, in this case regarding function
overloading.)
In cases where a given parameter in wxWindows is intended for both input
and output, wxPython will still have that parameter as input, but it
will return the output via a tuple. Thus, that variable will appear in
*both* the parameter list and the return list.
I'm not sure whether this applies to the specific case you have in mind,
but it seems likely. Most of the wxWindows docs have wxPython notes
that will indicate this sort of translation, but if you're using one of
the odd corners of wxWindows, the wxPython notes might not be complete.
Jeff Shannon
Technician/Programmer
Credit International
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Friday, April 18, 2003 12:51 PM
To: wxPython-users@lists.wxwindows.org
Subject: Re: [wxPython-users] How to pass _int_p from Python?
Ben Allfree wrote:
> How do I call something like func(*int x) from Python?
>
> A few wxPython controls look for _int_p and passing a normal int type
from
> Python doesn't work.
Do you know of any besides AdjustPagebreak? I'll fix them too.
In the meantime you can do something like this:
intptr = ptrcreate("int", value)
Then later:
newvalue = ptrvalue(intptr)
Just be aware that this won't work anymore once I fix the methods to use
the INOUT typemap.
[later]
Ah, I see you've already figured out those helpers...
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org