rming almost all the old python stuffs

This commit is contained in:
Dana Jansens 2003-03-17 22:04:20 +00:00
parent 75b07a2bb3
commit df3d926cb2
10 changed files with 0 additions and 2084 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,19 +0,0 @@
#ifndef __clientwrap_h
#define __clientwrap_h
#include <Python.h>
struct Client;
/* ClientWrap is a PyObject */
typedef struct ClientWrap {
PyObject_HEAD
struct Client *client;
} ClientWrap;
void clientwrap_startup();
void clientwrap_shutdown();
PyObject *clientwrap_new(struct Client *client);
#endif

View file

@ -1,80 +0,0 @@
#include <Python.h>
#include <glib.h>
/* This simply wraps the config.py module so that it can be accessed from the
C code.
*/
static PyObject *add, *get, *set, *reset;
void configwrap_startup()
{
PyObject *c, *cdict;
/* get the ob module/dict */
c = PyImport_ImportModule("config"); /* new */
g_assert(c != NULL);
cdict = PyModule_GetDict(c); /* borrowed */
g_assert(cdict != NULL);
/* get the functions */
add = PyDict_GetItemString(cdict, "add");
g_assert(add != NULL);
get = PyDict_GetItemString(cdict, "get");
g_assert(get != NULL);
set = PyDict_GetItemString(cdict, "set");
g_assert(set != NULL);
reset = PyDict_GetItemString(cdict, "reset");
g_assert(reset != NULL);
Py_DECREF(c);
}
void configwrap_shutdown()
{
Py_DECREF(get);
Py_DECREF(set);
Py_DECREF(reset);
Py_DECREF(add);
}
void configwrap_add_int(char *modname, char *varname, char *friendname,
char *description, int defvalue)
{
PyObject *r;
r= PyObject_CallFunction(add, "sssssi", modname, varname,
friendname, description, "integer", defvalue);
g_assert(r != NULL);
Py_DECREF(r);
}
int configwrap_get_int(char *modname, char *varname)
{
PyObject *r;
int i;
r = PyObject_CallFunction(get, "ss", modname, varname);
g_assert(r != NULL);
i = PyInt_AsLong(r);
Py_DECREF(r);
return i;
}
void configwrap_set_int(char *modname, char *varname, int value)
{
PyObject *r;
r = PyObject_CallFunction(set, "ssi", modname, varname, value);
g_assert(r != NULL);
Py_DECREF(r);
}
void configwrap_reset(char *modname, char *varname)
{
PyObject *r;
r = PyObject_CallFunction(reset, "ss", modname, varname);
g_assert(r != NULL);
Py_DECREF(r);
}

View file

@ -1,15 +0,0 @@
#ifndef __configwrap_h
#define __configwrap_h
void configwrap_startup();
void configwrap_shutdown();
void configwrap_add_int(char *modname, char *varname, char *friendname,
char *description, int defvalue);
int configwrap_get_int(char *modname, char *varname);
void configwrap_set_int(char *modname, char *varname, int value);
void configwrap_reset(char *modname, char *varname);
#endif

View file

@ -1,296 +0,0 @@
#include "hooks.h"
#include <glib.h>
/*
*
* Define the 'Hook' class type
*
*/
#define IS_HOOK(v) ((v)->ob_type == &HookType)
staticforward PyTypeObject HookType;
typedef struct HookObject {
PyObject_HEAD
GSList *funcs;
} HookObject;
static int hook_init(HookObject *self, PyObject *args, PyObject *kwds)
{
char *keywords[] = { 0 };
if (!PyArg_ParseTupleAndKeywords(args, kwds, ":__init__", keywords))
return -1;
self->funcs = NULL;
return 0;
}
static void hook_dealloc(HookObject *self)
{
GSList *it;
for (it = self->funcs; it != NULL; it = it->next)
Py_DECREF((PyObject*) it->data);
PyObject_Del((PyObject*) self);
}
static PyObject *hook_fire(HookObject *self, PyObject *args)
{
GSList *it;
if (!IS_HOOK(self)) {
PyErr_SetString(PyExc_TypeError,
"descriptor 'fire' requires a 'Hook' object");
return NULL;
}
for (it = self->funcs; it != NULL; it = it->next) {
PyObject *ret = PyObject_CallObject(it->data, args);
if (ret == NULL)
return NULL;
Py_DECREF(ret);
}
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *hook_append(HookObject *self, PyObject *args)
{
PyObject *func;
if (!IS_HOOK(self)) {
PyErr_SetString(PyExc_TypeError,
"descriptor 'append' requires a 'Hook' object");
return NULL;
}
if (!PyArg_ParseTuple(args, "O:append", &func))
return NULL;
if (!PyCallable_Check(func)) {
PyErr_SetString(PyExc_TypeError,
"descriptor 'append' requires a callable argument");
return NULL;
}
self->funcs = g_slist_append(self->funcs, func);
Py_INCREF(func);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *hook_remove(HookObject *self, PyObject *args)
{
PyObject *func;
GSList *it;
if (!IS_HOOK(self)) {
PyErr_SetString(PyExc_TypeError,
"descriptor 'remove' requires a 'Hook' object");
return NULL;
}
if (!PyArg_ParseTuple(args, "O:remove", &func))
return NULL;
if (!PyCallable_Check(func)) {
PyErr_SetString(PyExc_TypeError,
"descriptor 'remove' requires a callable argument");
return NULL;
}
it = g_slist_find(self->funcs, func);
if (it != NULL) {
self->funcs = g_slist_delete_link(self->funcs, it);
Py_DECREF(func);
Py_INCREF(Py_None);
return Py_None;
}
PyErr_SetString(PyExc_TypeError,
"given callable object was not found in Hook");
return NULL;
}
static PyObject *hook_call(HookObject *self, PyObject *args)
{
PyObject *ret;
GSList *it, *next;
gboolean stop = FALSE;
if (!IS_HOOK(self)) {
PyErr_SetString(PyExc_TypeError,
"descriptor '__call__' requires a 'Hook' object");
return NULL;
}
for (it = self->funcs; !stop && it != NULL;) {
next = it->next; /* incase the hook removes itself */
ret = PyObject_CallObject(it->data, args);
if (ret == NULL)
return NULL;
if (ret != Py_None)
stop = TRUE;
Py_DECREF(ret);
it = next;
}
Py_INCREF(Py_None);
return Py_None;
}
static PyTypeObject HookType = {
PyObject_HEAD_INIT(NULL)
0,
"Hook",
sizeof(HookObject),
0,
(destructor) hook_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
};
static PyMethodDef HookMethods[] = {
{"append", (PyCFunction)hook_append, METH_VARARGS,
"hook.add(func) -- Add a function to the hook." },
{"remove", (PyCFunction)hook_remove, METH_VARARGS,
"hook.remove(func) -- Remove a function from the hook." },
{ NULL, NULL, 0, NULL }
};
/*
*
* Module initialization/finalization
*
*/
static PyObject *hooks, *hooksdict;
static PyMethodDef HooksMethods[] = {
{ NULL, NULL, 0, NULL }
};
struct HookObject *hooks_create(char *name)
{
HookObject *hook;
int ret;
hook = PyObject_New(HookObject, &HookType);
hook->funcs = NULL;
/* add it to the hooks module */
ret = PyDict_SetItemString(hooksdict, name, (PyObject*) hook);
g_assert(ret != -1);
return hook;
}
void hooks_startup()
{
HookType.ob_type = &PyType_Type;
HookType.tp_methods = HookMethods;
HookType.tp_alloc = PyType_GenericAlloc;
HookType.tp_new = PyType_GenericNew;
HookType.tp_init = (initproc) hook_init;
HookType.tp_call = (ternaryfunc) hook_call;
PyType_Ready(&HookType);
Py_InitModule("hooks", HooksMethods);
/* get the hooks module/dict */
hooks = PyImport_ImportModule("hooks"); /* new */
g_assert(hooks != NULL);
hooksdict = PyModule_GetDict(hooks); /* borrowed */
g_assert(hooksdict != NULL);
/* add the Hook type to the hooks module */
PyDict_SetItemString(hooksdict, "Hook", (PyObject*) &HookType);
hook_startup = hooks_create("startup");
hook_shutdown = hooks_create("shutdown");
hook_visibledesktop = hooks_create("visibledesktop");
hook_numdesktops = hooks_create("numdesktops");
hook_desktopnames = hooks_create("desktopnames");
hook_showdesktop = hooks_create("showdesktop");
hook_screenconfiguration = hooks_create("screenconfiguration");
hook_screenarea = hooks_create("screenarea");
hook_managed = hooks_create("managed");
hook_closed = hooks_create("closed");
hook_bell = hooks_create("bell");
hook_urgent = hooks_create("urgent");
hook_pointerenter = hooks_create("pointerenter");
hook_pointerleave = hooks_create("pointerleave");
hook_focused = hooks_create("focused");
hook_requestactivate = hooks_create("requestactivate");
hook_title = hooks_create("title");
hook_desktop = hooks_create("desktop");
hook_iconic = hooks_create("iconic");
hook_shaded = hooks_create("shaded");
hook_maximized = hooks_create("maximized");
hook_fullscreen = hooks_create("fullscreen");
hook_visible = hooks_create("visible");
hook_configuration = hooks_create("configuration");
}
void hooks_shutdown()
{
Py_DECREF(hook_startup);
Py_DECREF(hook_shutdown);
Py_DECREF(hook_visibledesktop);
Py_DECREF(hook_numdesktops);
Py_DECREF(hook_desktopnames);
Py_DECREF(hook_showdesktop);
Py_DECREF(hook_screenconfiguration);
Py_DECREF(hook_screenarea);
Py_DECREF(hook_managed);
Py_DECREF(hook_closed);
Py_DECREF(hook_bell);
Py_DECREF(hook_urgent);
Py_DECREF(hook_pointerenter);
Py_DECREF(hook_pointerleave);
Py_DECREF(hook_focused);
Py_DECREF(hook_requestactivate);
Py_DECREF(hook_title);
Py_DECREF(hook_desktop);
Py_DECREF(hook_iconic);
Py_DECREF(hook_shaded);
Py_DECREF(hook_maximized);
Py_DECREF(hook_fullscreen);
Py_DECREF(hook_visible);
Py_DECREF(hook_configuration);
Py_DECREF(hooks);
}
void hooks_fire(struct HookObject *hook, PyObject *args)
{
PyObject *ret = hook_call(hook, args);
if (ret == NULL)
PyErr_Print();
Py_XDECREF(ret);
}
void hooks_fire_client(struct HookObject *hook, struct Client *client)
{
PyObject *args;
if (client != NULL) {
PyObject *c = clientwrap_new(client);
g_assert(c != NULL);
args = Py_BuildValue("(O)", c);
Py_DECREF(c);
} else {
args = Py_BuildValue("(O)", Py_None);
}
g_assert(args != NULL);
hooks_fire(hook, args);
Py_DECREF(args);
}

View file

@ -1,56 +0,0 @@
#ifndef __hooks_h
#define __hooks_h
#include "clientwrap.h"
#include <Python.h>
void hooks_startup();
void hooks_shutdown();
struct HookObject;
struct HookObject *hooks_create(char *name);
struct HookObject *hook_startup;
struct HookObject *hook_shutdown;
struct HookObject *hook_visibledesktop;
struct HookObject *hook_numdesktops;
struct HookObject *hook_desktopnames;
struct HookObject *hook_showdesktop;
struct HookObject *hook_screenconfiguration;
struct HookObject *hook_screenarea;
struct HookObject *hook_managed;
struct HookObject *hook_closed;
struct HookObject *hook_bell;
struct HookObject *hook_urgent;
struct HookObject *hook_pointerenter;
struct HookObject *hook_pointerleave;
struct HookObject *hook_focused;
struct HookObject *hook_requestactivate;
struct HookObject *hook_title;
struct HookObject *hook_desktop;
struct HookObject *hook_iconic;
struct HookObject *hook_shaded;
struct HookObject *hook_maximized;
struct HookObject *hook_fullscreen;
struct HookObject *hook_visible;
struct HookObject *hook_configuration;
#define HOOKFIRE(hook, ...) \
{ \
PyObject *args = Py_BuildValue(__VA_ARGS__); \
g_assert(args != NULL); \
hooks_fire(hook_##hook, args); \
Py_DECREF(args); \
}
#define HOOKFIRECLIENT(hook, client) \
{ \
hooks_fire_client(hook_##hook, client); \
}
void hooks_fire(struct HookObject *hook, PyObject *args);
void hooks_fire_client(struct HookObject *hook, struct Client *client);
#endif

View file

@ -1,502 +0,0 @@
#include "openboxwrap.h"
#include "openbox.h"
#include "screen.h"
#include "prop.h"
/***************************************************************************
Define the type 'OpenboxWrap'
***************************************************************************/
#define IS_OWRAP(v) ((v)->ob_type == &OpenboxWrapType)
#define CHECK_OWRAP(self, funcname) { \
if (!IS_OWRAP(self)) { \
PyErr_SetString(PyExc_TypeError, \
"descriptor '" funcname "' requires a 'Openbox' " \
"object"); \
return NULL; \
} \
}
staticforward PyTypeObject OpenboxWrapType;
/***************************************************************************
Attribute methods
***************************************************************************/
static PyObject *owrap_shutdown(OpenboxWrap *self, PyObject *args)
{
CHECK_OWRAP(self, "shutdown");
if (!PyArg_ParseTuple(args, ":shutdown"))
return NULL;
ob_shutdown = TRUE;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *owrap_restart(OpenboxWrap *self, PyObject *args)
{
char *path = NULL;
CHECK_OWRAP(self, "restart");
if (!PyArg_ParseTuple(args, "|s:restart", &path))
return NULL;
ob_shutdown = ob_restart = TRUE;
ob_restart_path = path;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *owrap_state(OpenboxWrap *self, PyObject *args)
{
CHECK_OWRAP(self, "state");
if (!PyArg_ParseTuple(args, ":state"))
return NULL;
return PyInt_FromLong(ob_state);
}
static PyObject *owrap_desktop(OpenboxWrap *self, PyObject *args)
{
CHECK_OWRAP(self, "desktop");
if (!PyArg_ParseTuple(args, ":desktop"))
return NULL;
return PyInt_FromLong(screen_desktop);
}
static PyObject *owrap_setDesktop(OpenboxWrap *self, PyObject *args)
{
int desktop;
CHECK_OWRAP(self, "setDesktop");
if (!PyArg_ParseTuple(args, "i:setDesktop", &desktop))
return NULL;
if (desktop < 0 || (unsigned)desktop >= screen_num_desktops) {
PyErr_SetString(PyExc_ValueError, "invalid desktop");
return NULL;
}
screen_set_desktop(desktop);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *owrap_setNextDesktop(OpenboxWrap *self, PyObject *args)
{
gboolean wrap = TRUE;
guint d;
CHECK_OWRAP(self, "setNextDesktop");
if (!PyArg_ParseTuple(args, "|i:setNextDesktop", &wrap))
return NULL;
d = screen_desktop + 1;
if (d >= screen_num_desktops && wrap)
d = 0;
if (d < screen_num_desktops)
screen_set_desktop(d);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *owrap_setPreviousDesktop(OpenboxWrap *self, PyObject *args)
{
gboolean wrap = TRUE;
guint d;
CHECK_OWRAP(self, "setPreviousDesktop");
if (!PyArg_ParseTuple(args, "|i:setPreviousDesktop", &wrap))
return NULL;
d = screen_desktop - 1;
if (d >= screen_num_desktops && wrap)
d = screen_num_desktops - 1;
if (d < screen_num_desktops)
screen_set_desktop(d);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *owrap_numDesktops(OpenboxWrap *self, PyObject *args)
{
CHECK_OWRAP(self, "numDesktops");
if (!PyArg_ParseTuple(args, ":numDesktops"))
return NULL;
return PyInt_FromLong(screen_num_desktops);
}
static PyObject *owrap_setNumDesktops(OpenboxWrap *self, PyObject *args)
{
int desktops;
CHECK_OWRAP(self, "setNumDesktops");
if (!PyArg_ParseTuple(args, "i:setNumDesktops", &desktops))
return NULL;
if (desktops <= 0) {
PyErr_SetString(PyExc_ValueError, "invalid number of desktops");
return NULL;
}
screen_set_num_desktops(desktops);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *owrap_desktopNames(OpenboxWrap *self, PyObject *args)
{
PyObject *tuple;
int i, s;
CHECK_OWRAP(self, "desktopNames");
if (!PyArg_ParseTuple(args, ":desktopNames"))
return NULL;
s = screen_desktop_names->len;
tuple = PyTuple_New(s);
for (i = 0; i < s; ++i)
PyTuple_SET_ITEM(tuple, i, g_ptr_array_index(screen_desktop_names, i));
return tuple;
}
static PyObject *owrap_setDesktopNames(OpenboxWrap *self, PyObject *args)
{
PyObject *seq;
int i, s;
GPtrArray *data;
CHECK_OWRAP(self, "setDesktopNames");
if (!PyArg_ParseTuple(args, "O:setDesktopNames", &seq))
return NULL;
if (!PySequence_Check(seq))
PyErr_SetString(PyExc_TypeError, "expected a sequence");
return NULL;
s = PySequence_Size(seq);
for (i = 0; i < s; ++i) {
PyObject *item;
gboolean check;
item = PySequence_GetItem(seq, i); /* new */
check = PyString_Check(item);
Py_DECREF(item);
if (!check) {
PyErr_SetString(PyExc_TypeError, "expected a sequence of strings");
return NULL;
}
}
data = g_ptr_array_sized_new(s);
for (i = 0; i < s; ++i) {
PyObject *item;
item = PySequence_GetItem(seq, i); /* new */
g_ptr_array_index(data, i) = PyString_AsString(item); /* borrowed */
Py_DECREF(item);
}
PROP_SETSA(ob_root, net_desktop_names, utf8, data);
g_ptr_array_free(data, TRUE);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *owrap_showingDesktop(OpenboxWrap *self, PyObject *args)
{
CHECK_OWRAP(self, "showingDesktop");
if (!PyArg_ParseTuple(args, ":showingDesktop"))
return NULL;
return PyInt_FromLong(!!screen_showing_desktop);
}
static PyObject *owrap_setShowingDesktop(OpenboxWrap *self, PyObject *args)
{
int show;
CHECK_OWRAP(self, "setShowingDesktop");
if (!PyArg_ParseTuple(args, "i:setShowingDesktop", &show))
return NULL;
screen_show_desktop(show);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *owrap_screenArea(OpenboxWrap *self, PyObject *args)
{
int desktop;
Rect *area;
PyObject *tuple;
CHECK_OWRAP(self, "screenArea");
if (!PyArg_ParseTuple(args, "i:screenArea", &desktop))
return NULL;
area = screen_area(desktop);
if (area == NULL) {
PyErr_SetString(PyExc_ValueError, "invalid desktop");
return NULL;
}
tuple = PyTuple_New(4);
PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(area->x));
PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(area->y));
PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(area->width));
PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(area->height));
return tuple;
}
static PyObject *owrap_screenStrut(OpenboxWrap *self, PyObject *args)
{
int desktop;
Strut *strut;
PyObject *tuple;
CHECK_OWRAP(self, "screenStrut");
if (!PyArg_ParseTuple(args, "i:screenStrut", &desktop))
return NULL;
strut = screen_strut(desktop);
if (strut == NULL) {
PyErr_SetString(PyExc_ValueError, "invalid desktop");
return NULL;
}
tuple = PyTuple_New(4);
PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(strut->left));
PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(strut->top));
PyTuple_SET_ITEM(tuple, 2, PyInt_FromLong(strut->right));
PyTuple_SET_ITEM(tuple, 3, PyInt_FromLong(strut->bottom));
return tuple;
}
static PyObject *owrap_physicalSize(OpenboxWrap *self, PyObject *args)
{
PyObject *tuple;
CHECK_OWRAP(self, "physicalSize");
if (!PyArg_ParseTuple(args, ":physicalSize"))
return NULL;
tuple = PyTuple_New(2);
PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong(screen_physical_size.width));
PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong(screen_physical_size.height));
return tuple;
}
static PyObject *owrap_screenNumber(OpenboxWrap *self, PyObject *args)
{
CHECK_OWRAP(self, "screenNumber");
if (!PyArg_ParseTuple(args, ":screenNumber"))
return NULL;
return PyInt_FromLong(ob_screen);
}
static PyObject *owrap_rootWindow(OpenboxWrap *self, PyObject *args)
{
CHECK_OWRAP(self, "rootWindow");
if (!PyArg_ParseTuple(args, ":rootWindow"))
return NULL;
return PyInt_FromLong(ob_root);
}
static PyObject *owrap_clientList(OpenboxWrap *self, PyObject *args)
{
CHECK_OWRAP(self, "clientList");
if (!PyArg_ParseTuple(args, ":clientList"))
return NULL;
Py_INCREF(self->client_list);
return self->client_list;
}
#define METH(n, d) {#n, (PyCFunction)owrap_##n, METH_VARARGS, #d}
static PyMethodDef OpenboxWrapMethods[] = {
METH(shutdown,
"Causes Openbox to shutdown and exit."),
METH(restart,
"Causes Openbox to shutdown and restart. If path is specified, "
"Openbox will shutdown and attempt to run the specified executable "
"instead of restarting itself. If that fails, however, it will "
"restart itself."),
METH(state,
"Returns Openbox's current state, this will be one of the State "
"constants."),
METH(desktop,
"Returns the number of the currently visible desktop. This will be "
"in the range of [0, numDesktops())."),
METH(setDesktop,
"Sets the specified desktop as the visible desktop."),
METH(setNextDesktop,
"Sets the visible desktop to the next desktop, optionally wrapping "
"around when reaching the last."),
METH(setPreviousDesktop,
"Sets the visible desktop to the previous desktop, optionally "
"wrapping around when reaching the first."),
METH(numDesktops,
"Returns the number of desktops available."),
METH(desktopNames,
"Returns a tuple of names, containing a name for each desktop. The "
"tuple may have a length greater than numDesktops() if more names "
"have been specified."),
METH(setDesktopNames,
"Sets the names for the desktops."),
METH(showingDesktop,
"Returns True or False, depicting if Openbox is in 'showing the "
"desktop' mode. In 'showing the desktop' mode, all normal clients "
"are hidden and the desktop is given focus if possible."),
METH(setShowingDesktop,
"Enters or leaves 'showing the desktop' mode. See showingDesktop() "
"for a description of this mode."),
METH(screenArea,
"Returns the on-screen available area. This is the area not reserved "
"by applications' struts. Windows should be placed within this area, "
"not within the physicalSize()."),
METH(screenStrut,
"Returns the combined strut which has been reserved by all "
"applications on the desktops."),
METH(physicalSize,
"Returns the physical size of the display device (in pixels)."),
METH(screenNumber,
"Returns the number of the screen on which Openbox is running."),
METH(rootWindow,
"Return the window id of the root window."),
METH(clientList,
"Returns a all clients currently being managed by Openbox. This list "
"is updated as clients are managed and closed/destroyed/released."),
{ NULL, NULL, 0, NULL }
};
/***************************************************************************
Type methods/struct
***************************************************************************/
/*static PyObject *owrap_getattr(OpenboxWrap *self, char *name)
{
CHECK_OWRAP(self, "getattr");
return Py_FindMethod(OpenboxWrapAttributeMethods, (PyObject*)self, name);
}*/
static void owrap_dealloc(OpenboxWrap *self)
{
PyObject_Del((PyObject*) self);
}
static PyTypeObject OpenboxWrapType = {
PyObject_HEAD_INIT(NULL)
0,
"Openbox",
sizeof(OpenboxWrap),
0,
(destructor) owrap_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
};
/***************************************************************************
Define the type 'OpenboxState'
***************************************************************************/
#define IS_OSTATE(v) ((v)->ob_type == &OpenboxStateType)
#define CHECK_OSTATE(self, funcname) { \
if (!IS_OSTATE(self)) { \
PyErr_SetString(PyExc_TypeError, \
"descriptor '" funcname "' requires a 'State' " \
"object"); \
return NULL; \
} \
}
staticforward PyTypeObject OpenboxStateType;
typedef struct OpenboxState {
PyObject_HEAD
} OpenboxState;
static void ostate_dealloc(PyObject *self)
{
PyObject_Del(self);
}
static PyObject *ostate_getattr(OpenboxState *self, char *name)
{
struct S { char *name; int val; };
struct S s[] = {
{ "Starting", State_Starting },
{ "Running", State_Running },
{ "Exiting", State_Exiting },
{ NULL, 0 } };
int i;
CHECK_OSTATE(self, "__getattr__");
for (i = 0; s[i].name != NULL; ++i)
if (!strcmp(s[i].name, name))
return PyInt_FromLong(s[i].val);
PyErr_SetString(PyExc_AttributeError, "invalid attribute");
return NULL;
}
static PyTypeObject OpenboxStateType = {
PyObject_HEAD_INIT(NULL)
0,
"State",
sizeof(OpenboxState),
0,
(destructor) ostate_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc) ostate_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
};
/***************************************************************************
External methods
***************************************************************************/
void openboxwrap_startup()
{
PyObject *ob, *obdict, *state;
OpenboxWrapType.ob_type = &PyType_Type;
OpenboxWrapType.tp_methods = OpenboxWrapMethods;
PyType_Ready(&OpenboxWrapType);
/* get the ob module/dict */
ob = PyImport_ImportModule("ob"); /* new */
g_assert(ob != NULL);
obdict = PyModule_GetDict(ob); /* borrowed */
g_assert(obdict != NULL);
/* add an Openbox instance to the ob module */
openboxwrap_obj = PyObject_New(OpenboxWrap, &OpenboxWrapType);
openboxwrap_obj->client_list = PyList_New(0);
PyDict_SetItemString(obdict, "Openbox", (PyObject*) openboxwrap_obj);
/* add an instance of OpenboxState */
state = (PyObject*) PyObject_New(OpenboxState, &OpenboxStateType);
PyDict_SetItemString(obdict, "State", state);
Py_DECREF(state);
Py_DECREF(ob);
}
void openboxwrap_shutdown()
{
Py_DECREF(openboxwrap_obj->client_list);
Py_DECREF(openboxwrap_obj);
}

View file

@ -1,17 +0,0 @@
#ifndef __openboxwrap_h
#define __openboxwrap_h
#include <Python.h>
/* OpenboxWrap is a PyObject */
typedef struct OpenboxWrap {
PyObject_HEAD
PyObject *client_list;
} OpenboxWrap;
OpenboxWrap *openboxwrap_obj;
void openboxwrap_startup();
void openboxwrap_shutdown();
#endif

View file

@ -1,60 +0,0 @@
#include <Python.h>
#include <glib.h>
static PyMethodDef ObMethods[] = {
{ NULL, NULL, 0, NULL }
};
static PyMethodDef InputMethods[] = {
{ NULL, NULL, 0, NULL }
};
void python_startup()
{
PyObject *sys, *sysdict, *syspath, *path1, *path2;
char *homescriptdir;
Py_Initialize();
/* fix up the system path */
sys = PyImport_ImportModule("sys"); /* new */
sysdict = PyModule_GetDict(sys); /* borrowed */
syspath = PyDict_GetItemString(sysdict, "path"); /* borrowed */
path1 = PyString_FromString(SCRIPTDIR); /* new */
PyList_Insert(syspath, 0, path1);
Py_DECREF(path1);
homescriptdir = g_build_filename(g_get_home_dir(), ".openbox", NULL);
path2 = PyString_FromString(homescriptdir); /* new */
PyList_Insert(syspath, 0, path2);
Py_DECREF(path2);
g_free(homescriptdir);
Py_DECREF(sys);
/* create the 'ob' module */
Py_InitModule("ob", ObMethods);
/* create the 'input' module */
Py_InitModule("input", InputMethods);
}
void python_shutdown()
{
Py_Finalize();
}
gboolean python_import(char *module)
{
PyObject *mod;
mod = PyImport_ImportModule(module); /* new */
if (mod == NULL) {
PyErr_Print();
return FALSE;
}
Py_DECREF(mod);
return TRUE;
}

View file

@ -1,10 +0,0 @@
#ifndef __python_h
#define __python_h
void python_startup();
void python_shutdown();
/*! Import a python module */
gboolean python_import(char *module);
#endif