Re: [PyQt] wchar_t type mapping

2009-06-21 Thread Diez B. Roggisch

Diez B. Roggisch schrieb:

Hi,

I want to wrap a method with the following signature:

virtual irr::gui::IGUIStaticText* addStaticText(const wchar_t* text, 
const irr::core::rectirr::s32 rectangle,
  bool border=false, bool wordWrap=true, 
irr::gui::IGUIElement* parent=0, irr::s32 id=-1,

  bool fillBackground = false) = 0;


All types are mapped or declared, and compilation succeeds.

However, on calling the function, Python barks with



Traceback (most recent call last):
  File hello_world.py, line 64, in module
main()
  File hello_world.py, line 45, in main
True);
TypeError: argument 1 of IGUIEnvironment.addStaticText() has an invalid 
type


Ok, I found the problem - one needs to pass a unicode-object. While this 
makes sense to a certain degree, I think it would be good to enhance the 
mapping of wchar_t so that an attempt to convert bytestrings to unicode 
is done (as it is in other python APIs), potentially producing a 
UnicodeDecodeError of course. Would that be something worth considering?


Diez
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] wchar_t type mapping

2009-06-20 Thread Diez B. Roggisch

Hi,

I want to wrap a method with the following signature:

virtual irr::gui::IGUIStaticText* addStaticText(const wchar_t* text, 
const irr::core::rectirr::s32 rectangle,
		  bool border=false, bool wordWrap=true, 
irr::gui::IGUIElement* parent=0, irr::s32 id=-1,

  bool fillBackground = 
false) = 0;


All types are mapped or declared, and compilation succeeds.

However, on calling the function, Python barks with



Traceback (most recent call last):
  File hello_world.py, line 64, in module
main()
  File hello_world.py, line 45, in main
True);
TypeError: argument 1 of IGUIEnvironment.addStaticText() has an invalid type



So I tried to map the wchar_t from and to PyUnicode-objects. But this 
gives me an error that says


mac-dir:IrrSinn-1.5 deets$ python2.6 setup.py install
running install
running build
running build_ext
building 'irrlicht' extension
/Library/Frameworks/Python.framework/Versions/2.6/bin/sip -c 
build/temp.macosx-10.3-i386-2.6 -b 
build/temp.macosx-10.3-i386-2.6/irr.sbf irr.sip

sip: types.sip:613: Invalid type for %MappedType
error: command 
'/Library/Frameworks/Python.framework/Versions/2.6/bin/sip' failed with 
exit status 1



The mapping looks like this:

%MappedType wchar_t*
{
%TypeHeaderCode
#include wchar.h
%End

%ConvertFromTypeCode
  if (!sipCpp)
return Py_None;
  wchar_t *s = (wchar_t*)sipCpp;
  return PyUnicode_FromWideChar(s, wcslen(s));
%End

%ConvertToTypeCode
   if (sipIsErr == NULL) {
 return PyUnicode_Check(sipPy);
   }
  if (sipPy == Py_None) {
*sipCppPtr = NULL;
return 0;
  }
  Py_ssize_t len = PyUnicode_GET_SIZE(sipPy);
  wchar_t *w = malloc(sizeof(wchar_t) * len + 1);
  w[len] = 0;
  PyUnicode_AsWideChar(PyUnicodeObject *unicode, wchar_t *w, Py_ssize_t 
size);

  PyUnicode_AsWideChar(sipPy, w, len);
  *sipCppPtr = w;
  return 1;
%End
};



Any suggestions? Of course if anything else fails, I could manually wrap 
the methods in question - but I'd rather spare myself that effort.


Diez
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt