1 /* Python scripting support
3 * Copyright (c) 2009 Sadrul Habib Chowdhury (sadrul@users.sf.net)
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program (see the file COPYING); if not, write to the
17 * Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
20 ****************************************************************
22 #include <sys/types.h>
38 #include <structmember.h>
40 extern struct win
*windows
;
49 static PyMemberDef py_window_members
[] =
51 {"title", T_STRING
, offsetof(PyWindow
, w
) + offsetof(struct win
, w_title
), 0, "Title of the window"},
52 {"number", T_INT
, offsetof(PyWindow
, w
) + offsetof(struct win
, w_number
), 0, "The window number"},
56 static PyTypeObject PyWindowType
=
58 PyObject_HEAD_INIT(NULL
)
60 .tp_name
= "screen.window",
61 .tp_basicsize
= sizeof(PyWindow
),
62 .tp_flags
= Py_TPFLAGS_DEFAULT
,
63 .tp_doc
= "Window object",
65 .tp_members
= py_window_members
69 PyWindow_FromWindow(struct win
*w
)
71 PyWindow
*obj
= PyWindowType
.tp_alloc(&PyWindowType
, 0);
73 return (PyObject
*)obj
;
79 screen_windows(PyObject
*self
)
81 struct win
*w
= windows
;
83 for (; w
; w
= w
->w_next
)
85 PyObject
*tuple
= PyTuple_New(count
);
87 for (w
= windows
, count
= 0; w
; w
= w
->w_next
, ++count
)
89 PyTuple_SetItem(tuple
, count
, PyWindow_FromWindow(w
));
95 const PyMethodDef py_methods
[] = {
96 {"windows", (PyCFunction
)screen_windows
, METH_NOARGS
, NULL
},
107 PyType_Ready(&PyWindowType
);
109 m
= Py_InitModule3 ("screen", py_methods
, NULL
);
111 Py_INCREF(&PyWindowType
);
112 PyModule_AddObject(m
, "Window", (PyObject
*)&PyWindowType
);
119 /*Py_Finalize(); // Crashes -- why? */
124 SPySource(const char *file
, int async
)
126 FILE *f
= fopen(file
, "rb");
127 int ret
= PyRun_SimpleFile(f
, file
);
131 return 1; /* Success */
133 if (PyErr_Occurred())
142 struct binding py_binding
=