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
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 $@ $<
%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"
#include "bindings.hh"
#include "otk/display.hh"
#include "otk/screeninfo.hh"
+#include "otk/util.hh"
void set_reset_key(const std::string &key)
{
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+%module ob_callback
+
%include "std_string.i"
%{
PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
return false;
}
- Py_INCREF(func);
+ Py_INCREF(func); // the func is never decreffed... XXX
return true;
}
PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
return false;
}
- Py_INCREF(func);
+ Py_INCREF(func); // the func is never decreffed... XXX
return true;
}
PyErr_SetString(PyExc_RuntimeError,"Unable to grab keybaord.");
return false;
}
- Py_INCREF(func);
+ Py_INCREF(func); // the func is never decreffed... XXX
return true;
}
PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
return false;
}
- Py_INCREF(func);
+ Py_INCREF(func); // the func is never decreffed... XXX
return true;
}
#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 {
}
+%import "../otk/eventdispatcher.hh"
%include "openbox.hh"
%}
%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<ob::Client*> {
unsigned int s = $1.size();
$result = l;
}
-%typemap(python,out) const otk::Property::StringVect& {
- otk::Property::StringVect *v = $1;
+%typemap(python,out) const std::vector<otk::Rect>& {
+ std::vector<otk::Rect> *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<otk::Rect>::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;
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<otk::Rect> &xineramaAreas() {
+ return otk::display->screenInfo(self->number())->xineramaAreas();
+ }
+
+ Window rootWindow() {
+ return otk::display->screenInfo(self->number())->rootWindow();
+ }
}
%immutable Screen::clients;
%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):
--- /dev/null
+// -*- 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"
--- /dev/null
+// -*- 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"
--- /dev/null
+// -*- 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"
--- /dev/null
+// -*- 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"
--- /dev/null
+// -*- 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"
--- /dev/null
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+
+%module otk_point
+
+%{
+#include "config.h"
+#include "point.hh"
+%}
+
+%include "point.hh"
--- /dev/null
+// -*- 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"
--- /dev/null
+// -*- 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"
--- /dev/null
+// -*- 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"
--- /dev/null
+// -*- 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"
--- /dev/null
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+
+%module otk_rendertexture
+
+%{
+#include "config.h"
+#include "rendertexture.hh"
+%}
+
+%include "rendertexture.hh"
--- /dev/null
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+
+%module otk_size
+
+%{
+#include "config.h"
+#include "size.hh"
+%}
+
+%include "size.hh"
--- /dev/null
+// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
+
+%module otk_strut
+
+%{
+#include "config.h"
+#include "strut.hh"
+%}
+
+%include "strut.hh"
--- /dev/null
+// -*- 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"
-// 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 */
%typemap(out) const ustring & {
$result = PyString_FromString($1->c_str());
}
-
}
--- /dev/null
+// -*- 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<Widget*>& {
+ std::list<Widget*> *v = $1;
+ unsigned int s = v->size();
+ PyObject *l = PyList_New(s);
+
+ std::list<Widget*>::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"