[C++-sig] Boost and wxWidgets
Joan Carles Jimenez
jjcarles at jocajica.com
Wed Jan 13 22:06:40 CET 2010
Hi.
I am testing the following source code:
--------
Canvas.h
--------
#ifndef _CANVAS_H_
#define _CANVAS_H_
#include <string>
#include "wx/wx.h"
class CanvasFrame
{
protected:
wxFrame* _frame;
public:
CanvasFrame(const std::string& pTitle);
~CanvasFrame(void);
void Plot(void);
};
#endif /* _CANVAS_H_ */
----------
Canvas.cpp
----------
#include <Python.h>
#include "canvas.h"
CanvasFrame::CanvasFrame(const std::string& pTitle)
{
_frame = new wxFrame(NULL, wxID_ANY,
wxString::FromAscii(pTitle.c_str()));
}
CanvasFrame::~CanvasFrame(void)
{
if(_frame) {
delete _frame;
}
}
void CanvasFrame::Plot(void)
{
}
-----------
wrapper.cpp
-----------
#include <boost/python.hpp>
#include "canvas.h"
using namespace boost::python;
BOOST_PYTHON_MODULE(canvas)
{
class_<CanvasFrame>("CanvasFrame", init<const std::string&>())
.def("Plot", &CanvasFrame::Plot)
;
}
And to generate the module "canvas.so" I execute:
g++ -shared -g -I. -I/usr/include/python2.6 -lpython2.6 canvas.cpp
wrapper.cpp /usr/lib64/libboost_python.so -fPIC `wx-config --cxxflags`
`wx-config --libs` -o canvas.so
"canvas.so" is generated without any problems but when I execute in the
python console the next code:
>>> import canvas
>>> a = canvas.CanvasFrame('My Plot Window')
I have the next errors:
(process:3521): GLib-GObject-CRITICAL **: gtype.c:2458: initialization
assertion failed, use IA__g_type_init() prior to this function
(process:3521): GLib-CRITICAL **: g_once_init_leave: assertion
`initialization_value != 0' failed
(process:3521): Gdk-CRITICAL **: gdk_cursor_new_for_display: assertion
`GDK_IS_DISPLAY (display)' failed
(process:3521): GLib-GObject-CRITICAL **: gtype.c:2458: initialization
assertion failed, use IA__g_type_init() prior to this function
And more, and more, and more. I have watched the examples of
http://wiki.python.org/moin/boost.python/ExportingClasses
but I have not seen any problem. They can help me? Thanks!
P.D. Sorry for my english!
More information about the Cplusplus-sig
mailing list