From 5869cc29ef15181427e65079d9a52c5d21190206 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 24 Dec 2002 21:27:16 +0000 Subject: [PATCH] wrap otk with swig/python --- otk/Makefile.am | 13 +++++-- otk/application.cc | 4 +-- otk/application.hh | 4 +-- otk/button.hh | 14 ++++---- otk/color.hh | 2 ++ otk/eventdispatcher.hh | 12 +++---- otk/eventhandler.hh | 2 +- otk/focuslabel.hh | 2 +- otk/focuswidget.hh | 14 ++++---- otk/image.hh | 8 +++-- otk/otk.i | 81 ++++++++++++++++++++++++++++++++++++++++++ otk/style.hh | 15 +++----- otk/texture.hh | 2 ++ otk/widget.hh | 34 +++++++++--------- 14 files changed, 149 insertions(+), 58 deletions(-) create mode 100644 otk/otk.i diff --git a/otk/Makefile.am b/otk/Makefile.am index 3f32a45e..568ade0e 100644 --- a/otk/Makefile.am +++ b/otk/Makefile.am @@ -1,4 +1,4 @@ -CPPFLAGS=$(XFT_CFLAGS) @CPPFLAGS@ +CPPFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CPPFLAGS@ INCLUDES= -I../src @@ -9,7 +9,10 @@ libotk_a_SOURCES= color.cc display.cc font.cc gccache.cc image.cc \ texture.cc timer.cc timerqueuemanager.cc style.cc \ configuration.cc util.cc widget.cc focuswidget.cc \ button.cc eventhandler.cc eventdispatcher.cc \ - label.cc focuslabel.cc application.cc appwidget.cc + label.cc focuslabel.cc application.cc appwidget.cc \ + otk_wrap.cc + +#libotk_a_LDFLAGS = $(PYTHON_LDFLAGS) MAINTAINERCLEANFILES= Makefile.in @@ -19,6 +22,12 @@ distclean-local: otk_test: libotk.a otk_test.cc $(CXX) $(CPPFLAGS) -DHAVE_CONFIG_H -I. -I. -I.. -I../src $(XFT_CFLAGS) -Wall -W -pedantic -DNDEBUG -g -O2 -o otk_test otk_test.cc $(XFT_LIBS) ./libotk.a +otk.i: $(wildcard *.hh) + touch $@ + +otk_wrap.cc: otk.i + swig -python -c++ -nodefault -o $@ $< + # local dependencies application.o: application.cc application.hh eventdispatcher.hh \ eventhandler.hh display.hh configuration.hh timerqueuemanager.hh \ diff --git a/otk/application.cc b/otk/application.cc index 70f9e24b..dedefaef 100644 --- a/otk/application.cc +++ b/otk/application.cc @@ -60,12 +60,12 @@ void OtkApplication::loadStyle(void) _style->load(*_style_conf); } -void OtkApplication::exec(void) +void OtkApplication::run(void) { if (_appwidget_count <= 0) { std::cerr << "ERROR: No main widgets exist. You must create and show() " << "an OtkAppWidget for the OtkApplication before calling " << - "OtkApplication::exec().\n"; + "OtkApplication::run().\n"; ::exit(1); } diff --git a/otk/application.hh b/otk/application.hh index 7696e73d..63fb4195 100644 --- a/otk/application.hh +++ b/otk/application.hh @@ -19,13 +19,13 @@ public: OtkApplication(int argc, char **argv); virtual ~OtkApplication(); - virtual void exec(void); + virtual void run(void); // more bummy cool functionality void setDockable(bool dockable) { _dockable = dockable; } inline bool isDockable(void) const { return _dockable; } - inline Style *getStyle(void) const { return _style; } + inline otk::Style *getStyle(void) const { return _style; } // more accessors private: diff --git a/otk/button.hh b/otk/button.hh index 5924e9b0..17ddce03 100644 --- a/otk/button.hh +++ b/otk/button.hh @@ -12,18 +12,18 @@ public: OtkButton(OtkWidget *parent); ~OtkButton(); - inline const BTexture *getPressedFocusTexture(void) const + inline const otk::BTexture *getPressedFocusTexture(void) const { return _pressed_focus_tx; } - void setPressedFocusTexture(BTexture *texture) + void setPressedFocusTexture(otk::BTexture *texture) { _pressed_focus_tx = texture; } - inline const BTexture *getPressedUnfocusTexture(void) const + inline const otk::BTexture *getPressedUnfocusTexture(void) const { return _pressed_unfocus_tx; } - void setPressedUnfocusTexture(BTexture *texture) + void setPressedUnfocusTexture(otk::BTexture *texture) { _pressed_unfocus_tx = texture; } - void setTexture(BTexture *texture); - void setUnfocusTexture(BTexture *texture); + void setTexture(otk::BTexture *texture); + void setUnfocusTexture(otk::BTexture *texture); inline bool isPressed(void) const { return _pressed; } void press(unsigned int mouse_button); @@ -32,7 +32,7 @@ public: void buttonPressHandler(const XButtonEvent &e); void buttonReleaseHandler(const XButtonEvent &e); - virtual void setStyle(Style *style); + virtual void setStyle(otk::Style *style); private: diff --git a/otk/color.hh b/otk/color.hh index 387c81bf..cbbff646 100644 --- a/otk/color.hh +++ b/otk/color.hh @@ -40,7 +40,9 @@ public: unsigned long pixel(void) const; // operators +#ifndef SWIG BColor &operator=(const BColor &c); +#endif inline bool operator==(const BColor &c) const { return (r == c.r && b == c.b && b == c.b); } inline bool operator!=(const BColor &c) const diff --git a/otk/eventdispatcher.hh b/otk/eventdispatcher.hh index 9f7fb865..a9b5af7b 100644 --- a/otk/eventdispatcher.hh +++ b/otk/eventdispatcher.hh @@ -16,21 +16,21 @@ public: virtual ~OtkEventDispatcher(); virtual void clearAllHandlers(void); - virtual void registerHandler(Window id, OtkEventHandler *handler); + virtual void registerHandler(Window id, otk::OtkEventHandler *handler); virtual void clearHandler(Window id); virtual void dispatchEvents(void); - inline void setFallbackHandler(OtkEventHandler *fallback) + inline void setFallbackHandler(otk::OtkEventHandler *fallback) { _fallback = fallback; } - OtkEventHandler *getFallbackHandler(void) const { return _fallback; } + otk::OtkEventHandler *getFallbackHandler(void) const { return _fallback; } //! Sets an event handler that gets all events for all handlers after //! any specific handlers have received them - inline void setMasterHandler(OtkEventHandler *master) + inline void setMasterHandler(otk::OtkEventHandler *master) { _master = master; } - OtkEventHandler *getMasterHandler(void) const { return _master; } + otk::OtkEventHandler *getMasterHandler(void) const { return _master; } - OtkEventHandler *findHandler(Window win); + otk::OtkEventHandler *findHandler(Window win); private: OtkEventMap _map; diff --git a/otk/eventhandler.hh b/otk/eventhandler.hh index bbc0449d..9308ed03 100644 --- a/otk/eventhandler.hh +++ b/otk/eventhandler.hh @@ -11,7 +11,7 @@ extern "C" { namespace otk { -class OtkEventHandler{ +class OtkEventHandler { public: //! Dispatches events to one of the other handlers based on their type. virtual void handle(const XEvent &e); diff --git a/otk/focuslabel.hh b/otk/focuslabel.hh index 042082eb..64b8189a 100644 --- a/otk/focuslabel.hh +++ b/otk/focuslabel.hh @@ -18,7 +18,7 @@ public: void update(void); - virtual void setStyle(Style *style); + virtual void setStyle(otk::Style *style); private: //! Object used by Xft to render to the drawable diff --git a/otk/focuswidget.hh b/otk/focuswidget.hh index 2a97c6aa..bc69ad6b 100644 --- a/otk/focuswidget.hh +++ b/otk/focuswidget.hh @@ -10,23 +10,23 @@ class OtkFocusWidget : public OtkWidget { public: - OtkFocusWidget(OtkWidget *parent, Direction = Horizontal); + OtkFocusWidget(otk::OtkWidget *parent, Direction = Horizontal); virtual ~OtkFocusWidget(); virtual void focus(void); virtual void unfocus(void); - virtual void setTexture(BTexture *texture); - virtual void setBorderColor(const BColor *color); + virtual void setTexture(otk::BTexture *texture); + virtual void setBorderColor(const otk::BColor *color); - inline void setUnfocusTexture(BTexture *texture) + inline void setUnfocusTexture(otk::BTexture *texture) { _unfocus_texture = texture; } - inline BTexture *getUnfocusTexture(void) const + inline otk::BTexture *getUnfocusTexture(void) const { return _unfocus_texture; } - inline void setUnfocusBorderColor(const BColor *color) + inline void setUnfocusBorderColor(const otk::BColor *color) { _unfocus_bcolor = color; } - inline const BColor *getUnfocusBorderColor(void) const + inline const otk::BColor *getUnfocusBorderColor(void) const { return _unfocus_bcolor; } inline bool isFocused(void) const { return _focused; } diff --git a/otk/image.hh b/otk/image.hh index 5407e522..da489323 100644 --- a/otk/image.hh +++ b/otk/image.hh @@ -68,15 +68,17 @@ public: class BImageControl { public: +#ifndef SWIG struct CachedImage { Pixmap pixmap; unsigned int count, width, height; unsigned long pixel1, pixel2, texture; }; +#endif - BImageControl(OBTimerQueueManager *timermanager, - const ScreenInfo *scrn, + BImageControl(otk::OBTimerQueueManager *timermanager, + const otk::ScreenInfo *scrn, bool _dither= False, int _cpc = 4, unsigned long cache_timeout = 300000l, unsigned long cmax = 200l); @@ -98,7 +100,7 @@ public: unsigned long getSqrt(unsigned int x); Pixmap renderImage(unsigned int width, unsigned int height, - const BTexture &texture); + const otk::BTexture &texture); void installRootColormap(void); void removeImage(Pixmap pixmap); diff --git a/otk/otk.i b/otk/otk.i new file mode 100644 index 00000000..9fcd5b6c --- /dev/null +++ b/otk/otk.i @@ -0,0 +1,81 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +%module otk + +%{ +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include "application.hh" +#include "appwidget.hh" +#include "assassin.hh" +#include "button.hh" +#include "color.hh" +#include "configuration.hh" +#include "display.hh" +#include "eventdispatcher.hh" +#include "eventhandler.hh" +#include "focuslabel.hh" +#include "focuswidget.hh" +#include "font.hh" +#include "gccache.hh" +#include "image.hh" +#include "label.hh" +#include "point.hh" +#include "property.hh" +#include "rect.hh" +#include "screeninfo.hh" +#include "strut.hh" +#include "style.hh" +#include "texture.hh" +#include "timer.hh" +#include "timerqueue.hh" +#include "timerqueuemanager.hh" +#include "util.hh" +#include "widget.hh" +%} + +%include stl.i +//%include std_list.i + +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); +} + +%include "eventdispatcher.hh" +%include "eventhandler.hh" +%include "widget.hh" +%include "focuswidget.hh" +%include "focuslabel.hh" +%include "appwidget.hh" +%include "application.hh" +%include "assassin.hh" +%include "button.hh" +%include "color.hh" +%include "configuration.hh" +%include "display.hh" +%include "font.hh" +%include "gccache.hh" +%include "image.hh" +%include "label.hh" +%include "point.hh" +%include "property.hh" +%include "rect.hh" +%include "screeninfo.hh" +%include "strut.hh" +%include "style.hh" +%include "texture.hh" +%include "timer.hh" +%include "timerqueue.hh" +%include "timerqueuemanager.hh" +%include "util.hh" diff --git a/otk/style.hh b/otk/style.hh index c0e0bbd9..ec9f3f8d 100644 --- a/otk/style.hh +++ b/otk/style.hh @@ -13,6 +13,11 @@ namespace otk { +struct PixmapMask { + Pixmap mask; + unsigned int w, h; +}; + class Style { public: @@ -23,11 +28,6 @@ public: enum TextJustify { LeftJustify = 1, RightJustify, CenterJustify }; enum BulletType { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet }; - struct PixmapMask { - Pixmap mask; - unsigned int w, h; - }; - // private: BImageControl *image_control; @@ -83,17 +83,12 @@ public: void load(const Configuration &style); - inline BColor *getBorderColor(void) { return &border_color; } - inline BColor *getTextFocus(void) { return &l_text_focus; } inline BColor *getTextUnfocus(void) { return &l_text_unfocus; } inline BColor *getButtonPicFocus(void) { return &b_pic_focus; } inline BColor *getButtonPicUnfocus(void) { return &b_pic_unfocus; } - inline BTexture *getFrameFocus(void) { return &f_focus; } - inline BTexture *getFrameUnfocus(void) { return &f_unfocus; } - inline BTexture *getTitleFocus(void) { return &t_focus; } inline BTexture *getTitleUnfocus(void) { return &t_unfocus; } diff --git a/otk/texture.hh b/otk/texture.hh index d887a337..f487f449 100644 --- a/otk/texture.hh +++ b/otk/texture.hh @@ -63,7 +63,9 @@ public: void setTexture(const unsigned long _texture) { t = _texture; } void addTexture(const unsigned long _texture) { t |= _texture; } +#ifndef SWIG BTexture &operator=(const BTexture &tt); +#endif inline bool operator==(const BTexture &tt) { return (c == tt.c && ct == tt.ct && lc == tt.lc && sc == tt.sc && t == tt.t); } diff --git a/otk/widget.hh b/otk/widget.hh index 608d8e58..fd14e57b 100644 --- a/otk/widget.hh +++ b/otk/widget.hh @@ -25,8 +25,8 @@ public: typedef std::list OtkWidgetList; - OtkWidget(OtkWidget *parent, Direction = Horizontal); - OtkWidget(OtkEventDispatcher *event_dispatcher, Style *style, + OtkWidget(otk::OtkWidget *parent, Direction = Horizontal); + OtkWidget(otk::OtkEventDispatcher *event_dispatcher, otk::Style *style, Direction direction = Horizontal, Cursor cursor = 0, int bevel_width = 1); @@ -38,12 +38,12 @@ public: void configureHandler(const XConfigureEvent &e); inline Window window(void) const { return _window; } - inline const OtkWidget *parent(void) const { return _parent; } + inline const otk::OtkWidget *parent(void) const { return _parent; } inline const OtkWidgetList &children(void) const { return _children; } inline unsigned int screen(void) const { return _screen; } - inline const Rect &rect(void) const { return _rect; } + inline const otk::Rect &rect(void) const { return _rect; } - void move(const Point &to); + void move(const otk::Point &to); void move(int x, int y); virtual void setWidth(int); @@ -52,11 +52,11 @@ public: virtual int width() const { return _rect.width(); } virtual int height() const { return _rect.height(); } - virtual void resize(const Point &to); + virtual void resize(const otk::Point &to); virtual void resize(int x, int y); - virtual void setGeometry(const Rect &new_geom); - virtual void setGeometry(const Point &topleft, int width, int height); + virtual void setGeometry(const otk::Rect &new_geom); + virtual void setGeometry(const otk::Point &topleft, int width, int height); virtual void setGeometry(int x, int y, int width, int height); inline bool isVisible(void) const { return _visible; }; @@ -75,12 +75,12 @@ public: bool grabKeyboard(void); void ungrabKeyboard(void); - inline BTexture *texture(void) const { return _texture; } - virtual void setTexture(BTexture *texture) + inline otk::BTexture *texture(void) const { return _texture; } + virtual void setTexture(otk::BTexture *texture) { _texture = texture; _dirty = true; } - inline const BColor *borderColor(void) const { return _bcolor; } - virtual void setBorderColor(const BColor *color) { + inline const otk::BColor *borderColor(void) const { return _bcolor; } + virtual void setBorderColor(const otk::BColor *color) { assert(color); _bcolor = color; XSetWindowBorder(OBDisplay::display, _window, color->pixel()); } @@ -88,7 +88,7 @@ public: inline int borderWidth(void) const { return _bwidth; } void setBorderWidth(int width) { _bwidth = width; - XSetWindowBorderWidth(OBDisplay::display, _window, width); + XSetWindowBorderWidth(otk::OBDisplay::display, _window, width); } virtual void addChild(OtkWidget *child, bool front = false); @@ -113,12 +113,12 @@ public: inline Direction direction(void) const { return _direction; } void setDirection(Direction dir) { _direction = dir; } - inline Style *style(void) const { return _style; } - virtual void setStyle(Style *style); + inline otk::Style *style(void) const { return _style; } + virtual void setStyle(otk::Style *style); - inline OtkEventDispatcher *eventDispatcher(void) + inline otk::OtkEventDispatcher *eventDispatcher(void) { return _event_dispatcher; } - void setEventDispatcher(OtkEventDispatcher *disp); + void setEventDispatcher(otk::OtkEventDispatcher *disp); void unmanaged(void) { _unmanaged = true; } -- 2.45.2