wrap otk with swig/python

This commit is contained in:
Dana Jansens 2002-12-24 21:27:16 +00:00
parent 2e273ae3ac
commit 5869cc29ef
14 changed files with 149 additions and 58 deletions

View file

@ -1,4 +1,4 @@
CPPFLAGS=$(XFT_CFLAGS) @CPPFLAGS@ CPPFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CPPFLAGS@
INCLUDES= -I../src 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 \ texture.cc timer.cc timerqueuemanager.cc style.cc \
configuration.cc util.cc widget.cc focuswidget.cc \ configuration.cc util.cc widget.cc focuswidget.cc \
button.cc eventhandler.cc eventdispatcher.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 MAINTAINERCLEANFILES= Makefile.in
@ -19,6 +22,12 @@ distclean-local:
otk_test: libotk.a otk_test.cc 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 $(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 # local dependencies
application.o: application.cc application.hh eventdispatcher.hh \ application.o: application.cc application.hh eventdispatcher.hh \
eventhandler.hh display.hh configuration.hh timerqueuemanager.hh \ eventhandler.hh display.hh configuration.hh timerqueuemanager.hh \

View file

@ -60,12 +60,12 @@ void OtkApplication::loadStyle(void)
_style->load(*_style_conf); _style->load(*_style_conf);
} }
void OtkApplication::exec(void) void OtkApplication::run(void)
{ {
if (_appwidget_count <= 0) { if (_appwidget_count <= 0) {
std::cerr << "ERROR: No main widgets exist. You must create and show() " << std::cerr << "ERROR: No main widgets exist. You must create and show() " <<
"an OtkAppWidget for the OtkApplication before calling " << "an OtkAppWidget for the OtkApplication before calling " <<
"OtkApplication::exec().\n"; "OtkApplication::run().\n";
::exit(1); ::exit(1);
} }

View file

@ -19,13 +19,13 @@ public:
OtkApplication(int argc, char **argv); OtkApplication(int argc, char **argv);
virtual ~OtkApplication(); virtual ~OtkApplication();
virtual void exec(void); virtual void run(void);
// more bummy cool functionality // more bummy cool functionality
void setDockable(bool dockable) { _dockable = dockable; } void setDockable(bool dockable) { _dockable = dockable; }
inline bool isDockable(void) const { return _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 // more accessors
private: private:

View file

@ -12,18 +12,18 @@ public:
OtkButton(OtkWidget *parent); OtkButton(OtkWidget *parent);
~OtkButton(); ~OtkButton();
inline const BTexture *getPressedFocusTexture(void) const inline const otk::BTexture *getPressedFocusTexture(void) const
{ return _pressed_focus_tx; } { return _pressed_focus_tx; }
void setPressedFocusTexture(BTexture *texture) void setPressedFocusTexture(otk::BTexture *texture)
{ _pressed_focus_tx = texture; } { _pressed_focus_tx = texture; }
inline const BTexture *getPressedUnfocusTexture(void) const inline const otk::BTexture *getPressedUnfocusTexture(void) const
{ return _pressed_unfocus_tx; } { return _pressed_unfocus_tx; }
void setPressedUnfocusTexture(BTexture *texture) void setPressedUnfocusTexture(otk::BTexture *texture)
{ _pressed_unfocus_tx = texture; } { _pressed_unfocus_tx = texture; }
void setTexture(BTexture *texture); void setTexture(otk::BTexture *texture);
void setUnfocusTexture(BTexture *texture); void setUnfocusTexture(otk::BTexture *texture);
inline bool isPressed(void) const { return _pressed; } inline bool isPressed(void) const { return _pressed; }
void press(unsigned int mouse_button); void press(unsigned int mouse_button);
@ -32,7 +32,7 @@ public:
void buttonPressHandler(const XButtonEvent &e); void buttonPressHandler(const XButtonEvent &e);
void buttonReleaseHandler(const XButtonEvent &e); void buttonReleaseHandler(const XButtonEvent &e);
virtual void setStyle(Style *style); virtual void setStyle(otk::Style *style);
private: private:

View file

@ -40,7 +40,9 @@ public:
unsigned long pixel(void) const; unsigned long pixel(void) const;
// operators // operators
#ifndef SWIG
BColor &operator=(const BColor &c); BColor &operator=(const BColor &c);
#endif
inline bool operator==(const BColor &c) const inline bool operator==(const BColor &c) const
{ return (r == c.r && b == c.b && b == c.b); } { return (r == c.r && b == c.b && b == c.b); }
inline bool operator!=(const BColor &c) const inline bool operator!=(const BColor &c) const

View file

@ -16,21 +16,21 @@ public:
virtual ~OtkEventDispatcher(); virtual ~OtkEventDispatcher();
virtual void clearAllHandlers(void); 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 clearHandler(Window id);
virtual void dispatchEvents(void); virtual void dispatchEvents(void);
inline void setFallbackHandler(OtkEventHandler *fallback) inline void setFallbackHandler(otk::OtkEventHandler *fallback)
{ _fallback = 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 //! Sets an event handler that gets all events for all handlers after
//! any specific handlers have received them //! any specific handlers have received them
inline void setMasterHandler(OtkEventHandler *master) inline void setMasterHandler(otk::OtkEventHandler *master)
{ _master = 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: private:
OtkEventMap _map; OtkEventMap _map;

View file

@ -18,7 +18,7 @@ public:
void update(void); void update(void);
virtual void setStyle(Style *style); virtual void setStyle(otk::Style *style);
private: private:
//! Object used by Xft to render to the drawable //! Object used by Xft to render to the drawable

View file

@ -10,23 +10,23 @@ class OtkFocusWidget : public OtkWidget {
public: public:
OtkFocusWidget(OtkWidget *parent, Direction = Horizontal); OtkFocusWidget(otk::OtkWidget *parent, Direction = Horizontal);
virtual ~OtkFocusWidget(); virtual ~OtkFocusWidget();
virtual void focus(void); virtual void focus(void);
virtual void unfocus(void); virtual void unfocus(void);
virtual void setTexture(BTexture *texture); virtual void setTexture(otk::BTexture *texture);
virtual void setBorderColor(const BColor *color); virtual void setBorderColor(const otk::BColor *color);
inline void setUnfocusTexture(BTexture *texture) inline void setUnfocusTexture(otk::BTexture *texture)
{ _unfocus_texture = texture; } { _unfocus_texture = texture; }
inline BTexture *getUnfocusTexture(void) const inline otk::BTexture *getUnfocusTexture(void) const
{ return _unfocus_texture; } { return _unfocus_texture; }
inline void setUnfocusBorderColor(const BColor *color) inline void setUnfocusBorderColor(const otk::BColor *color)
{ _unfocus_bcolor = color; } { _unfocus_bcolor = color; }
inline const BColor *getUnfocusBorderColor(void) const inline const otk::BColor *getUnfocusBorderColor(void) const
{ return _unfocus_bcolor; } { return _unfocus_bcolor; }
inline bool isFocused(void) const { return _focused; } inline bool isFocused(void) const { return _focused; }

View file

@ -68,15 +68,17 @@ public:
class BImageControl { class BImageControl {
public: public:
#ifndef SWIG
struct CachedImage { struct CachedImage {
Pixmap pixmap; Pixmap pixmap;
unsigned int count, width, height; unsigned int count, width, height;
unsigned long pixel1, pixel2, texture; unsigned long pixel1, pixel2, texture;
}; };
#endif
BImageControl(OBTimerQueueManager *timermanager, BImageControl(otk::OBTimerQueueManager *timermanager,
const ScreenInfo *scrn, const otk::ScreenInfo *scrn,
bool _dither= False, int _cpc = 4, bool _dither= False, int _cpc = 4,
unsigned long cache_timeout = 300000l, unsigned long cache_timeout = 300000l,
unsigned long cmax = 200l); unsigned long cmax = 200l);
@ -98,7 +100,7 @@ public:
unsigned long getSqrt(unsigned int x); unsigned long getSqrt(unsigned int x);
Pixmap renderImage(unsigned int width, unsigned int height, Pixmap renderImage(unsigned int width, unsigned int height,
const BTexture &texture); const otk::BTexture &texture);
void installRootColormap(void); void installRootColormap(void);
void removeImage(Pixmap pixmap); void removeImage(Pixmap pixmap);

81
otk/otk.i Normal file
View file

@ -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"

View file

@ -13,6 +13,11 @@
namespace otk { namespace otk {
struct PixmapMask {
Pixmap mask;
unsigned int w, h;
};
class Style { class Style {
public: public:
@ -23,11 +28,6 @@ public:
enum TextJustify { LeftJustify = 1, RightJustify, CenterJustify }; enum TextJustify { LeftJustify = 1, RightJustify, CenterJustify };
enum BulletType { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet }; enum BulletType { RoundBullet = 1, TriangleBullet, SquareBullet, NoBullet };
struct PixmapMask {
Pixmap mask;
unsigned int w, h;
};
// private: // private:
BImageControl *image_control; BImageControl *image_control;
@ -83,17 +83,12 @@ public:
void load(const Configuration &style); void load(const Configuration &style);
inline BColor *getBorderColor(void) { return &border_color; }
inline BColor *getTextFocus(void) { return &l_text_focus; } inline BColor *getTextFocus(void) { return &l_text_focus; }
inline BColor *getTextUnfocus(void) { return &l_text_unfocus; } inline BColor *getTextUnfocus(void) { return &l_text_unfocus; }
inline BColor *getButtonPicFocus(void) { return &b_pic_focus; } inline BColor *getButtonPicFocus(void) { return &b_pic_focus; }
inline BColor *getButtonPicUnfocus(void) { return &b_pic_unfocus; } 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 *getTitleFocus(void) { return &t_focus; }
inline BTexture *getTitleUnfocus(void) { return &t_unfocus; } inline BTexture *getTitleUnfocus(void) { return &t_unfocus; }

View file

@ -63,7 +63,9 @@ public:
void setTexture(const unsigned long _texture) { t = _texture; } void setTexture(const unsigned long _texture) { t = _texture; }
void addTexture(const unsigned long _texture) { t |= _texture; } void addTexture(const unsigned long _texture) { t |= _texture; }
#ifndef SWIG
BTexture &operator=(const BTexture &tt); BTexture &operator=(const BTexture &tt);
#endif
inline bool operator==(const BTexture &tt) inline bool operator==(const BTexture &tt)
{ return (c == tt.c && ct == tt.ct && lc == tt.lc && { return (c == tt.c && ct == tt.ct && lc == tt.lc &&
sc == tt.sc && t == tt.t); } sc == tt.sc && t == tt.t); }

View file

@ -25,8 +25,8 @@ public:
typedef std::list<OtkWidget *> OtkWidgetList; typedef std::list<OtkWidget *> OtkWidgetList;
OtkWidget(OtkWidget *parent, Direction = Horizontal); OtkWidget(otk::OtkWidget *parent, Direction = Horizontal);
OtkWidget(OtkEventDispatcher *event_dispatcher, Style *style, OtkWidget(otk::OtkEventDispatcher *event_dispatcher, otk::Style *style,
Direction direction = Horizontal, Cursor cursor = 0, Direction direction = Horizontal, Cursor cursor = 0,
int bevel_width = 1); int bevel_width = 1);
@ -38,12 +38,12 @@ public:
void configureHandler(const XConfigureEvent &e); void configureHandler(const XConfigureEvent &e);
inline Window window(void) const { return _window; } 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 const OtkWidgetList &children(void) const { return _children; }
inline unsigned int screen(void) const { return _screen; } 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); void move(int x, int y);
virtual void setWidth(int); virtual void setWidth(int);
@ -52,11 +52,11 @@ public:
virtual int width() const { return _rect.width(); } virtual int width() const { return _rect.width(); }
virtual int height() const { return _rect.height(); } 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 resize(int x, int y);
virtual void setGeometry(const Rect &new_geom); virtual void setGeometry(const otk::Rect &new_geom);
virtual void setGeometry(const Point &topleft, int width, int height); virtual void setGeometry(const otk::Point &topleft, int width, int height);
virtual void setGeometry(int x, int y, int width, int height); virtual void setGeometry(int x, int y, int width, int height);
inline bool isVisible(void) const { return _visible; }; inline bool isVisible(void) const { return _visible; };
@ -75,12 +75,12 @@ public:
bool grabKeyboard(void); bool grabKeyboard(void);
void ungrabKeyboard(void); void ungrabKeyboard(void);
inline BTexture *texture(void) const { return _texture; } inline otk::BTexture *texture(void) const { return _texture; }
virtual void setTexture(BTexture *texture) virtual void setTexture(otk::BTexture *texture)
{ _texture = texture; _dirty = true; } { _texture = texture; _dirty = true; }
inline const BColor *borderColor(void) const { return _bcolor; } inline const otk::BColor *borderColor(void) const { return _bcolor; }
virtual void setBorderColor(const BColor *color) { virtual void setBorderColor(const otk::BColor *color) {
assert(color); _bcolor = color; assert(color); _bcolor = color;
XSetWindowBorder(OBDisplay::display, _window, color->pixel()); XSetWindowBorder(OBDisplay::display, _window, color->pixel());
} }
@ -88,7 +88,7 @@ public:
inline int borderWidth(void) const { return _bwidth; } inline int borderWidth(void) const { return _bwidth; }
void setBorderWidth(int width) { void setBorderWidth(int width) {
_bwidth = width; _bwidth = width;
XSetWindowBorderWidth(OBDisplay::display, _window, width); XSetWindowBorderWidth(otk::OBDisplay::display, _window, width);
} }
virtual void addChild(OtkWidget *child, bool front = false); virtual void addChild(OtkWidget *child, bool front = false);
@ -113,12 +113,12 @@ public:
inline Direction direction(void) const { return _direction; } inline Direction direction(void) const { return _direction; }
void setDirection(Direction dir) { _direction = dir; } void setDirection(Direction dir) { _direction = dir; }
inline Style *style(void) const { return _style; } inline otk::Style *style(void) const { return _style; }
virtual void setStyle(Style *style); virtual void setStyle(otk::Style *style);
inline OtkEventDispatcher *eventDispatcher(void) inline otk::OtkEventDispatcher *eventDispatcher(void)
{ return _event_dispatcher; } { return _event_dispatcher; }
void setEventDispatcher(OtkEventDispatcher *disp); void setEventDispatcher(otk::OtkEventDispatcher *disp);
void unmanaged(void) { _unmanaged = true; } void unmanaged(void) { _unmanaged = true; }