python has begun!

This commit is contained in:
Dana Jansens 2002-12-19 23:54:41 +00:00
parent 977ecf1f1e
commit 700984bd15
9 changed files with 194 additions and 6 deletions

View file

@ -75,7 +75,7 @@ CFLAGS="$CFLAGS $DEBUG"
dnl Check for Python
AC_CHECK_HEADER([python2.2/Python.h],
PYTHON_CFLAGS="-Ipython2.2",
,
AC_MSG_ERROR([Openbox requires the use of Python 2.2. This is its secret special formula for extreme sexiness.
See http://www.python.org
]))
@ -84,7 +84,6 @@ AC_CHECK_LIB([python2.2], [Py_Initialize],
AC_MSG_ERROR([Openbox requires the use of Python 2.2. This is its secret special formula for extreme sexiness.
See http://www.python.org
]))
AC_SUBST([PYTHON_CFLAGS])
AC_SUBST([PYTHON_LDFLAGS])
dnl Check for X headers and libraries

View file

@ -2,7 +2,7 @@ localedir=$(datadir)/locale
DEFAULT_MENU=$(pkgdatadir)/menu
DEFAULT_STYLE=$(pkgdatadir)/styles/mbdtex
CPPFLAGS=$(XFT_CFLAGS) $(PYTHON_CFLAGS) @CPPFLAGS@ \
CPPFLAGS=$(XFT_CFLAGS) @CPPFLAGS@ \
-DDEFAULTMENU=\"$(DEFAULT_MENU)\" \
-DDEFAULTSTYLE=\"$(DEFAULT_STYLE)\" \
-DLOCALEDIR=\"$(localedir)\"
@ -17,7 +17,7 @@ openbox3_LDADD=../otk/libotk.a @LIBINTL@
openbox3_SOURCES= actions.cc client.cc frame.cc openbox.cc screen.cc \
main.cc rootwindow.cc backgroundwidget.cc labelwidget.cc \
buttonwidget.cc
buttonwidget.cc python.cc python_client.cc
MAINTAINERCLEANFILES= Makefile.in

View file

@ -30,7 +30,7 @@ int main(int argc, char **argv) {
ob::Openbox openbox(argc, argv);
//ob::Blackbox blackbox(argc, argv, 0);
//Blackbox blackbox(argv, session_display, rc_file);
openbox.eventLoop();

View file

@ -9,6 +9,7 @@
#include "client.hh"
#include "screen.hh"
#include "actions.hh"
#include "python_client.hh"
#include "otk/property.hh"
#include "otk/display.hh"
#include "otk/assassin.hh"
@ -90,6 +91,9 @@ Openbox::Openbox(int argc, char **argv)
_doshutdown = false;
_rcfilepath = otk::expandTilde("~/.openbox/rc3");
_pyclients = PyDict_New();
assert(_pyclients);
parseCommandLine(argc, argv);
// TEMPORARY: using the xrdb rc3
@ -149,7 +153,19 @@ Openbox::Openbox(int argc, char **argv)
printf(_("No screens were found without a window manager. Exiting.\n"));
::exit(1);
}
// initialize the python interface
Py_SetProgramName(argv[0]);
Py_Initialize();
initopenbox(); // initialize the static 'openbox' module
FILE *rcpyfd = fopen("/home/natas/.openbox/user.py", "r");
if (!rcpyfd) {
printf("failed to load python file /home/natas/.openbox/user.py\n");
} else {
PyRun_SimpleFile(rcpyfd, "/home/natas/.openbox/user.py");
fclose(rcpyfd);
}
_state = State_Normal; // done starting
}
@ -261,6 +277,12 @@ void Openbox::eventLoop()
void Openbox::addClient(Window window, OBClient *client)
{
_clients[window] = client;
// maintain the python list here too
PyClientObject* pyclient = PyObject_New(PyClientObject, &PyClient_Type);
pyclient->window = window;
pyclient->client = client;
PyDict_SetItem(_pyclients, PyLong_FromLong(window), (PyObject*)pyclient);
}

View file

@ -18,6 +18,7 @@ extern "C" {
#include <vector>
#include <map>
#include "python.hh"
#include "otk/screeninfo.hh"
#include "otk/timerqueuemanager.hh"
#include "otk/property.hh"
@ -93,6 +94,7 @@ private:
//! A list of all managed clients
ClientMap _clients;
PyObject *_pyclients; // PyDictObject
//! A list of all the managed screens
ScreenList _screens;
@ -169,6 +171,8 @@ public:
//! Returns the mouse cursors used throughout Openbox
inline const Cursors &cursors() const { return _cursors; }
inline PyObject *pyclients() const { return _pyclients; }
//! The main function of the Openbox class
/*!
This function should be called after instantiating the Openbox class.

45
src/python.cc Normal file
View file

@ -0,0 +1,45 @@
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif
#include "python.hh"
#include "python_client.hh"
#include "openbox.hh"
namespace ob {
extern "C" {
static PyObject *shit(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":shit"))
return NULL;
printf("SHIT CALLED!@!\n");
return Py_None;
}
static PyMethodDef OBMethods[] = {
{"shit", shit, METH_VARARGS,
"Do some shit, yo!"},
{"get_client_dict", get_client_dict, METH_VARARGS,
"Get the list of all clients"},
{NULL, NULL, 0, NULL}
};
void initopenbox()
{
PyClient_Type.ob_type = &PyType_Type;
Py_InitModule("openbox", OBMethods);
}
}
}

20
src/python.hh Normal file
View file

@ -0,0 +1,20 @@
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifndef __python_hh
#define __python_hh
/*! @file python.hh
@brief Python stuff
*/
#include <python2.2/Python.h>
namespace ob {
extern "C" {
void initopenbox();
}
}
#endif // __python_hh

69
src/python_client.cc Normal file
View file

@ -0,0 +1,69 @@
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifdef HAVE_CONFIG_H
# include "../config.h"
#endif
#include "python_client.hh"
#include "openbox.hh"
namespace ob {
extern "C" {
PyObject *get_client_dict(PyObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":get_client_dict"))
return NULL;
return PyDictProxy_New(Openbox::instance->pyclients());
}
PyObject *getWindow(PyObject* self, PyObject* args)
{
if (!PyArg_ParseTuple(args, ":getWindow"))
return NULL;
return PyLong_FromLong(((PyClientObject*)self)->window);
}
static PyMethodDef attr_methods[] = {
{"getWindow", getWindow, METH_VARARGS,
"Return the window id."},
{NULL, NULL, 0, NULL} /* sentinel */
};
static PyObject *getattr(PyObject *obj, char *name)
{
return Py_FindMethod(attr_methods, obj, name);
}
static void client_dealloc(PyObject* self)
{
PyObject_Del(self);
}
PyTypeObject PyClient_Type = {
PyObject_HEAD_INIT(NULL)
0,
"Client",
sizeof(PyClientObject),
0,
client_dealloc, /*tp_dealloc*/
0, /*tp_print*/
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 */
};
}
}

29
src/python_client.hh Normal file
View file

@ -0,0 +1,29 @@
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifndef __pythonclient_hh
#define __pythonclient_hh
/*! @file python_client.hh
@brief Python stuff
*/
#include "python.hh"
#include "client.hh"
namespace ob {
extern "C" {
typedef struct {
PyObject_HEAD
Window window;
OBClient *client;
} PyClientObject;
extern PyTypeObject PyClient_Type;
PyObject *get_client_dict(PyObject* self, PyObject* args);
}
}
#endif // __pythonclient_hh