| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *   Interface to the ncurses panel library | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Original version by Thomas Gellekum | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Release Number */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *PyCursesVersion = "2.1"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Includes */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Python.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "py_curses.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <panel.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *PyCursesError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Utility Functions */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Check the return code from a curses function and return None  | 
					
						
							|  |  |  |  * or raise an exception as appropriate. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | PyCursesCheckERR(int code, char *fname) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (code != ERR) { | 
					
						
							|  |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  | 	if (fname == NULL) { | 
					
						
							|  |  |  | 	    PyErr_SetString(PyCursesError, catchall_ERR); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 	    PyErr_Format(PyCursesError, "%s() returned ERR", fname); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************
 | 
					
						
							|  |  |  |  The Panel Object | 
					
						
							|  |  |  | ******************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Definition of the panel object and panel type */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct { | 
					
						
							|  |  |  |     PyObject_HEAD | 
					
						
							|  |  |  |     PANEL *pan; | 
					
						
							|  |  |  |     PyCursesWindowObject *wo;	/* for reference counts */ | 
					
						
							|  |  |  | } PyCursesPanelObject; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyTypeObject PyCursesPanel_Type; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-19 02:45:37 +00:00
										 |  |  | #define PyCursesPanel_Check(v)	 (Py_TYPE(v) == &PyCursesPanel_Type)
 | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Some helper functions. The problem is that there's always a window
 | 
					
						
							|  |  |  |    associated with a panel. To ensure that Python's GC doesn't pull | 
					
						
							|  |  |  |    this window from under our feet we need to keep track of references | 
					
						
							|  |  |  |    to the corresponding window object within Python. We can't use | 
					
						
							|  |  |  |    dupwin(oldwin) to keep a copy of the curses WINDOW because the | 
					
						
							|  |  |  |    contents of oldwin is copied only once; code like | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    win = newwin(...) | 
					
						
							|  |  |  |    pan = win.panel() | 
					
						
							|  |  |  |    win.addstr(some_string) | 
					
						
							|  |  |  |    pan.window().addstr(other_string) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    will fail. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* We keep a linked list of PyCursesPanelObjects, lop. A list should
 | 
					
						
							|  |  |  |    suffice, I don't expect more than a handful or at most a few | 
					
						
							|  |  |  |    dozens of panel objects within a typical program. */ | 
					
						
							|  |  |  | typedef struct _list_of_panels { | 
					
						
							|  |  |  |     PyCursesPanelObject *po; | 
					
						
							|  |  |  |     struct _list_of_panels *next; | 
					
						
							|  |  |  | } list_of_panels; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* list anchor */ | 
					
						
							|  |  |  | static list_of_panels *lop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Insert a new panel object into lop */ | 
					
						
							|  |  |  | static int | 
					
						
							|  |  |  | insert_lop(PyCursesPanelObject *po) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     list_of_panels *new; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     if ((new = (list_of_panels *)malloc(sizeof(list_of_panels))) == NULL) { | 
					
						
							|  |  |  | 	PyErr_NoMemory(); | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     new->po = po; | 
					
						
							|  |  |  |     new->next = lop; | 
					
						
							|  |  |  |     lop = new; | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Remove the panel object from lop */ | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | remove_lop(PyCursesPanelObject *po) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     list_of_panels *temp, *n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     temp = lop; | 
					
						
							|  |  |  |     if (temp->po == po) { | 
					
						
							|  |  |  | 	lop = temp->next; | 
					
						
							|  |  |  | 	free(temp); | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2006-03-07 13:38:14 +00:00
										 |  |  |     while (temp->next == NULL || temp->next->po != po) { | 
					
						
							|  |  |  | 	if (temp->next == NULL) { | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | 	    PyErr_SetString(PyExc_RuntimeError, | 
					
						
							|  |  |  | 			    "remove_lop: can't find Panel Object"); | 
					
						
							| 
									
										
										
										
											2006-03-07 13:38:14 +00:00
										 |  |  | 	    return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | 	temp = temp->next; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     n = temp->next->next; | 
					
						
							|  |  |  |     free(temp->next); | 
					
						
							|  |  |  |     temp->next = n; | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Return the panel object that corresponds to pan */ | 
					
						
							|  |  |  | static PyCursesPanelObject * | 
					
						
							|  |  |  | find_po(PANEL *pan) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     list_of_panels *temp; | 
					
						
							|  |  |  |     for (temp = lop; temp->po->pan != pan; temp = temp->next) | 
					
						
							|  |  |  | 	if (temp->next == NULL) return NULL;	/* not found!? */ | 
					
						
							|  |  |  |     return temp->po; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Function Prototype Macros - They are ugly but very, very useful. ;-)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    X - function name | 
					
						
							|  |  |  |    TYPE - parameter Type | 
					
						
							|  |  |  |    ERGSTR - format string for construction of the return value | 
					
						
							|  |  |  |    PARSESTR - format string for argument parsing */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define Panel_NoArgNoReturnFunction(X) \
 | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  | static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \ | 
					
						
							|  |  |  | { return PyCursesCheckERR(X(self->pan), # X); } | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define Panel_NoArgTrueFalseFunction(X) \
 | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  | static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \ | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | { \ | 
					
						
							|  |  |  |   if (X (self->pan) == FALSE) { Py_INCREF(Py_False); return Py_False; } \ | 
					
						
							|  |  |  |   else { Py_INCREF(Py_True); return Py_True; } } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define Panel_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
 | 
					
						
							| 
									
										
										
										
											2000-12-23 05:46:23 +00:00
										 |  |  | static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \ | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | { \ | 
					
						
							|  |  |  |   TYPE arg1, arg2; \ | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, PARSESTR, &arg1, &arg2)) return NULL; \ | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  |   return PyCursesCheckERR(X(self->pan, arg1, arg2), # X); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------- PANEL routines --------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Panel_NoArgNoReturnFunction(bottom_panel) | 
					
						
							|  |  |  | Panel_NoArgNoReturnFunction(hide_panel) | 
					
						
							|  |  |  | Panel_NoArgNoReturnFunction(show_panel) | 
					
						
							|  |  |  | Panel_NoArgNoReturnFunction(top_panel) | 
					
						
							|  |  |  | Panel_NoArgTrueFalseFunction(panel_hidden) | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  | Panel_TwoArgNoReturnFunction(move_panel, int, "ii;y,x") | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Allocation and deallocation of Panel Objects */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyCursesPanelObject *po; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     po = PyObject_NEW(PyCursesPanelObject, &PyCursesPanel_Type); | 
					
						
							|  |  |  |     if (po == NULL) return NULL; | 
					
						
							|  |  |  |     po->pan = pan; | 
					
						
							|  |  |  |     po->wo = wo; | 
					
						
							|  |  |  |     Py_INCREF(wo); | 
					
						
							|  |  |  |     if (insert_lop(po) < 0) { | 
					
						
							|  |  |  | 	PyObject_DEL(po); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return (PyObject *)po; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | PyCursesPanel_Dealloc(PyCursesPanelObject *po) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void)del_panel(po->pan); | 
					
						
							|  |  |  |     Py_DECREF(po->wo); | 
					
						
							|  |  |  |     remove_lop(po); | 
					
						
							| 
									
										
										
										
											2002-01-30 15:47:34 +00:00
										 |  |  |     PyObject_DEL(po); | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* panel_above(NULL) returns the bottom panel in the stack. To get
 | 
					
						
							|  |  |  |    this behaviour we use curses.panel.bottom_panel(). */ | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  | PyCursesPanel_above(PyCursesPanelObject *self) | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     PANEL *pan; | 
					
						
							|  |  |  |     PyCursesPanelObject *po; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     pan = panel_above(self->pan); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (pan == NULL) {		/* valid output, it means the calling panel
 | 
					
						
							|  |  |  | 				   is on top of the stack */ | 
					
						
							|  |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     po = find_po(pan); | 
					
						
							|  |  |  |     if (po == NULL) { | 
					
						
							|  |  |  | 	PyErr_SetString(PyExc_RuntimeError, | 
					
						
							|  |  |  | 			"panel_above: can't find Panel Object"); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Py_INCREF(po); | 
					
						
							|  |  |  |     return (PyObject *)po; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* panel_below(NULL) returns the top panel in the stack. To get
 | 
					
						
							| 
									
										
										
										
											2001-01-19 15:35:26 +00:00
										 |  |  |    this behaviour we use curses.panel.top_panel(). */ | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  | PyCursesPanel_below(PyCursesPanelObject *self) | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     PANEL *pan; | 
					
						
							|  |  |  |     PyCursesPanelObject *po; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     pan = panel_below(self->pan); | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     if (pan == NULL) {		/* valid output, it means the calling panel
 | 
					
						
							|  |  |  | 				   is on the bottom of the stack */ | 
					
						
							|  |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     po = find_po(pan); | 
					
						
							|  |  |  |     if (po == NULL) { | 
					
						
							|  |  |  | 	PyErr_SetString(PyExc_RuntimeError, | 
					
						
							|  |  |  | 			"panel_below: can't find Panel Object"); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Py_INCREF(po); | 
					
						
							|  |  |  |     return (PyObject *)po; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  | PyCursesPanel_window(PyCursesPanelObject *self) | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     Py_INCREF(self->wo); | 
					
						
							|  |  |  |     return (PyObject *)self->wo; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyCursesPanelObject *po; | 
					
						
							|  |  |  |     PyCursesWindowObject *temp; | 
					
						
							|  |  |  |     int rtn; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  |     if (PyTuple_Size(args) != 1) { | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | 	PyErr_SetString(PyExc_TypeError, "replace requires one argument"); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (!PyArg_ParseTuple(args, "O!;window object", | 
					
						
							|  |  |  | 			  &PyCursesWindow_Type, &temp)) | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     po = find_po(self->pan); | 
					
						
							|  |  |  |     if (po == NULL) { | 
					
						
							|  |  |  | 	PyErr_SetString(PyExc_RuntimeError, | 
					
						
							|  |  |  | 			"replace_panel: can't find Panel Object"); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rtn = replace_panel(self->pan, temp->win); | 
					
						
							|  |  |  |     if (rtn == ERR) { | 
					
						
							|  |  |  | 	PyErr_SetString(PyCursesError, "replace_panel() returned ERR"); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Py_DECREF(po->wo); | 
					
						
							|  |  |  |     po->wo = temp; | 
					
						
							|  |  |  |     Py_INCREF(po->wo); | 
					
						
							|  |  |  |     Py_INCREF(Py_None); | 
					
						
							|  |  |  |     return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  | PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj) | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     Py_INCREF(obj); | 
					
						
							| 
									
										
										
										
											2001-10-13 08:50:10 +00:00
										 |  |  |     return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj), | 
					
						
							| 
									
										
										
										
											2000-12-23 05:46:23 +00:00
										 |  |  |                             "set_panel_userptr"); | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  | static PyObject * | 
					
						
							|  |  |  | PyCursesPanel_userptr(PyCursesPanelObject *self) | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     PyObject *obj; | 
					
						
							|  |  |  |     PyCursesInitialised;  | 
					
						
							| 
									
										
										
										
											2000-12-23 05:46:23 +00:00
										 |  |  |     obj = (PyObject *) panel_userptr(self->pan); | 
					
						
							| 
									
										
										
										
											2006-01-09 06:24:35 +00:00
										 |  |  |     if (obj == NULL) { | 
					
						
							|  |  |  | 	PyErr_SetString(PyCursesError, "no userptr set"); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  |     Py_INCREF(obj); | 
					
						
							|  |  |  |     return obj; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Module interface */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMethodDef PyCursesPanel_Methods[] = { | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  |     {"above",           (PyCFunction)PyCursesPanel_above, METH_NOARGS}, | 
					
						
							|  |  |  |     {"below",           (PyCFunction)PyCursesPanel_below, METH_NOARGS}, | 
					
						
							|  |  |  |     {"bottom",          (PyCFunction)PyCursesPanel_bottom_panel, METH_NOARGS}, | 
					
						
							|  |  |  |     {"hidden",          (PyCFunction)PyCursesPanel_panel_hidden, METH_NOARGS}, | 
					
						
							|  |  |  |     {"hide",            (PyCFunction)PyCursesPanel_hide_panel, METH_NOARGS}, | 
					
						
							|  |  |  |     {"move",            (PyCFunction)PyCursesPanel_move_panel, METH_VARARGS}, | 
					
						
							| 
									
										
										
										
											2002-03-31 14:55:17 +00:00
										 |  |  |     {"replace",         (PyCFunction)PyCursesPanel_replace_panel, METH_VARARGS}, | 
					
						
							| 
									
										
										
										
											2002-01-17 23:08:27 +00:00
										 |  |  |     {"set_userptr",     (PyCFunction)PyCursesPanel_set_panel_userptr, METH_O}, | 
					
						
							|  |  |  |     {"show",            (PyCFunction)PyCursesPanel_show_panel, METH_NOARGS}, | 
					
						
							|  |  |  |     {"top",             (PyCFunction)PyCursesPanel_top_panel, METH_NOARGS}, | 
					
						
							|  |  |  |     {"userptr",         (PyCFunction)PyCursesPanel_userptr, METH_NOARGS}, | 
					
						
							|  |  |  |     {"window",          (PyCFunction)PyCursesPanel_window, METH_NOARGS}, | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  |     {NULL,		NULL}   /* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | PyCursesPanel_GetAttr(PyCursesPanelObject *self, char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return Py_FindMethod(PyCursesPanel_Methods, (PyObject *)self, name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyTypeObject PyCursesPanel_Type = { | 
					
						
							| 
									
										
											  
											
												Merged revisions 56467-56482 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk
................
  r56477 | martin.v.loewis | 2007-07-21 09:04:38 +0200 (Sa, 21 Jul 2007) | 11 lines
  Merged revisions 56466-56476 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk
  ........
    r56476 | martin.v.loewis | 2007-07-21 08:55:02 +0200 (Sa, 21 Jul 2007) | 4 lines
    PEP 3123: Provide forward compatibility with Python 3.0, while keeping
    backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
    PyVarObject_HEAD_INIT.
  ........
................
  r56478 | martin.v.loewis | 2007-07-21 09:47:23 +0200 (Sa, 21 Jul 2007) | 2 lines
  PEP 3123: Use proper C inheritance for PyObject.
................
  r56479 | martin.v.loewis | 2007-07-21 10:06:55 +0200 (Sa, 21 Jul 2007) | 3 lines
  Add longintrepr.h to Python.h, so that the compiler can
  see that PyFalse is really some kind of PyObject*.
................
  r56480 | martin.v.loewis | 2007-07-21 10:47:18 +0200 (Sa, 21 Jul 2007) | 2 lines
  Qualify SHIFT, MASK, BASE.
................
  r56482 | martin.v.loewis | 2007-07-21 19:10:57 +0200 (Sa, 21 Jul 2007) | 2 lines
  Correctly refer to _ob_next.
................
											
										 
											2007-07-21 17:22:18 +00:00
										 |  |  |     PyVarObject_HEAD_INIT(NULL, 0) | 
					
						
							| 
									
										
										
										
											2001-12-08 18:02:58 +00:00
										 |  |  |     "_curses_panel.curses panel",	/*tp_name*/ | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  |     sizeof(PyCursesPanelObject),	/*tp_basicsize*/ | 
					
						
							|  |  |  |     0,			/*tp_itemsize*/ | 
					
						
							|  |  |  |     /* methods */ | 
					
						
							|  |  |  |     (destructor)PyCursesPanel_Dealloc, /*tp_dealloc*/ | 
					
						
							|  |  |  |     0,			/*tp_print*/ | 
					
						
							|  |  |  |     (getattrfunc)PyCursesPanel_GetAttr, /*tp_getattr*/ | 
					
						
							|  |  |  |     (setattrfunc)0, /*tp_setattr*/ | 
					
						
							|  |  |  |     0,			/*tp_compare*/ | 
					
						
							|  |  |  |     0,			/*tp_repr*/ | 
					
						
							|  |  |  |     0,			/*tp_as_number*/ | 
					
						
							|  |  |  |     0,			/*tp_as_sequence*/ | 
					
						
							|  |  |  |     0,			/*tp_as_mapping*/ | 
					
						
							|  |  |  |     0,			/*tp_hash*/ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Wrapper for panel_above(NULL). This function returns the bottom
 | 
					
						
							|  |  |  |    panel of the stack, so it's renamed to bottom_panel(). | 
					
						
							|  |  |  |    panel.above() *requires* a panel object in the first place which | 
					
						
							|  |  |  |    may be undesirable. */ | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2002-03-25 20:46:46 +00:00
										 |  |  | PyCurses_bottom_panel(PyObject *self) | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     PANEL *pan; | 
					
						
							|  |  |  |     PyCursesPanelObject *po; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     PyCursesInitialised; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pan = panel_above(NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-19 15:35:26 +00:00
										 |  |  |     if (pan == NULL) {		/* valid output, it means
 | 
					
						
							|  |  |  | 				   there's no panel at all */   | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     po = find_po(pan); | 
					
						
							|  |  |  |     if (po == NULL) { | 
					
						
							|  |  |  | 	PyErr_SetString(PyExc_RuntimeError, | 
					
						
							|  |  |  | 			"panel_above: can't find Panel Object"); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Py_INCREF(po); | 
					
						
							|  |  |  |     return (PyObject *)po; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | PyCurses_new_panel(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyCursesWindowObject *win; | 
					
						
							|  |  |  |     PANEL *pan; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-23 05:46:23 +00:00
										 |  |  |     if (!PyArg_ParseTuple(args, "O!", &PyCursesWindow_Type, &win)) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  |     pan = new_panel(win->win); | 
					
						
							|  |  |  |     if (pan == NULL) { | 
					
						
							|  |  |  | 	PyErr_SetString(PyCursesError, catchall_NULL); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return (PyObject *)PyCursesPanel_New(pan, win); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Wrapper for panel_below(NULL). This function returns the top panel
 | 
					
						
							|  |  |  |    of the stack, so it's renamed to top_panel(). panel.below() | 
					
						
							|  |  |  |    *requires* a panel object in the first place which may be | 
					
						
							|  |  |  |    undesirable. */ | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2002-03-25 20:46:46 +00:00
										 |  |  | PyCurses_top_panel(PyObject *self) | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     PANEL *pan; | 
					
						
							|  |  |  |     PyCursesPanelObject *po; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     PyCursesInitialised; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     pan = panel_below(NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (pan == NULL) {		/* valid output, it means
 | 
					
						
							|  |  |  | 				   there's no panel at all */ | 
					
						
							|  |  |  | 	Py_INCREF(Py_None); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     po = find_po(pan); | 
					
						
							|  |  |  |     if (po == NULL) { | 
					
						
							|  |  |  | 	PyErr_SetString(PyExc_RuntimeError, | 
					
						
							|  |  |  | 			"panel_below: can't find Panel Object"); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     Py_INCREF(po); | 
					
						
							|  |  |  |     return (PyObject *)po; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-03-25 20:46:46 +00:00
										 |  |  | static PyObject *PyCurses_update_panels(PyObject *self) | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | {  | 
					
						
							|  |  |  |     PyCursesInitialised; | 
					
						
							|  |  |  |     update_panels(); | 
					
						
							|  |  |  |     Py_INCREF(Py_None); | 
					
						
							|  |  |  |     return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* List of functions defined in the module */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMethodDef PyCurses_methods[] = { | 
					
						
							| 
									
										
										
										
											2002-03-25 20:46:46 +00:00
										 |  |  |     {"bottom_panel",        (PyCFunction)PyCurses_bottom_panel,  METH_NOARGS}, | 
					
						
							|  |  |  |     {"new_panel",           (PyCFunction)PyCurses_new_panel,     METH_VARARGS}, | 
					
						
							|  |  |  |     {"top_panel",           (PyCFunction)PyCurses_top_panel,     METH_NOARGS}, | 
					
						
							|  |  |  |     {"update_panels",       (PyCFunction)PyCurses_update_panels, METH_NOARGS}, | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  |     {NULL,		NULL}		/* sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Initialization function for the module */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-02 02:27:13 +00:00
										 |  |  | PyMODINIT_FUNC | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  | init_curses_panel(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyObject *m, *d, *v; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-27 18:58:04 +00:00
										 |  |  |     /* Initialize object type */ | 
					
						
							| 
									
										
										
										
											2007-12-19 02:45:37 +00:00
										 |  |  |     Py_TYPE(&PyCursesPanel_Type) = &PyType_Type; | 
					
						
							| 
									
										
										
										
											2001-01-22 15:29:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  |     import_curses(); | 
					
						
							| 
									
										
										
										
											2001-01-27 18:58:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  |     /* Create the module and add the functions */ | 
					
						
							|  |  |  |     m = Py_InitModule("_curses_panel", PyCurses_methods); | 
					
						
							| 
									
										
										
										
											2006-01-19 06:09:39 +00:00
										 |  |  |     if (m == NULL) | 
					
						
							|  |  |  |     	return; | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  |     d = PyModule_GetDict(m); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* For exception _curses_panel.error */ | 
					
						
							|  |  |  |     PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL); | 
					
						
							|  |  |  |     PyDict_SetItemString(d, "error", PyCursesError); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Make the version available */ | 
					
						
							| 
									
										
										
										
											2007-08-23 21:42:55 +00:00
										 |  |  |     v = PyUnicode_FromString(PyCursesVersion); | 
					
						
							| 
									
										
										
										
											2000-12-22 21:54:12 +00:00
										 |  |  |     PyDict_SetItemString(d, "version", v); | 
					
						
							|  |  |  |     PyDict_SetItemString(d, "__version__", v); | 
					
						
							|  |  |  |     Py_DECREF(v); | 
					
						
							|  |  |  | } |