/* * PypyCaca libcaca Python bindings * Copyright (c) 2006 Jean-Yves Lamoureux * All Rights Reserved * * $Id$ * * This library is free software; you can redistribute it and/or * modify it under the terms of the Do What The Fuck You Want To * Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/wtfpl/COPYING for more details. */ #include "pypycaca.h" static PyMethodDef CacaMethods[] = { {"init", pycaca_init, METH_VARARGS, "Init libcaca"}, {"set_delay", pycaca_set_delay, METH_VARARGS, "Set delay"}, {"get_rendertime", pycaca_get_rendertime, METH_NOARGS, "Get render time"}, {"get_width", pycaca_get_width, METH_NOARGS, "Get width"}, {"get_height", pycaca_get_height, METH_NOARGS, "Get Height"}, {"set_size", pycaca_set_size, METH_VARARGS, "Set size"}, {"set_width", pycaca_set_width, METH_VARARGS, "Set width"}, {"set_height", pycaca_set_height, METH_VARARGS, "Set height"}, {"set_window_title", pycaca_set_window_title, METH_VARARGS, "Set window titl"}, {"get_window_width", pycaca_get_window_width, METH_NOARGS, "Get window width"}, {"get_window_height", pycaca_get_window_height, METH_NOARGS, "Get Window height"}, {"refresh", pycaca_refresh, METH_NOARGS, "Refresh window"}, {"end", pycaca_end, METH_NOARGS, "End libcaca"}, {"get_feature", pycaca_get_feature, METH_VARARGS, "Get feature"}, {"set_feature", pycaca_set_feature, METH_VARARGS, "Set feature"}, {"get_feature_name", pycaca_get_feature_name, METH_VARARGS, "Get feature name"}, {"get_event", pycaca_get_event, METH_VARARGS, "Get event"}, {"wait_event", pycaca_wait_event, METH_VARARGS, "Wait event"}, {"get_mouse_x", pycaca_get_mouse_x, METH_NOARGS, "Get Mouse X"}, {"get_mouse_y", pycaca_get_mouse_y, METH_NOARGS, "Get mouse Y"}, {"draw_line", pycaca_draw_line, METH_VARARGS, "Init libcaca"}, {"draw_thin_line", pycaca_draw_thin_line, METH_VARARGS, "Init libcaca"}, {"draw_circle", pycaca_draw_circle, METH_VARARGS, "Init libcaca"}, {"draw_ellipse", pycaca_draw_ellipse, METH_VARARGS, "Init libcaca"}, {"draw_thin_ellipse", pycaca_draw_thin_ellipse, METH_VARARGS, "Init libcaca"}, {"fill_ellipse", pycaca_fill_ellipse, METH_VARARGS, "Init libcaca"}, {"draw_box", pycaca_draw_box, METH_VARARGS, "Init libcaca"}, {"fill_box", pycaca_fill_box, METH_VARARGS, "Init libcaca"}, {"draw_thin_box", pycaca_draw_thin_box, METH_VARARGS, "Init libcaca"}, {"draw_triangle", pycaca_draw_triangle, METH_VARARGS, "Init libcaca"}, {"draw_thin_triangle", pycaca_draw_thin_triangle, METH_VARARGS, "Init libcaca"}, {"fill_triangle", pycaca_fill_triangle, METH_VARARGS, "Init libcaca"}, {"draw_polyline", pycaca_draw_polyline, METH_VARARGS, ""}, {"draw_thin_polyline", pycaca_draw_thin_polyline, METH_VARARGS, ""}, {"set_color", pycaca_set_color, METH_VARARGS, "Init libcaca"}, {"get_fg_color", pycaca_get_fg_color, METH_VARARGS, ""}, {"get_bg_color", pycaca_get_bg_color, METH_VARARGS, ""}, {"get_color_name", pycaca_get_color_name, METH_VARARGS, ""}, {"putchar", pycaca_putchar, METH_VARARGS, ""}, {"putstr", pycaca_putstr, METH_VARARGS, ""}, {"printf", pycaca_printf, METH_VARARGS, ""}, {"clear", pycaca_clear, METH_VARARGS, ""}, {"load_sprite", pycaca_load_sprite, METH_VARARGS, ""}, {"draw_sprite", pycaca_draw_sprite, METH_VARARGS, ""}, {"get_sprite_frames", pycaca_get_sprite_frames, METH_VARARGS, ""}, {"get_sprite_width", pycaca_get_sprite_width, METH_VARARGS, ""}, {"get_sprite_height", pycaca_get_sprite_height, METH_VARARGS, ""}, {"get_sprite_dx", pycaca_get_sprite_dx, METH_VARARGS, ""}, {"get_sprite_dy", pycaca_get_sprite_dy, METH_VARARGS, ""}, {"free_sprite", pycaca_free_sprite, METH_VARARGS, ""}, {"get_html", pycaca_get_html, METH_VARARGS, ""}, {"get_html3", pycaca_get_html3, METH_VARARGS, ""}, {"get_irc", pycaca_get_irc, METH_VARARGS, ""}, {"get_ansi", pycaca_get_ansi, METH_VARARGS, ""}, {"create_bitmap", pycaca_create_bitmap, METH_VARARGS, ""}, {"set_bitmap_palette", pycaca_set_bitmap_palette, METH_VARARGS, ""}, {"set_bitmap_gamma", pycaca_set_bitmap_gamma, METH_VARARGS, ""}, {"draw_bitmap", pycaca_draw_bitmap, METH_VARARGS, ""}, {"free_bitmap", pycaca_free_bitmap, METH_VARARGS, ""}, // {"", , METH_VARARGS, ""}, {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC initcaca(void) { PyObject *obj, *dict; obj = Py_InitModule("caca", CacaMethods); dict = PyModule_GetDict(obj); SET_INTCONSTANT(dict,CACA_EVENT_NONE ); SET_INTCONSTANT(dict,CACA_EVENT_KEY_PRESS ); SET_INTCONSTANT(dict,CACA_EVENT_KEY_RELEASE ); SET_INTCONSTANT(dict,CACA_EVENT_MOUSE_PRESS ); SET_INTCONSTANT(dict,CACA_EVENT_MOUSE_RELEASE ); SET_INTCONSTANT(dict,CACA_EVENT_MOUSE_MOTION ); SET_INTCONSTANT(dict,CACA_EVENT_RESIZE ); SET_INTCONSTANT(dict,CACA_EVENT_ANY ); SET_INTCONSTANT(dict, CACA_COLOR_BLACK ); SET_INTCONSTANT(dict, CACA_COLOR_BLUE ); SET_INTCONSTANT(dict, CACA_COLOR_GREEN ); SET_INTCONSTANT(dict, CACA_COLOR_CYAN ); SET_INTCONSTANT(dict, CACA_COLOR_RED ); SET_INTCONSTANT(dict, CACA_COLOR_MAGENTA ); SET_INTCONSTANT(dict, CACA_COLOR_BROWN ); SET_INTCONSTANT(dict, CACA_COLOR_LIGHTGRAY ); SET_INTCONSTANT(dict, CACA_COLOR_DARKGRAY ); SET_INTCONSTANT(dict, CACA_COLOR_LIGHTBLUE ); SET_INTCONSTANT(dict, CACA_COLOR_LIGHTGREEN ); SET_INTCONSTANT(dict, CACA_COLOR_LIGHTCYAN ); SET_INTCONSTANT(dict, CACA_COLOR_LIGHTRED ); SET_INTCONSTANT(dict, CACA_COLOR_LIGHTMAGENTA ); SET_INTCONSTANT(dict, CACA_COLOR_YELLOW ); SET_INTCONSTANT(dict, CACA_COLOR_WHITE ); SET_INTCONSTANT(dict, CACA_BACKGROUND ); SET_INTCONSTANT(dict, CACA_BACKGROUND_BLACK ); SET_INTCONSTANT(dict, CACA_BACKGROUND_SOLID ); SET_INTCONSTANT(dict, CACA_BACKGROUND_MIN ); SET_INTCONSTANT(dict, CACA_BACKGROUND_MAX ); SET_INTCONSTANT(dict, CACA_ANTIALIASING ); SET_INTCONSTANT(dict, CACA_ANTIALIASING_NONE ); SET_INTCONSTANT(dict, CACA_ANTIALIASING_PREFILTER ); SET_INTCONSTANT(dict, CACA_ANTIALIASING_MIN ); SET_INTCONSTANT(dict, CACA_ANTIALIASING_MAX ); SET_INTCONSTANT(dict, CACA_DITHERING ); SET_INTCONSTANT(dict, CACA_DITHERING_NONE ); SET_INTCONSTANT(dict, CACA_DITHERING_ORDERED2 ); SET_INTCONSTANT(dict, CACA_DITHERING_ORDERED4 ); SET_INTCONSTANT(dict, CACA_DITHERING_ORDERED8 ); SET_INTCONSTANT(dict, CACA_DITHERING_RANDOM ); SET_INTCONSTANT(dict, CACA_DITHERING_FSTEIN ); SET_INTCONSTANT(dict, CACA_DITHERING_MIN ); SET_INTCONSTANT(dict, CACA_DITHERING_MAX ); SET_INTCONSTANT(dict, CACA_FEATURE_UNKNOWN ); SET_INTCONSTANT(dict, CACA_KEY_UNKNOWN ); SET_INTCONSTANT(dict, CACA_KEY_BACKSPACE ); SET_INTCONSTANT(dict, CACA_KEY_TAB ); SET_INTCONSTANT(dict, CACA_KEY_RETURN ); SET_INTCONSTANT(dict, CACA_KEY_PAUSE ); SET_INTCONSTANT(dict, CACA_KEY_ESCAPE ); SET_INTCONSTANT(dict, CACA_KEY_DELETE ); SET_INTCONSTANT(dict, CACA_KEY_UP ); SET_INTCONSTANT(dict, CACA_KEY_DOWN ); SET_INTCONSTANT(dict, CACA_KEY_LEFT ); SET_INTCONSTANT(dict, CACA_KEY_RIGHT ); SET_INTCONSTANT(dict, CACA_KEY_INSERT ); SET_INTCONSTANT(dict, CACA_KEY_HOME ); SET_INTCONSTANT(dict, CACA_KEY_END ); SET_INTCONSTANT(dict, CACA_KEY_PAGEUP ); SET_INTCONSTANT(dict, CACA_KEY_PAGEDOWN ); SET_INTCONSTANT(dict, CACA_KEY_F1 ); SET_INTCONSTANT(dict, CACA_KEY_F2 ); SET_INTCONSTANT(dict, CACA_KEY_F3 ); SET_INTCONSTANT(dict, CACA_KEY_F4 ); SET_INTCONSTANT(dict, CACA_KEY_F5 ); SET_INTCONSTANT(dict, CACA_KEY_F6 ); SET_INTCONSTANT(dict, CACA_KEY_F7 ); SET_INTCONSTANT(dict, CACA_KEY_F8 ); SET_INTCONSTANT(dict, CACA_KEY_F9 ); SET_INTCONSTANT(dict, CACA_KEY_F10 ); SET_INTCONSTANT(dict, CACA_KEY_F11 ); SET_INTCONSTANT(dict, CACA_KEY_F12 ); SET_INTCONSTANT(dict, CACA_KEY_F13 ); SET_INTCONSTANT(dict, CACA_KEY_F14 ); SET_INTCONSTANT(dict, CACA_KEY_F15 ); } /*******************/ /* Basic functions */ /*******************/ static PyObject * pycaca_init(PyObject *self, PyObject *args) { int ret; ret = caca_init(); return Py_BuildValue("i", ret); } static PyObject * pycaca_set_delay(PyObject *self, PyObject *args) { int value=0; if (!PyArg_ParseTuple(args, "i", &value)) caca_set_delay(value); return Py_BuildValue("i", 1); /*FIXME*/ } static PyObject * pycaca_get_rendertime(PyObject *self, PyObject *args) { int ret = caca_get_rendertime(); return Py_BuildValue("i", ret); } static PyObject * pycaca_get_width(PyObject *self, PyObject *args) { int ret = caca_get_width(); return Py_BuildValue("i", ret); } static PyObject * pycaca_get_height(PyObject *self, PyObject *args) { int ret = caca_get_height(); return Py_BuildValue("i", ret); } static PyObject * pycaca_set_size(PyObject *self, PyObject *args) { int width, height; if (!PyArg_ParseTuple(args, "ii", &width, &height)) caca_set_size(width, height); return Py_BuildValue("i", 1); /* FIXME */ } static PyObject * pycaca_set_width(PyObject *self, PyObject *args) { int width; if (!PyArg_ParseTuple(args, "i", &width)); caca_set_width(width); return Py_BuildValue("i", 1); /* FIXME */ } static PyObject * pycaca_set_height(PyObject *self, PyObject *args) { int height; if (!PyArg_ParseTuple(args, "i", &height)); caca_set_height(height); return Py_BuildValue("i", 1); /* FIXME */ } static PyObject * pycaca_set_window_title(PyObject *self, PyObject *args) { int ret; const char *str; if (!PyArg_ParseTuple(args, "s", &str)); ret = caca_set_window_title(str); return Py_BuildValue("i", ret); /* FIXME */ } static PyObject * pycaca_get_window_width(PyObject *self, PyObject *args) { int ret = caca_get_window_width(); return Py_BuildValue("i", ret); } static PyObject * pycaca_get_window_height(PyObject *self, PyObject *args) { int ret = caca_get_window_height(); return Py_BuildValue("i", ret); } static PyObject * pycaca_refresh(PyObject *self, PyObject *args) { caca_refresh(); return Py_BuildValue("i", 1); /*FIXME*/ } static PyObject * pycaca_end(PyObject *self, PyObject *args) { caca_end(); return Py_BuildValue("i", 1); /*FIXME*/ } static PyObject * pycaca_get_feature(PyObject *self, PyObject *args) { int value, ret; if (!PyArg_ParseTuple(args, "i", &value)); ret = caca_get_feature(value); return Py_BuildValue("i", ret); } static PyObject * pycaca_set_feature(PyObject *self, PyObject *args) { int value; if (!PyArg_ParseTuple(args, "i", &value)); caca_set_feature(value); return Py_BuildValue("i", 1); /* FIXME */ } static PyObject * pycaca_get_feature_name(PyObject *self, PyObject *args) { int value; char* ret; if (!PyArg_ParseTuple(args, "i", &value)); ret = (char* const)caca_get_feature_name(value); return Py_BuildValue("s", ret); } /******************/ /* Event handling */ /******************/ static PyObject * pycaca_get_event(PyObject *self, PyObject *args) { int value, ret; if (!PyArg_ParseTuple(args, "i", &value)); ret = caca_get_event(value); return Py_BuildValue("i", ret); } static PyObject * pycaca_wait_event(PyObject *self, PyObject *args) { int value, ret; if (!PyArg_ParseTuple(args, "i", &value)); ret = caca_get_event(value); return Py_BuildValue("i", ret); } static PyObject * pycaca_get_mouse_x(PyObject *self, PyObject *args) { int ret = caca_get_mouse_x(); return Py_BuildValue("i", ret); } static PyObject * pycaca_get_mouse_y(PyObject *self, PyObject *args) { int ret = caca_get_mouse_y(); return Py_BuildValue("i", ret); } /**********************/ /* Primitives drawing */ /**********************/ static PyObject * pycaca_draw_line(PyObject *self, PyObject *args) { int x1, y1, x2, y2; char c; if (!PyArg_ParseTuple(args, "iiiic", &x1,&y1,&x2,&y2,&c)); caca_draw_line(x1,y1,x2,y2,c); return Py_BuildValue("i", 1); /* FIXME */ } static PyObject * pycaca_draw_polyline(PyObject *self, PyObject *args) { PyObject *list_x, *list_y, *item; int *x, *y, n, lenx, leny, i; char c; if (!PyArg_ParseTuple(args, "OOic", &list_x, &list_y, &n, &c)); lenx = PySequence_Length(list_x); leny = PySequence_Length(list_y); x = (int*) malloc(lenx*sizeof(int)); y = (int*) malloc(leny*sizeof(int)); if((x == NULL) || (y==NULL)) return NULL; /* FIXME */ for(i=0;i