From 4534151926c4f3887ba9e37ae67df16f1eb039ef Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 17 Feb 2003 21:25:52 +0000 Subject: [PATCH] split up the otk stuff into separate files. wrap otk::Property properly with typemaps so that it is usable. wrap otk::Timer properly so that you can use it with a python callback --- wrap/Makefile.am | 4 +- wrap/ob.i | 3 +- wrap/{callback.i => ob_callback.i} | 10 +- wrap/ob_client.i | 4 +- wrap/ob_openbox.i | 1 + wrap/ob_screen.i | 39 +++++-- wrap/otk.i | 81 ++++---------- wrap/otk_application.i | 13 +++ wrap/otk_appwidget.i | 20 ++++ wrap/otk_button.i | 22 ++++ wrap/otk_font.i | 13 +++ wrap/otk_label.i | 21 ++++ wrap/otk_point.i | 10 ++ wrap/otk_property.i | 164 +++++++++++++++++++++++++++++ wrap/otk_rect.i | 13 +++ wrap/otk_rendercolor.i | 17 +++ wrap/otk_renderstyle.i | 27 +++++ wrap/otk_rendertexture.i | 10 ++ wrap/otk_size.i | 10 ++ wrap/otk_strut.i | 10 ++ wrap/otk_timer.i | 78 ++++++++++++++ wrap/{ustring.i => otk_ustring.i} | 6 +- wrap/otk_widget.i | 35 ++++++ 23 files changed, 531 insertions(+), 80 deletions(-) rename wrap/{callback.i => ob_callback.i} (95%) create mode 100644 wrap/otk_application.i create mode 100644 wrap/otk_appwidget.i create mode 100644 wrap/otk_button.i create mode 100644 wrap/otk_font.i create mode 100644 wrap/otk_label.i create mode 100644 wrap/otk_point.i create mode 100644 wrap/otk_property.i create mode 100644 wrap/otk_rect.i create mode 100644 wrap/otk_rendercolor.i create mode 100644 wrap/otk_renderstyle.i create mode 100644 wrap/otk_rendertexture.i create mode 100644 wrap/otk_size.i create mode 100644 wrap/otk_strut.i create mode 100644 wrap/otk_timer.i rename wrap/{ustring.i => otk_ustring.i} (90%) create mode 100644 wrap/otk_widget.i diff --git a/wrap/Makefile.am b/wrap/Makefile.am index d3e44edc..3f904882 100644 --- a/wrap/Makefile.am +++ b/wrap/Makefile.am @@ -41,9 +41,9 @@ otk.i: $(wildcard ../otk/*.hh) ob.i: $(addprefix ../src/,openbox.hh screen.hh client.hh python.hh frame.hh) @touch $@ -wrap_otk.cc: otk.i +wrap_otk.cc: otk.i otk_point.i otk_rect.i otk_size.i otk_rendercolor.i otk_rendertexture.i otk_ustring.i otk_font.i otk_renderstyle.i otk_widget.i otk_label.i otk_button.i otk_appwidget.i otk_application.i otk_strut.i otk_property.i otk_timer.i $(SWIG) $(SWIG_PYTHON_OPT) $(filter -I%,$(CPPFLAGS)) -nodefault -o $@ $< -wrap_ob.cc: ob.i callback.i ob_client.i ob_screen.i ob_openbox.i ob_frame.i ob_python.i +wrap_ob.cc: ob.i ob_callback.i ob_client.i ob_screen.i ob_openbox.i ob_frame.i ob_python.i $(SWIG) $(SWIG_PYTHON_OPT) $(filter -I%,$(CPPFLAGS)) -nodefault -o $@ $< diff --git a/wrap/ob.i b/wrap/ob.i index 8f3cb4e3..b6c9461e 100644 --- a/wrap/ob.i +++ b/wrap/ob.i @@ -32,7 +32,7 @@ void send_client_msg(Window target, Atom type, Window about, %include "ob_client.i" %include "ob_frame.i" %include "ob_python.i" -%include "callback.i" +%include "ob_callback.i" // for Window etc %import "X11/X.h" @@ -42,6 +42,7 @@ void send_client_msg(Window target, Atom type, Window about, #include "bindings.hh" #include "otk/display.hh" #include "otk/screeninfo.hh" +#include "otk/util.hh" void set_reset_key(const std::string &key) { diff --git a/wrap/callback.i b/wrap/ob_callback.i similarity index 95% rename from wrap/callback.i rename to wrap/ob_callback.i index b13a3e9d..776bdb2b 100644 --- a/wrap/callback.i +++ b/wrap/ob_callback.i @@ -1,5 +1,7 @@ // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- +%module ob_callback + %include "std_string.i" %{ @@ -121,7 +123,7 @@ bool mbind(const std::string &button, ob::MouseContext::MC context, PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); return false; } - Py_INCREF(func); + Py_INCREF(func); // the func is never decreffed... XXX return true; } @@ -136,7 +138,7 @@ bool ebind(ob::EventAction::EA action, PyObject *func) PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); return false; } - Py_INCREF(func); + Py_INCREF(func); // the func is never decreffed... XXX return true; } @@ -147,7 +149,7 @@ bool kgrab(int screen, PyObject *func) PyErr_SetString(PyExc_RuntimeError,"Unable to grab keybaord."); return false; } - Py_INCREF(func); + Py_INCREF(func); // the func is never decreffed... XXX return true; } @@ -197,7 +199,7 @@ bool kbind(PyObject *keylist, ob::KeyContext::KC context, PyObject *func) PyErr_SetString(PyExc_RuntimeError,"Unable to add binding."); return false; } - Py_INCREF(func); + Py_INCREF(func); // the func is never decreffed... XXX return true; } diff --git a/wrap/ob_client.i b/wrap/ob_client.i index af861edd..353db7e5 100644 --- a/wrap/ob_client.i +++ b/wrap/ob_client.i @@ -7,8 +7,8 @@ #include "client.hh" %} -%include "otk.i" // XXX otk_size.i!!! -%include "ustring.i" +%include "otk_size.i" +%include "otk_ustring.i" %include "std_string.i" namespace ob { diff --git a/wrap/ob_openbox.i b/wrap/ob_openbox.i index ed44380b..48cfa905 100644 --- a/wrap/ob_openbox.i +++ b/wrap/ob_openbox.i @@ -31,4 +31,5 @@ namespace ob { } +%import "../otk/eventdispatcher.hh" %include "openbox.hh" diff --git a/wrap/ob_screen.i b/wrap/ob_screen.i index bbf7b57c..b182d2d7 100644 --- a/wrap/ob_screen.i +++ b/wrap/ob_screen.i @@ -10,8 +10,23 @@ %} %include "ob_client.i" -%include "otk.i" // XXX otk_rect.i!!! -%include "ustring.i" +%include "otk_rect.i" +%include "otk_ustring.i" +%include "otk_size.i" +%include "std_vector.i" + +%typemap(python,out) const otk::Property::StringVect& { + otk::Property::StringVect *v = $1; + unsigned int s = v->size(); + PyObject *l = PyList_New(s); + + otk::Property::StringVect::const_iterator it = v->begin(), end = v->end(); + for (unsigned int i = 0; i < s; ++i, ++it) { + PyObject *pdata = PyString_FromString(it->c_str()); + PyList_SET_ITEM(l, i, pdata); + } + $result = l; +} %typemap(python,out) std::list { unsigned int s = $1.size(); @@ -25,14 +40,14 @@ $result = l; } -%typemap(python,out) const otk::Property::StringVect& { - otk::Property::StringVect *v = $1; +%typemap(python,out) const std::vector& { + std::vector *v = $1; unsigned int s = v->size(); PyObject *l = PyList_New(s); - otk::Property::StringVect::const_iterator it = v->begin(), end = v->end(); + std::vector::const_iterator it = v->begin(), end = v->end(); for (unsigned int i = 0; i < s; ++i, ++it) { - PyObject *pdata = PyString_FromString(it->c_str()); + PyObject *pdata = SWIG_NewPointerObj((void*)&(*it),SWIGTYPE_p_otk__Rect,0); PyList_SET_ITEM(l, i, pdata); } $result = l; @@ -52,6 +67,18 @@ namespace ob { send_client_msg(root, otk::Property::atoms.net_current_desktop, root, desktop); } + + const otk::Size& size() { + return otk::display->screenInfo(self->number())->size(); + } + + const std::vector &xineramaAreas() { + return otk::display->screenInfo(self->number())->xineramaAreas(); + } + + Window rootWindow() { + return otk::display->screenInfo(self->number())->rootWindow(); + } } %immutable Screen::clients; diff --git a/wrap/otk.i b/wrap/otk.i index 4ff835a6..6611a992 100644 --- a/wrap/otk.i +++ b/wrap/otk.i @@ -2,79 +2,36 @@ %module otk -%{ -#include "otk.hh" -%} - -%include "stl.i" -%include "typemaps.i" -//%include std_list.i -%include "ustring.i" +%import "eventhandler.hh" +%import "eventdispatcher.hh" + +%include "otk_strut.i" +%include "otk_point.i" +%include "otk_size.i" +%include "otk_rect.i" +%include "otk_rendercolor.i" +%include "otk_rendertexture.i" +%include "otk_font.i" +%include "otk_ustring.i" +%include "otk_renderstyle.i" +%include "otk_widget.i" +%include "otk_label.i" +%include "otk_button.i" +%include "otk_application.i" +%include "otk_appwidget.i" +%include "otk_property.i" +%include "otk_timer.i" -%immutable otk::display; %immutable otk::Property::atoms; -namespace otk { -/*%rename(setValue_bool) Configuration::setValue(std::string const &,bool); -%rename(setValue_unsigned) Configuration::setValue(const std::string &, unsigned int); -%rename(setValue_long) Configuration::setValue(const std::string &, long); -%rename(setValue_unsignedlong) Configuration::setValue(const std::string &, unsigned long); -%rename(setValue_string) Configuration::setValue(const std::string &, const std::string &); -%rename(setValue_charptr) Configuration::setValue(const std::string &, const char *);*/ - -%rename(itostring_unsigned) itostring(unsigned int); -%rename(itostring_long) itostring(long); -%rename(itostring_unsigned_long) itostring(unsigned long); - -// these are needed for guile, but not needed for python! -//%rename(equals) BColor::operator==; -//%rename(equals) Rect::operator==; -//%rename(equals) BTexture::operator==; -//%ignore BColor::operator!=; -//%ignore BTexture::operator!=; -%ignore Rect::operator!=; -%ignore Rect::operator|; -%ignore Rect::operator|=; -%ignore Rect::operator&; -%ignore Rect::operator&=; -//%ignore OBTimer::operator<; %ignore TimerLessThan; -/* -%rename(set_multi) OtkProperty::set(Window, Atoms, Atoms, unsigned long[], int); -%rename(set_string) OtkProperty::set(Window, Atoms, StringType, const std::string &); -%rename(set_string_multi) OtkProperty::set(Window, Atoms, StringType, const StringVect &); -*/ -} - -%include "eventhandler.hh" -%include "eventdispatcher.hh" -%include "point.hh" -%include "size.hh" -%include "rect.hh" -%include "rendercolor.hh" -%include "rendertexture.hh" -%include "font.hh" -%include "renderstyle.hh" -%include "widget.hh" -%include "label.hh" -%include "appwidget.hh" -%include "application.hh" -%include "button.hh" -%include "display.hh" -%include "rendercontrol.hh" -%include "screeninfo.hh" -%include "strut.hh" - -%apply unsigned long *OUTPUT { unsigned long *value }; -%include "property.hh" // for Window etc %import "X11/X.h" // globals %pythoncode %{ -display = cvar.display; atoms = cvar.Property_atoms; def style(screen): diff --git a/wrap/otk_application.i b/wrap/otk_application.i new file mode 100644 index 00000000..68780553 --- /dev/null +++ b/wrap/otk_application.i @@ -0,0 +1,13 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_application + +%{ +#include "config.h" +#include "application.hh" +%} + +%include "otk_widget.i" + +%import "../otk/eventdispatcher.hh" +%include "application.hh" diff --git a/wrap/otk_appwidget.i b/wrap/otk_appwidget.i new file mode 100644 index 00000000..25de3469 --- /dev/null +++ b/wrap/otk_appwidget.i @@ -0,0 +1,20 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_appwidget + +%{ +#include "config.h" +#include "appwidget.hh" +%} + +%include "otk_widget.i" +%include "otk_application.i" + +namespace otk { + +%ignore AppWidget::clientMessageHandler(const XClientMessageEvent &); + + +} + +%include "appwidget.hh" diff --git a/wrap/otk_button.i b/wrap/otk_button.i new file mode 100644 index 00000000..e2161607 --- /dev/null +++ b/wrap/otk_button.i @@ -0,0 +1,22 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_button + +%{ +#include "config.h" +#include "button.hh" +%} + +%include "otk_widget.i" +%include "otk_ustring.i" +%include "otk_font.i" +%include "otk_renderstyle.i" + +namespace otk { + +%ignore Button::clickHandler(unsigned int); +%ignore Button::styleChanged(const RenderStyle &); + +} + +%include "button.hh" diff --git a/wrap/otk_font.i b/wrap/otk_font.i new file mode 100644 index 00000000..797a1532 --- /dev/null +++ b/wrap/otk_font.i @@ -0,0 +1,13 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_rendertexture + +%{ +#include "config.h" +#include "font.hh" +%} + +%include "otk_ustring.i" +%include "std_string.i" + +%include "font.hh" diff --git a/wrap/otk_label.i b/wrap/otk_label.i new file mode 100644 index 00000000..ca85b899 --- /dev/null +++ b/wrap/otk_label.i @@ -0,0 +1,21 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_label + +%{ +#include "config.h" +#include "label.hh" +%} + +%include "otk_widget.i" +%include "otk_ustring.i" +%include "otk_font.i" +%include "otk_renderstyle.i" + +namespace otk { + +%ignore Label::renderForeground(Surface &); + +} + +%include "label.hh" diff --git a/wrap/otk_point.i b/wrap/otk_point.i new file mode 100644 index 00000000..6e2fc6f1 --- /dev/null +++ b/wrap/otk_point.i @@ -0,0 +1,10 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_point + +%{ +#include "config.h" +#include "point.hh" +%} + +%include "point.hh" diff --git a/wrap/otk_property.i b/wrap/otk_property.i new file mode 100644 index 00000000..118f8c5c --- /dev/null +++ b/wrap/otk_property.i @@ -0,0 +1,164 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_property + +%{ +#include "config.h" +#include "property.hh" +%} + +%include "otk_ustring.i" + +%typemap(python,in) const otk::Property::StringVect & (otk::Property::StringVect temp) { + if (PyList_Check($input)) { + int s = PyList_Size($input); + temp = otk::Property::StringVect(s); + for (int i = 0; i < s; ++i) { + PyObject *o = PyList_GetItem($input, i); + if (PyString_Check(o)) { + temp[i] = PyString_AsString(o); + } else { + SWIG_exception(SWIG_TypeError, "list of strings expected"); + } + } + $1 = &temp; + } else { + SWIG_exception(SWIG_TypeError, "list expected"); + } +} + +%typemap(python,in) unsigned long value[] (unsigned long *temp) { + if (PyList_Check($input)) { + int s = PyList_Size($input); + temp = new unsigned long[s]; + for (int i = 0; i < s; ++i) { + PyObject *o = PyList_GetItem($input, i); + if (PyInt_Check(o)) { + temp[i] = PyInt_AsLong(o); + } else if (PyLong_Check(o)) { + temp[i] = PyLong_AsLong(o); + } else { + SWIG_exception(SWIG_TypeError, "list of numbers expected"); + } + } + $1 = temp; + } else { + SWIG_exception(SWIG_TypeError, "list expected"); + } +} + +%typemap(python,freearg) unsigned long value[] { + delete [] $1; +} + +%typemap(python,in,numinputs=0) otk::ustring *value (otk::ustring temp) { + $1 = &temp; +} + +%typemap(python,argout) otk::ustring *value { + PyObject *tuple; + int s; + if (PyTuple_Check($result)) { + s = PyTuple_Size($result); + _PyTuple_Resize(&$result, s + 1); + tuple = $result; + } else { + tuple = PyTuple_New(2); + PyTuple_SET_ITEM(tuple, 0, $result); + Py_INCREF($result); + s = 1; + } + + PyTuple_SET_ITEM(tuple, s, PyString_FromString($1->c_str())); + $result = tuple; +} + +%typemap(python,in,numinputs=0) unsigned long *value (unsigned long temp) { + $1 = &temp; +} + +%typemap(python,argout) unsigned long *value { + PyObject *s = PyLong_FromLong(*$1); + $result = s; +} + +%typemap(python,in) unsigned long *nelements (unsigned long temp) { + temp = (unsigned)PyLong_AsLong($input); + $1 = &temp; +} + +%typemap(python,in,numinputs=0) unsigned long **value (unsigned long *temp) { + $1 = &temp; +} + +%typemap(python,argout) (unsigned long *nelements, unsigned long **value) { + PyObject *tuple; + int s; + if (PyTuple_Check($result)) { + s = PyTuple_Size($result); + _PyTuple_Resize(&$result, s + 2); + tuple = $result; + } else { + tuple = PyTuple_New(3); + PyTuple_SET_ITEM(tuple, 0, $result); + Py_INCREF($result); + s = 1; + } + + int sz = *$1; + + PyTuple_SET_ITEM(tuple, s++, PyLong_FromLong(sz)); + + PyObject *r = PyList_New(sz); + for (int i = 0; i < sz; ++i) { + PyList_SET_ITEM(r, i, PyLong_FromLong((*$2)[i])); + } + PyTuple_SET_ITEM(tuple, s, r); + $result = tuple; +} + +%typemap(python,in,numinputs=0) StringVect *strings (StringVect temp) { + $1 = &temp; +} + +%typemap(python,argout) (unsigned long *nelements, StringVect *strings) { + PyObject *tuple; + int s; + if (PyTuple_Check($result)) { + s = PyTuple_Size($result); + _PyTuple_Resize(&$result, s + 2); + tuple = $result; + } else { + tuple = PyTuple_New(3); + PyTuple_SET_ITEM(tuple, 0, $result); + Py_INCREF($result); + s = 1; + } + + int sz = *$1; + + PyTuple_SET_ITEM(tuple, s++, PyLong_FromLong(sz)); + + PyObject *r = PyList_New(sz); + for (int i = 0; i < sz; ++i) { + PyList_SET_ITEM(r, i, PyString_FromString((*$2)[i].c_str())); + } + PyTuple_SET_ITEM(tuple, s, r); + $result = tuple; +} + +namespace otk { + +%ignore Property::NUM_STRING_TYPE; +%ignore Property::initialize(); + +%rename(getNum) Property::get(Window, Atom, Atom, unsigned long*); +%rename(getNums) Property::get(Window, Atom, Atom, unsigned long*, + unsigned long**); +%rename(getString) Property::get(Window, Atom, StringType, ustring*); +%rename(getStrings) Property::get(Window, Atom, StringType, unsigned long*, + StringVect); + +} + +%include "property.hh" diff --git a/wrap/otk_rect.i b/wrap/otk_rect.i new file mode 100644 index 00000000..2ff54d94 --- /dev/null +++ b/wrap/otk_rect.i @@ -0,0 +1,13 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_rect + +%{ +#include "config.h" +#include "rect.hh" +%} + +%include "otk_point.i" +%include "otk_size.i" + +%include "rect.hh" diff --git a/wrap/otk_rendercolor.i b/wrap/otk_rendercolor.i new file mode 100644 index 00000000..04869ac2 --- /dev/null +++ b/wrap/otk_rendercolor.i @@ -0,0 +1,17 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_rendercolor + +%{ +#include "config.h" +#include "rendercolor.hh" +%} + +namespace otk { + +%ignore RenderColor::initialize(); +%ignore RenderColor::destroy(); + +} + +%include "rendercolor.hh" diff --git a/wrap/otk_renderstyle.i b/wrap/otk_renderstyle.i new file mode 100644 index 00000000..7bb4b52a --- /dev/null +++ b/wrap/otk_renderstyle.i @@ -0,0 +1,27 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_renderstyle + +%{ +#include "config.h" +#include "renderstyle.hh" +%} + +%include "std_string.i" +%include "otk_rendercolor.i" +%include "otk_rendertexture.i" +%include "otk_font.i" + +namespace otk { + +%ignore StyleNotify; + +%ignore RenderStyle::initialize(); +%ignore RenderStyle::destroy(); +%ignore RenderStyle::registerNotify(int, StyleNotify*); +%ignore RenderStyle::unregisterNotify(int, StyleNotify *); +%ignore RenderStyle::~RenderStyle(); + +} + +%include "renderstyle.hh" diff --git a/wrap/otk_rendertexture.i b/wrap/otk_rendertexture.i new file mode 100644 index 00000000..4d60f3f3 --- /dev/null +++ b/wrap/otk_rendertexture.i @@ -0,0 +1,10 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_rendertexture + +%{ +#include "config.h" +#include "rendertexture.hh" +%} + +%include "rendertexture.hh" diff --git a/wrap/otk_size.i b/wrap/otk_size.i new file mode 100644 index 00000000..0b468444 --- /dev/null +++ b/wrap/otk_size.i @@ -0,0 +1,10 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_size + +%{ +#include "config.h" +#include "size.hh" +%} + +%include "size.hh" diff --git a/wrap/otk_strut.i b/wrap/otk_strut.i new file mode 100644 index 00000000..ae005e50 --- /dev/null +++ b/wrap/otk_strut.i @@ -0,0 +1,10 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_strut + +%{ +#include "config.h" +#include "strut.hh" +%} + +%include "strut.hh" diff --git a/wrap/otk_timer.i b/wrap/otk_timer.i new file mode 100644 index 00000000..9f9eb77e --- /dev/null +++ b/wrap/otk_timer.i @@ -0,0 +1,78 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_timer + +%{ +#include "config.h" +#include "timer.hh" +%} + +%{ + struct PythonCallbackData { + PyObject *pyfunc; + void *data; + }; + + /* + Calls a python callback for the TimeoutHandler function type + */ + static void PythonCallback(PythonCallbackData *calldata) { + PyObject *arglist, *result; + + arglist = Py_BuildValue("(O)", calldata->data); + + // call the callback + result = PyEval_CallObject((PyObject*)calldata->pyfunc, arglist); + if (!result || PyErr_Occurred()) { + // an exception occured in the script, display it + PyErr_Print(); + } + + Py_XDECREF(result); + Py_DECREF(arglist); + } +%} + +// Grab a Python function object as a Python object. +%typemap(python,in) PyObject *func { + if (!PyCallable_Check($input)) { + PyErr_SetString(PyExc_TypeError, "Excepting a callable object."); + return NULL; + } + $1 = $input; +} + +namespace otk { + +%ignore Timer::Timer(long, TimeoutHandler, void*); +%ignore Timer::operator delete(void*); +%ignore Timer::initialize(); +%ignore Timer::destroy(); +%ignore Timer::dispatchTimers(bool); +%ignore Timer::nearestTimeout(struct timeval&); + +%extend Timer { + Timer(long, PyObject*, PyObject*); + + // if you don't call stop() before the object disappears, the timer will + // keep firing forever + void stop() { + delete self; + } +} + +} + +%{ + static otk::Timer *new_otk_Timer(long delay, + PyObject *func, PyObject *data) { + PythonCallbackData *d = new PythonCallbackData; + d->pyfunc = func; + d->data = data; + return new otk::Timer(delay, + (otk::Timer::TimeoutHandler)&PythonCallback, d); + // the PythonCallbackData is leaked.. XXX + } +%} + +%include "timer.hh" diff --git a/wrap/ustring.i b/wrap/otk_ustring.i similarity index 90% rename from wrap/ustring.i rename to wrap/otk_ustring.i index 06addfe2..fbd0cbfa 100644 --- a/wrap/ustring.i +++ b/wrap/otk_ustring.i @@ -1,11 +1,12 @@ -// SWIG typemaps for otk::ustring +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_rendertexture %{ #include "otk/ustring.hh" %} namespace otk { - class ustring; /* Overloading check */ @@ -36,5 +37,4 @@ namespace otk { %typemap(out) const ustring & { $result = PyString_FromString($1->c_str()); } - } diff --git a/wrap/otk_widget.i b/wrap/otk_widget.i new file mode 100644 index 00000000..a9f06b5d --- /dev/null +++ b/wrap/otk_widget.i @@ -0,0 +1,35 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk_widget + +%{ +#include "config.h" +#include "widget.hh" +%} + +%include "otk_rendercolor.i" + +%typemap(python,out) const std::list& { + std::list *v = $1; + unsigned int s = v->size(); + PyObject *l = PyList_New(s); + + std::list::const_iterator it = v->begin(), end = v->end(); + for (unsigned int i = 0; i < s; ++i, ++it) { + PyObject *pdata = SWIG_NewPointerObj((void*)*it,SWIGTYPE_p_otk__Widget,0); + PyList_SET_ITEM(l, i, pdata); + } + $result = l; +} + +namespace otk { + +%ignore Widget::exposeHandler(const XExposeEvent &); +%ignore Widget::configureHandler(const XConfigureEvent &); +%ignore Widget::styleChanged(const RenderStyle &); + +} + +%import "../otk/eventhandler.hh" +%import "../otk/renderstyle.hh" +%include "widget.hh" -- 2.39.2