annotate Modules/_curses_panel.c @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 52294af4b663
children 8678534242a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
1 /*
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
2 * Interface to the ncurses panel library
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
3 *
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
4 * Original version by Thomas Gellekum
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
5 */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
6
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
7 /* Release Number */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
8
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
9 static char *PyCursesVersion = "2.1";
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
10
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
11 /* Includes */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
12
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
13 #include "Python.h"
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
14
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
15 #include "py_curses.h"
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
16
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
17 #include <panel.h>
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
18
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
19 static PyObject *PyCursesError;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
20
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
21
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
22 /* Utility Functions */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
23
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
24 /*
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
25 * Check the return code from a curses function and return None
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
26 * or raise an exception as appropriate.
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
27 */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
28
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
29 static PyObject *
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
30 PyCursesCheckERR(int code, char *fname)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
31 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
32 if (code != ERR) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
33 Py_INCREF(Py_None);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
34 return Py_None;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
35 } else {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
36 if (fname == NULL) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
37 PyErr_SetString(PyCursesError, catchall_ERR);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
38 } else {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
39 PyErr_Format(PyCursesError, "%s() returned ERR", fname);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
40 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
41 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
42 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
43 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
44
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
45 /*****************************************************************************
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
46 The Panel Object
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
47 ******************************************************************************/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
48
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
49 /* Definition of the panel object and panel type */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
50
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
51 typedef struct {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
52 PyObject_HEAD
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
53 PANEL *pan;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
54 PyCursesWindowObject *wo; /* for reference counts */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
55 } PyCursesPanelObject;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
56
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
57 PyTypeObject PyCursesPanel_Type;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
58
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
59 #define PyCursesPanel_Check(v) (Py_TYPE(v) == &PyCursesPanel_Type)
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
60
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
61 /* Some helper functions. The problem is that there's always a window
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
62 associated with a panel. To ensure that Python's GC doesn't pull
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
63 this window from under our feet we need to keep track of references
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
64 to the corresponding window object within Python. We can't use
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
65 dupwin(oldwin) to keep a copy of the curses WINDOW because the
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
66 contents of oldwin is copied only once; code like
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
67
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
68 win = newwin(...)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
69 pan = win.panel()
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
70 win.addstr(some_string)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
71 pan.window().addstr(other_string)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
72
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
73 will fail. */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
74
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
75 /* We keep a linked list of PyCursesPanelObjects, lop. A list should
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
76 suffice, I don't expect more than a handful or at most a few
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
77 dozens of panel objects within a typical program. */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
78 typedef struct _list_of_panels {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
79 PyCursesPanelObject *po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
80 struct _list_of_panels *next;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
81 } list_of_panels;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
82
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
83 /* list anchor */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
84 static list_of_panels *lop;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
85
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
86 /* Insert a new panel object into lop */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
87 static int
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
88 insert_lop(PyCursesPanelObject *po)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
89 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
90 list_of_panels *new;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
91
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
92 if ((new = (list_of_panels *)malloc(sizeof(list_of_panels))) == NULL) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
93 PyErr_NoMemory();
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
94 return -1;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
95 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
96 new->po = po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
97 new->next = lop;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
98 lop = new;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
99 return 0;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
100 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
101
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
102 /* Remove the panel object from lop */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
103 static void
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
104 remove_lop(PyCursesPanelObject *po)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
105 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
106 list_of_panels *temp, *n;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
107
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
108 temp = lop;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
109 if (temp->po == po) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
110 lop = temp->next;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
111 free(temp);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
112 return;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
113 }
36868
e62767e64de8 Coverity-found bug: don't use temp->next *before* checking it for NULL. Also
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
114 while (temp->next == NULL || temp->next->po != po) {
e62767e64de8 Coverity-found bug: don't use temp->next *before* checking it for NULL. Also
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
115 if (temp->next == NULL) {
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
116 PyErr_SetString(PyExc_RuntimeError,
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
117 "remove_lop: can't find Panel Object");
36868
e62767e64de8 Coverity-found bug: don't use temp->next *before* checking it for NULL. Also
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
118 return;
e62767e64de8 Coverity-found bug: don't use temp->next *before* checking it for NULL. Also
Thomas Wouters <thomas@python.org>
parents: 36324
diff changeset
119 }
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
120 temp = temp->next;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
121 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
122 n = temp->next->next;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
123 free(temp->next);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
124 temp->next = n;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
125 return;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
126 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
127
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
128 /* Return the panel object that corresponds to pan */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
129 static PyCursesPanelObject *
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
130 find_po(PANEL *pan)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
131 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
132 list_of_panels *temp;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
133 for (temp = lop; temp->po->pan != pan; temp = temp->next)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
134 if (temp->next == NULL) return NULL; /* not found!? */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
135 return temp->po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
136 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
137
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
138 /* Function Prototype Macros - They are ugly but very, very useful. ;-)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
139
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
140 X - function name
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
141 TYPE - parameter Type
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
142 ERGSTR - format string for construction of the return value
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
143 PARSESTR - format string for argument parsing */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
144
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
145 #define Panel_NoArgNoReturnFunction(X) \
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
146 static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
147 { return PyCursesCheckERR(X(self->pan), # X); }
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
148
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
149 #define Panel_NoArgTrueFalseFunction(X) \
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
150 static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
151 { \
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
152 if (X (self->pan) == FALSE) { Py_INCREF(Py_False); return Py_False; } \
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
153 else { Py_INCREF(Py_True); return Py_True; } }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
154
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
155 #define Panel_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \
15653
82bec388c636 Shortened / wrapped some long lines.
Fred Drake <fdrake@acm.org>
parents: 15651
diff changeset
156 static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
157 { \
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
158 TYPE arg1, arg2; \
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
159 if (!PyArg_ParseTuple(args, PARSESTR, &arg1, &arg2)) return NULL; \
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
160 return PyCursesCheckERR(X(self->pan, arg1, arg2), # X); }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
161
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
162 /* ------------- PANEL routines --------------- */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
163
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
164 Panel_NoArgNoReturnFunction(bottom_panel)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
165 Panel_NoArgNoReturnFunction(hide_panel)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
166 Panel_NoArgNoReturnFunction(show_panel)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
167 Panel_NoArgNoReturnFunction(top_panel)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
168 Panel_NoArgTrueFalseFunction(panel_hidden)
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
169 Panel_TwoArgNoReturnFunction(move_panel, int, "ii;y,x")
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
170
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
171 /* Allocation and deallocation of Panel Objects */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
172
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
173 static PyObject *
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
174 PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
175 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
176 PyCursesPanelObject *po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
177
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
178 po = PyObject_NEW(PyCursesPanelObject, &PyCursesPanel_Type);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
179 if (po == NULL) return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
180 po->pan = pan;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
181 po->wo = wo;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
182 Py_INCREF(wo);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
183 if (insert_lop(po) < 0) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
184 PyObject_DEL(po);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
185 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
186 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
187 return (PyObject *)po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
188 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
189
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
190 static void
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
191 PyCursesPanel_Dealloc(PyCursesPanelObject *po)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
192 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
193 (void)del_panel(po->pan);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
194 Py_DECREF(po->wo);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
195 remove_lop(po);
21846
26b758c00fb6 Oh look, another one.
Michael W. Hudson <mwh@python.net>
parents: 21756
diff changeset
196 PyObject_DEL(po);
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
197 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
198
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
199 /* panel_above(NULL) returns the bottom panel in the stack. To get
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
200 this behaviour we use curses.panel.bottom_panel(). */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
201 static PyObject *
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
202 PyCursesPanel_above(PyCursesPanelObject *self)
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
203 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
204 PANEL *pan;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
205 PyCursesPanelObject *po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
206
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
207 pan = panel_above(self->pan);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
208
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
209 if (pan == NULL) { /* valid output, it means the calling panel
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
210 is on top of the stack */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
211 Py_INCREF(Py_None);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
212 return Py_None;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
213 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
214 po = find_po(pan);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
215 if (po == NULL) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
216 PyErr_SetString(PyExc_RuntimeError,
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
217 "panel_above: can't find Panel Object");
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
218 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
219 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
220 Py_INCREF(po);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
221 return (PyObject *)po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
222 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
223
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
224 /* panel_below(NULL) returns the top panel in the stack. To get
16034
19eee2db2b16 Minor patch from Thomas Gellekum:
Andrew M. Kuchling <amk@amk.ca>
parents: 15653
diff changeset
225 this behaviour we use curses.panel.top_panel(). */
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
226 static PyObject *
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
227 PyCursesPanel_below(PyCursesPanelObject *self)
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
228 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
229 PANEL *pan;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
230 PyCursesPanelObject *po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
231
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
232 pan = panel_below(self->pan);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
233
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
234 if (pan == NULL) { /* valid output, it means the calling panel
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
235 is on the bottom of the stack */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
236 Py_INCREF(Py_None);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
237 return Py_None;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
238 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
239 po = find_po(pan);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
240 if (po == NULL) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
241 PyErr_SetString(PyExc_RuntimeError,
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
242 "panel_below: can't find Panel Object");
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
243 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
244 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
245 Py_INCREF(po);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
246 return (PyObject *)po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
247 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
248
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
249 static PyObject *
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
250 PyCursesPanel_window(PyCursesPanelObject *self)
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
251 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
252 Py_INCREF(self->wo);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
253 return (PyObject *)self->wo;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
254 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
255
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
256 static PyObject *
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
257 PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
258 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
259 PyCursesPanelObject *po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
260 PyCursesWindowObject *temp;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
261 int rtn;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
262
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
263 if (PyTuple_Size(args) != 1) {
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
264 PyErr_SetString(PyExc_TypeError, "replace requires one argument");
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
265 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
266 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
267 if (!PyArg_ParseTuple(args, "O!;window object",
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
268 &PyCursesWindow_Type, &temp))
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
269 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
270
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
271 po = find_po(self->pan);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
272 if (po == NULL) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
273 PyErr_SetString(PyExc_RuntimeError,
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
274 "replace_panel: can't find Panel Object");
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
275 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
276 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
277
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
278 rtn = replace_panel(self->pan, temp->win);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
279 if (rtn == ERR) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
280 PyErr_SetString(PyCursesError, "replace_panel() returned ERR");
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
281 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
282 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
283 Py_DECREF(po->wo);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
284 po->wo = temp;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
285 Py_INCREF(po->wo);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
286 Py_INCREF(Py_None);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
287 return Py_None;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
288 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
289
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
290 static PyObject *
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
291 PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj)
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
292 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
293 Py_INCREF(obj);
20411
4dab61f48458 Cast argument to set_panel_userptr to void*. Fixes bug #417240.
Martin v. Löwis <martin@v.loewis.de>
parents: 16306
diff changeset
294 return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj),
15653
82bec388c636 Shortened / wrapped some long lines.
Fred Drake <fdrake@acm.org>
parents: 15651
diff changeset
295 "set_panel_userptr");
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
296 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
297
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
298 static PyObject *
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
299 PyCursesPanel_userptr(PyCursesPanelObject *self)
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
300 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
301 PyObject *obj;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
302 PyCursesInitialised;
15653
82bec388c636 Shortened / wrapped some long lines.
Fred Drake <fdrake@acm.org>
parents: 15651
diff changeset
303 obj = (PyObject *) panel_userptr(self->pan);
36251
8df194294c90 Bug #1400115, Fix segfault when calling curses.panel.userptr()
Neal Norwitz <nnorwitz@gmail.com>
parents: 24471
diff changeset
304 if (obj == NULL) {
8df194294c90 Bug #1400115, Fix segfault when calling curses.panel.userptr()
Neal Norwitz <nnorwitz@gmail.com>
parents: 24471
diff changeset
305 PyErr_SetString(PyCursesError, "no userptr set");
8df194294c90 Bug #1400115, Fix segfault when calling curses.panel.userptr()
Neal Norwitz <nnorwitz@gmail.com>
parents: 24471
diff changeset
306 return NULL;
8df194294c90 Bug #1400115, Fix segfault when calling curses.panel.userptr()
Neal Norwitz <nnorwitz@gmail.com>
parents: 24471
diff changeset
307 }
8df194294c90 Bug #1400115, Fix segfault when calling curses.panel.userptr()
Neal Norwitz <nnorwitz@gmail.com>
parents: 24471
diff changeset
308
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
309 Py_INCREF(obj);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
310 return obj;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
311 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
312
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
313
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
314 /* Module interface */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
315
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
316 static PyMethodDef PyCursesPanel_Methods[] = {
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
317 {"above", (PyCFunction)PyCursesPanel_above, METH_NOARGS},
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
318 {"below", (PyCFunction)PyCursesPanel_below, METH_NOARGS},
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
319 {"bottom", (PyCFunction)PyCursesPanel_bottom_panel, METH_NOARGS},
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
320 {"hidden", (PyCFunction)PyCursesPanel_panel_hidden, METH_NOARGS},
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
321 {"hide", (PyCFunction)PyCursesPanel_hide_panel, METH_NOARGS},
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
322 {"move", (PyCFunction)PyCursesPanel_move_panel, METH_VARARGS},
22707
dc2f745fcc67 Fix whitespace
Neal Norwitz <nnorwitz@gmail.com>
parents: 22561
diff changeset
323 {"replace", (PyCFunction)PyCursesPanel_replace_panel, METH_VARARGS},
21756
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
324 {"set_userptr", (PyCFunction)PyCursesPanel_set_panel_userptr, METH_O},
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
325 {"show", (PyCFunction)PyCursesPanel_show_panel, METH_NOARGS},
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
326 {"top", (PyCFunction)PyCursesPanel_top_panel, METH_NOARGS},
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
327 {"userptr", (PyCFunction)PyCursesPanel_userptr, METH_NOARGS},
d60350d71b60 Patch #477752: Drop old-style getargs from curses.
Martin v. Löwis <martin@v.loewis.de>
parents: 21313
diff changeset
328 {"window", (PyCFunction)PyCursesPanel_window, METH_NOARGS},
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
329 {NULL, NULL} /* sentinel */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
330 };
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
331
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
332 static PyObject *
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
333 PyCursesPanel_GetAttr(PyCursesPanelObject *self, char *name)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
334 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
335 return Py_FindMethod(PyCursesPanel_Methods, (PyObject *)self, name);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
336 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
337
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
338 /* -------------------------------------------------------*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
339
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
340 PyTypeObject PyCursesPanel_Type = {
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 36868
diff changeset
341 PyVarObject_HEAD_INIT(NULL, 0)
21313
91dd223829c6 Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents: 20411
diff changeset
342 "_curses_panel.curses panel", /*tp_name*/
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
343 sizeof(PyCursesPanelObject), /*tp_basicsize*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
344 0, /*tp_itemsize*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
345 /* methods */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
346 (destructor)PyCursesPanel_Dealloc, /*tp_dealloc*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
347 0, /*tp_print*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
348 (getattrfunc)PyCursesPanel_GetAttr, /*tp_getattr*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
349 (setattrfunc)0, /*tp_setattr*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
350 0, /*tp_compare*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
351 0, /*tp_repr*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
352 0, /*tp_as_number*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
353 0, /*tp_as_sequence*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
354 0, /*tp_as_mapping*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
355 0, /*tp_hash*/
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
356 };
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
357
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
358 /* Wrapper for panel_above(NULL). This function returns the bottom
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
359 panel of the stack, so it's renamed to bottom_panel().
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
360 panel.above() *requires* a panel object in the first place which
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
361 may be undesirable. */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
362 static PyObject *
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21846
diff changeset
363 PyCurses_bottom_panel(PyObject *self)
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
364 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
365 PANEL *pan;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
366 PyCursesPanelObject *po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
367
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
368 PyCursesInitialised;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
369
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
370 pan = panel_above(NULL);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
371
16034
19eee2db2b16 Minor patch from Thomas Gellekum:
Andrew M. Kuchling <amk@amk.ca>
parents: 15653
diff changeset
372 if (pan == NULL) { /* valid output, it means
19eee2db2b16 Minor patch from Thomas Gellekum:
Andrew M. Kuchling <amk@amk.ca>
parents: 15653
diff changeset
373 there's no panel at all */
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
374 Py_INCREF(Py_None);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
375 return Py_None;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
376 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
377 po = find_po(pan);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
378 if (po == NULL) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
379 PyErr_SetString(PyExc_RuntimeError,
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
380 "panel_above: can't find Panel Object");
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
381 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
382 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
383 Py_INCREF(po);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
384 return (PyObject *)po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
385 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
386
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
387 static PyObject *
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
388 PyCurses_new_panel(PyObject *self, PyObject *args)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
389 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
390 PyCursesWindowObject *win;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
391 PANEL *pan;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
392
15653
82bec388c636 Shortened / wrapped some long lines.
Fred Drake <fdrake@acm.org>
parents: 15651
diff changeset
393 if (!PyArg_ParseTuple(args, "O!", &PyCursesWindow_Type, &win))
82bec388c636 Shortened / wrapped some long lines.
Fred Drake <fdrake@acm.org>
parents: 15651
diff changeset
394 return NULL;
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
395 pan = new_panel(win->win);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
396 if (pan == NULL) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
397 PyErr_SetString(PyCursesError, catchall_NULL);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
398 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
399 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
400 return (PyObject *)PyCursesPanel_New(pan, win);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
401 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
402
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
403
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
404 /* Wrapper for panel_below(NULL). This function returns the top panel
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
405 of the stack, so it's renamed to top_panel(). panel.below()
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
406 *requires* a panel object in the first place which may be
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
407 undesirable. */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
408 static PyObject *
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21846
diff changeset
409 PyCurses_top_panel(PyObject *self)
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
410 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
411 PANEL *pan;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
412 PyCursesPanelObject *po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
413
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
414 PyCursesInitialised;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
415
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
416 pan = panel_below(NULL);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
417
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
418 if (pan == NULL) { /* valid output, it means
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
419 there's no panel at all */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
420 Py_INCREF(Py_None);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
421 return Py_None;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
422 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
423 po = find_po(pan);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
424 if (po == NULL) {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
425 PyErr_SetString(PyExc_RuntimeError,
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
426 "panel_below: can't find Panel Object");
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
427 return NULL;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
428 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
429 Py_INCREF(po);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
430 return (PyObject *)po;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
431 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
432
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21846
diff changeset
433 static PyObject *PyCurses_update_panels(PyObject *self)
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
434 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
435 PyCursesInitialised;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
436 update_panels();
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
437 Py_INCREF(Py_None);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
438 return Py_None;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
439 }
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
440
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
441
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
442 /* List of functions defined in the module */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
443
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
444 static PyMethodDef PyCurses_methods[] = {
22561
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21846
diff changeset
445 {"bottom_panel", (PyCFunction)PyCurses_bottom_panel, METH_NOARGS},
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21846
diff changeset
446 {"new_panel", (PyCFunction)PyCurses_new_panel, METH_VARARGS},
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21846
diff changeset
447 {"top_panel", (PyCFunction)PyCurses_top_panel, METH_NOARGS},
043ad7adc896 Remove many uses of PyArg_NoArgs macro, change METH_OLDARGS to METH_NOARGS.
Neal Norwitz <nnorwitz@gmail.com>
parents: 21846
diff changeset
448 {"update_panels", (PyCFunction)PyCurses_update_panels, METH_NOARGS},
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
449 {NULL, NULL} /* sentinel */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
450 };
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
451
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
452 /* Initialization function for the module */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
453
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 22707
diff changeset
454 PyMODINIT_FUNC
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
455 init_curses_panel(void)
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
456 {
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
457 PyObject *m, *d, *v;
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
458
16306
8e873fa5450e init_curses_panel(): Be more consistent with indentation and blank lines.
Fred Drake <fdrake@acm.org>
parents: 16106
diff changeset
459 /* Initialize object type */
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42334
diff changeset
460 Py_TYPE(&PyCursesPanel_Type) = &PyType_Type;
16106
28c414dcb3e1 SF Patch #103185, by jlt63: Some more standard modules cleanup for Cygwin
Guido van Rossum <guido@python.org>
parents: 16034
diff changeset
461
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
462 import_curses();
16306
8e873fa5450e init_curses_panel(): Be more consistent with indentation and blank lines.
Fred Drake <fdrake@acm.org>
parents: 16106
diff changeset
463
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
464 /* Create the module and add the functions */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
465 m = Py_InitModule("_curses_panel", PyCurses_methods);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36251
diff changeset
466 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36251
diff changeset
467 return;
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
468 d = PyModule_GetDict(m);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
469
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
470 /* For exception _curses_panel.error */
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
471 PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
472 PyDict_SetItemString(d, "error", PyCursesError);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
473
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
474 /* Make the version available */
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
475 v = PyString_FromString(PyCursesVersion);
15647
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
476 PyDict_SetItemString(d, "version", v);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
477 PyDict_SetItemString(d, "__version__", v);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
478 Py_DECREF(v);
e9f4b76699aa Patch #102813: add a wrapper for the panel library included with ncurses.
Andrew M. Kuchling <amk@amk.ca>
parents:
diff changeset
479 }