I have drawing context handle (HDC) from ctypes and I know it's a
memory drawing context.
I got the memory address of it from ctypes.
How can I wrap it wxPython?
What I have tried, and thought should work is to import sip, and then
use sip.wrapinstance, but it doesn't work.
No, in order to wrap a type in a class with sip, that class has to be
derived from sip.wrappertype. You can't force an arbitrary Python class
to suck up an arbitrary pointer. The class has to participate in the
wrapping. wx.MemoryDC doesn't participate.
I'm not sure the underlying wxWidets library has a way to do this even
in C++ code.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
I have drawing context handle (HDC) from ctypes and I know it's a memory
drawing context.
I got the memory address of it from ctypes.
How can I wrap it wxPython?
What I have tried, and thought should work is to import sip, and then
use sip.wrapinstance, but it doesn't work.
I get this weird error:
>>
TypeError:must be sip.wrappertype,notsip.wrappertype
What I tried is:
sip.wrapinstance(address,wx.MemoryDC)
Part of the problem is you are using the wrong sip module. Phoenix includes its own which is accessible as wx.siplib, in order to reduce external dependencies and to avoid problems if the wrong version of sip is already installed. So because of the separate sip modules there are two separate sets of type info, so they don't recognize the types from the other sets.
The other part of the problem is that an HDC is not the same as a wxMemoryDC object. The latter does contain a HDC of its own (on Windows) but what you've got is not a pointer to a wxMemoryDC so wrapinstance can not work with it. I expect that even if you use wx.siplib.wrapinstance all you will get is a pointer fault and a program crash as soon as you try to call a method that uses the HDC value as a wxDC pointer.
There is an undocumented SetHDC method in the C++ wxDC class. I'll take a closer look and see if it makes sense to wrap it in the Python classes.
Thanks guys for the responses, (I need to set my self up to get replies from this thread.)
The main reason for wanting access to setHDC in python is that we have a C++ code base and we are trying to wrap python on top of that.
Initially, we were going to use the gdi wrapped library from ctypes, but it seemed like wxPython is a better road.
···
On Friday, April 3, 2015 at 9:24:16 PM UTC-4, Robin Dunn wrote:
Eric Yen wrote:
Hi Everyone,
I have drawing context handle (HDC) from ctypes and I know it’s a memory
drawing context.
I got the memory address of it from ctypes.
How can I wrap it wxPython?
What I have tried, and thought should work is to import sip, and then
use sip.wrapinstance, but it doesn’t work.
I get this weird error:
TypeError:must be sip.wrappertype,notsip.wrappertype
What I tried is:
sip.wrapinstance(address,wx.MemoryDC)
Part of the problem is you are using the wrong sip module. Phoenix
includes its own which is accessible as wx.siplib, in order to reduce
external dependencies and to avoid problems if the wrong version of sip
is already installed. So because of the separate sip modules there are
two separate sets of type info, so they don’t recognize the types from
the other sets.
The other part of the problem is that an HDC is not the same as a
wxMemoryDC object. The latter does contain a HDC of its own (on
Windows) but what you’ve got is not a pointer to a wxMemoryDC so
wrapinstance can not work with it. I expect that even if you use
wx.siplib.wrapinstance all you will get is a pointer fault and a program
crash as soon as you try to call a method that uses the HDC value as a
wxDC pointer.
There is an undocumented SetHDC method in the C++ wxDC class. I’ll take
a closer look and see if it makes sense to wrap it in the Python classes.