Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Interface to the ncurses panel library |
| 3 | * |
| 4 | * Original version by Thomas Gellekum |
| 5 | */ |
| 6 | |
| 7 | /* Release Number */ |
| 8 | |
Serhiy Storchaka | 2d06e84 | 2015-12-25 19:53:18 +0200 | [diff] [blame] | 9 | static const char PyCursesVersion[] = "2.1"; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 10 | |
| 11 | /* Includes */ |
| 12 | |
| 13 | #include "Python.h" |
| 14 | |
| 15 | #include "py_curses.h" |
| 16 | |
| 17 | #include <panel.h> |
| 18 | |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 19 | typedef struct { |
| 20 | PyObject *PyCursesError; |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 21 | PyObject *PyCursesPanel_Type; |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 22 | } _curses_panelstate; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 23 | |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 24 | #define _curses_panelstate(o) ((_curses_panelstate *)PyModule_GetState(o)) |
| 25 | |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 26 | static int |
| 27 | _curses_panel_clear(PyObject *m) |
| 28 | { |
| 29 | Py_CLEAR(_curses_panelstate(m)->PyCursesError); |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | static int |
| 34 | _curses_panel_traverse(PyObject *m, visitproc visit, void *arg) |
| 35 | { |
| 36 | Py_VISIT(_curses_panelstate(m)->PyCursesError); |
| 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static void |
| 41 | _curses_panel_free(void *m) |
| 42 | { |
| 43 | _curses_panel_clear((PyObject *) m); |
| 44 | } |
| 45 | |
| 46 | static struct PyModuleDef _curses_panelmodule; |
| 47 | |
| 48 | #define _curses_panelstate_global \ |
| 49 | ((_curses_panelstate *) PyModule_GetState(PyState_FindModule(&_curses_panelmodule))) |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 50 | |
| 51 | /* Utility Functions */ |
| 52 | |
| 53 | /* |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 54 | * Check the return code from a curses function and return None |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 55 | * or raise an exception as appropriate. |
| 56 | */ |
| 57 | |
| 58 | static PyObject * |
Serhiy Storchaka | ef1585e | 2015-12-25 20:01:53 +0200 | [diff] [blame] | 59 | PyCursesCheckERR(int code, const char *fname) |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 60 | { |
| 61 | if (code != ERR) { |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 62 | Py_RETURN_NONE; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 63 | } else { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 64 | if (fname == NULL) { |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 65 | PyErr_SetString(_curses_panelstate_global->PyCursesError, catchall_ERR); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 66 | } else { |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 67 | PyErr_Format(_curses_panelstate_global->PyCursesError, "%s() returned ERR", fname); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 68 | } |
| 69 | return NULL; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
| 73 | /***************************************************************************** |
| 74 | The Panel Object |
| 75 | ******************************************************************************/ |
| 76 | |
| 77 | /* Definition of the panel object and panel type */ |
| 78 | |
| 79 | typedef struct { |
| 80 | PyObject_HEAD |
| 81 | PANEL *pan; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 82 | PyCursesWindowObject *wo; /* for reference counts */ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 83 | } PyCursesPanelObject; |
| 84 | |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 85 | #define PyCursesPanel_Check(v) \ |
| 86 | (Py_TYPE(v) == _curses_panelstate_global->PyCursesPanel_Type) |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 87 | |
| 88 | /* Some helper functions. The problem is that there's always a window |
| 89 | associated with a panel. To ensure that Python's GC doesn't pull |
| 90 | this window from under our feet we need to keep track of references |
| 91 | to the corresponding window object within Python. We can't use |
| 92 | dupwin(oldwin) to keep a copy of the curses WINDOW because the |
| 93 | contents of oldwin is copied only once; code like |
| 94 | |
| 95 | win = newwin(...) |
| 96 | pan = win.panel() |
| 97 | win.addstr(some_string) |
| 98 | pan.window().addstr(other_string) |
| 99 | |
| 100 | will fail. */ |
| 101 | |
| 102 | /* We keep a linked list of PyCursesPanelObjects, lop. A list should |
| 103 | suffice, I don't expect more than a handful or at most a few |
| 104 | dozens of panel objects within a typical program. */ |
| 105 | typedef struct _list_of_panels { |
| 106 | PyCursesPanelObject *po; |
| 107 | struct _list_of_panels *next; |
| 108 | } list_of_panels; |
| 109 | |
| 110 | /* list anchor */ |
| 111 | static list_of_panels *lop; |
| 112 | |
| 113 | /* Insert a new panel object into lop */ |
| 114 | static int |
| 115 | insert_lop(PyCursesPanelObject *po) |
| 116 | { |
| 117 | list_of_panels *new; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 118 | |
Victor Stinner | b640491 | 2013-07-07 16:21:41 +0200 | [diff] [blame] | 119 | if ((new = (list_of_panels *)PyMem_Malloc(sizeof(list_of_panels))) == NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 120 | PyErr_NoMemory(); |
| 121 | return -1; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 122 | } |
| 123 | new->po = po; |
| 124 | new->next = lop; |
| 125 | lop = new; |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | /* Remove the panel object from lop */ |
| 130 | static void |
| 131 | remove_lop(PyCursesPanelObject *po) |
| 132 | { |
| 133 | list_of_panels *temp, *n; |
| 134 | |
| 135 | temp = lop; |
| 136 | if (temp->po == po) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 137 | lop = temp->next; |
Victor Stinner | b640491 | 2013-07-07 16:21:41 +0200 | [diff] [blame] | 138 | PyMem_Free(temp); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 139 | return; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 140 | } |
Thomas Wouters | 47f003d | 2006-03-07 13:38:14 +0000 | [diff] [blame] | 141 | while (temp->next == NULL || temp->next->po != po) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 142 | if (temp->next == NULL) { |
| 143 | PyErr_SetString(PyExc_RuntimeError, |
| 144 | "remove_lop: can't find Panel Object"); |
| 145 | return; |
| 146 | } |
| 147 | temp = temp->next; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 148 | } |
| 149 | n = temp->next->next; |
Victor Stinner | b640491 | 2013-07-07 16:21:41 +0200 | [diff] [blame] | 150 | PyMem_Free(temp->next); |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 151 | temp->next = n; |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | /* Return the panel object that corresponds to pan */ |
| 156 | static PyCursesPanelObject * |
| 157 | find_po(PANEL *pan) |
| 158 | { |
| 159 | list_of_panels *temp; |
| 160 | for (temp = lop; temp->po->pan != pan; temp = temp->next) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 161 | if (temp->next == NULL) return NULL; /* not found!? */ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 162 | return temp->po; |
| 163 | } |
| 164 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 165 | /*[clinic input] |
| 166 | module _curses_panel |
| 167 | class _curses_panel.panel "PyCursesPanelObject *" "&PyCursesPanel_Type" |
| 168 | [clinic start generated code]*/ |
| 169 | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=2f4ef263ca850a31]*/ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 170 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 171 | #include "clinic/_curses_panel.c.h" |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 172 | |
| 173 | /* ------------- PANEL routines --------------- */ |
| 174 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 175 | /*[clinic input] |
| 176 | _curses_panel.panel.bottom |
| 177 | |
| 178 | Push the panel to the bottom of the stack. |
| 179 | [clinic start generated code]*/ |
| 180 | |
| 181 | static PyObject * |
| 182 | _curses_panel_panel_bottom_impl(PyCursesPanelObject *self) |
| 183 | /*[clinic end generated code: output=7aa7d14d7e1d1ce6 input=b6c920c071b61e2e]*/ |
| 184 | { |
| 185 | return PyCursesCheckERR(bottom_panel(self->pan), "bottom"); |
| 186 | } |
| 187 | |
| 188 | /*[clinic input] |
| 189 | _curses_panel.panel.hide |
| 190 | |
| 191 | Hide the panel. |
| 192 | |
| 193 | This does not delete the object, it just makes the window on screen invisible. |
| 194 | [clinic start generated code]*/ |
| 195 | |
| 196 | static PyObject * |
| 197 | _curses_panel_panel_hide_impl(PyCursesPanelObject *self) |
| 198 | /*[clinic end generated code: output=a7bbbd523e1eab49 input=f6ab884e99386118]*/ |
| 199 | { |
| 200 | return PyCursesCheckERR(hide_panel(self->pan), "hide"); |
| 201 | } |
| 202 | |
| 203 | /*[clinic input] |
| 204 | _curses_panel.panel.show |
| 205 | |
| 206 | Display the panel (which might have been hidden). |
| 207 | [clinic start generated code]*/ |
| 208 | |
| 209 | static PyObject * |
| 210 | _curses_panel_panel_show_impl(PyCursesPanelObject *self) |
| 211 | /*[clinic end generated code: output=6b4553ab45c97769 input=57b167bbefaa3755]*/ |
| 212 | { |
| 213 | return PyCursesCheckERR(show_panel(self->pan), "show"); |
| 214 | } |
| 215 | |
| 216 | /*[clinic input] |
| 217 | _curses_panel.panel.top |
| 218 | |
| 219 | Push panel to the top of the stack. |
| 220 | [clinic start generated code]*/ |
| 221 | |
| 222 | static PyObject * |
| 223 | _curses_panel_panel_top_impl(PyCursesPanelObject *self) |
| 224 | /*[clinic end generated code: output=0f5f2f8cdd2d1777 input=be33975ec3ca0e9a]*/ |
| 225 | { |
| 226 | return PyCursesCheckERR(top_panel(self->pan), "top"); |
| 227 | } |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 228 | |
| 229 | /* Allocation and deallocation of Panel Objects */ |
| 230 | |
| 231 | static PyObject * |
| 232 | PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo) |
| 233 | { |
| 234 | PyCursesPanelObject *po; |
| 235 | |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 236 | po = PyObject_NEW(PyCursesPanelObject, |
| 237 | (PyTypeObject *)(_curses_panelstate_global)->PyCursesPanel_Type); |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 238 | if (po == NULL) return NULL; |
| 239 | po->pan = pan; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 240 | if (insert_lop(po) < 0) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 241 | po->wo = NULL; |
| 242 | Py_DECREF(po); |
| 243 | return NULL; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 244 | } |
Victor Stinner | a761227 | 2010-03-03 21:56:53 +0000 | [diff] [blame] | 245 | po->wo = wo; |
| 246 | Py_INCREF(wo); |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 247 | return (PyObject *)po; |
| 248 | } |
| 249 | |
| 250 | static void |
| 251 | PyCursesPanel_Dealloc(PyCursesPanelObject *po) |
| 252 | { |
Serhiy Storchaka | df40b62 | 2016-05-09 00:11:59 +0300 | [diff] [blame] | 253 | PyObject *obj = (PyObject *) panel_userptr(po->pan); |
| 254 | if (obj) { |
| 255 | (void)set_panel_userptr(po->pan, NULL); |
| 256 | Py_DECREF(obj); |
| 257 | } |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 258 | (void)del_panel(po->pan); |
Victor Stinner | a761227 | 2010-03-03 21:56:53 +0000 | [diff] [blame] | 259 | if (po->wo != NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 260 | Py_DECREF(po->wo); |
| 261 | remove_lop(po); |
Victor Stinner | a761227 | 2010-03-03 21:56:53 +0000 | [diff] [blame] | 262 | } |
Michael W. Hudson | cf6bfe4 | 2002-01-30 15:47:34 +0000 | [diff] [blame] | 263 | PyObject_DEL(po); |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /* panel_above(NULL) returns the bottom panel in the stack. To get |
| 267 | this behaviour we use curses.panel.bottom_panel(). */ |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 268 | /*[clinic input] |
| 269 | _curses_panel.panel.above |
| 270 | |
| 271 | Return the panel above the current panel. |
| 272 | [clinic start generated code]*/ |
| 273 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 274 | static PyObject * |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 275 | _curses_panel_panel_above_impl(PyCursesPanelObject *self) |
| 276 | /*[clinic end generated code: output=70ac06d25fd3b4da input=c059994022976788]*/ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 277 | { |
| 278 | PANEL *pan; |
| 279 | PyCursesPanelObject *po; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 280 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 281 | pan = panel_above(self->pan); |
| 282 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 283 | if (pan == NULL) { /* valid output, it means the calling panel |
| 284 | is on top of the stack */ |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 285 | Py_RETURN_NONE; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 286 | } |
| 287 | po = find_po(pan); |
| 288 | if (po == NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 289 | PyErr_SetString(PyExc_RuntimeError, |
| 290 | "panel_above: can't find Panel Object"); |
| 291 | return NULL; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 292 | } |
| 293 | Py_INCREF(po); |
| 294 | return (PyObject *)po; |
| 295 | } |
| 296 | |
| 297 | /* panel_below(NULL) returns the top panel in the stack. To get |
Andrew M. Kuchling | ae89af9 | 2001-01-19 15:35:26 +0000 | [diff] [blame] | 298 | this behaviour we use curses.panel.top_panel(). */ |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 299 | /*[clinic input] |
| 300 | _curses_panel.panel.below |
| 301 | |
| 302 | Return the panel below the current panel. |
| 303 | [clinic start generated code]*/ |
| 304 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 305 | static PyObject * |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 306 | _curses_panel_panel_below_impl(PyCursesPanelObject *self) |
| 307 | /*[clinic end generated code: output=282861122e06e3de input=cc08f61936d297c6]*/ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 308 | { |
| 309 | PANEL *pan; |
| 310 | PyCursesPanelObject *po; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 311 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 312 | pan = panel_below(self->pan); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 313 | |
| 314 | if (pan == NULL) { /* valid output, it means the calling panel |
| 315 | is on the bottom of the stack */ |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 316 | Py_RETURN_NONE; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 317 | } |
| 318 | po = find_po(pan); |
| 319 | if (po == NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 320 | PyErr_SetString(PyExc_RuntimeError, |
| 321 | "panel_below: can't find Panel Object"); |
| 322 | return NULL; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 323 | } |
| 324 | Py_INCREF(po); |
| 325 | return (PyObject *)po; |
| 326 | } |
| 327 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 328 | /*[clinic input] |
| 329 | _curses_panel.panel.hidden |
| 330 | |
| 331 | Return True if the panel is hidden (not visible), False otherwise. |
| 332 | [clinic start generated code]*/ |
| 333 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 334 | static PyObject * |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 335 | _curses_panel_panel_hidden_impl(PyCursesPanelObject *self) |
| 336 | /*[clinic end generated code: output=66eebd1ab4501a71 input=453d4b4fce25e21a]*/ |
| 337 | { |
| 338 | if (panel_hidden(self->pan)) |
| 339 | Py_RETURN_TRUE; |
| 340 | else |
| 341 | Py_RETURN_FALSE; |
| 342 | } |
| 343 | |
| 344 | /*[clinic input] |
| 345 | _curses_panel.panel.move |
| 346 | |
| 347 | y: int |
| 348 | x: int |
| 349 | / |
| 350 | |
| 351 | Move the panel to the screen coordinates (y, x). |
| 352 | [clinic start generated code]*/ |
| 353 | |
| 354 | static PyObject * |
| 355 | _curses_panel_panel_move_impl(PyCursesPanelObject *self, int y, int x) |
| 356 | /*[clinic end generated code: output=d867535a89777415 input=e0b36b78acc03fba]*/ |
| 357 | { |
| 358 | return PyCursesCheckERR(move_panel(self->pan, y, x), "move_panel"); |
| 359 | } |
| 360 | |
| 361 | /*[clinic input] |
| 362 | _curses_panel.panel.window |
| 363 | |
| 364 | Return the window object associated with the panel. |
| 365 | [clinic start generated code]*/ |
| 366 | |
| 367 | static PyObject * |
| 368 | _curses_panel_panel_window_impl(PyCursesPanelObject *self) |
| 369 | /*[clinic end generated code: output=5f05940d4106b4cb input=6067353d2c307901]*/ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 370 | { |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 371 | Py_INCREF(self->wo); |
| 372 | return (PyObject *)self->wo; |
| 373 | } |
| 374 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 375 | /*[clinic input] |
| 376 | _curses_panel.panel.replace |
| 377 | |
| 378 | win: object(type="PyCursesWindowObject *", subclass_of="&PyCursesWindow_Type") |
| 379 | / |
| 380 | |
| 381 | Change the window associated with the panel to the window win. |
| 382 | [clinic start generated code]*/ |
| 383 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 384 | static PyObject * |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 385 | _curses_panel_panel_replace_impl(PyCursesPanelObject *self, |
| 386 | PyCursesWindowObject *win) |
| 387 | /*[clinic end generated code: output=2253a95f7b287255 input=4b1c4283987d9dfa]*/ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 388 | { |
| 389 | PyCursesPanelObject *po; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 390 | int rtn; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 391 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 392 | po = find_po(self->pan); |
| 393 | if (po == NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 394 | PyErr_SetString(PyExc_RuntimeError, |
| 395 | "replace_panel: can't find Panel Object"); |
| 396 | return NULL; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 399 | rtn = replace_panel(self->pan, win->win); |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 400 | if (rtn == ERR) { |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 401 | PyErr_SetString(_curses_panelstate_global->PyCursesError, "replace_panel() returned ERR"); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 402 | return NULL; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 403 | } |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 404 | Py_INCREF(win); |
| 405 | Py_SETREF(po->wo, win); |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 406 | Py_RETURN_NONE; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 409 | /*[clinic input] |
| 410 | _curses_panel.panel.set_userptr |
| 411 | |
| 412 | obj: object |
| 413 | / |
| 414 | |
| 415 | Set the panel’s user pointer to obj. |
| 416 | [clinic start generated code]*/ |
| 417 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 418 | static PyObject * |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 419 | _curses_panel_panel_set_userptr(PyCursesPanelObject *self, PyObject *obj) |
| 420 | /*[clinic end generated code: output=6fb145b3af88cf4a input=2056be1cd148b05c]*/ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 421 | { |
Andrew Kuchling | 53e5ea7 | 2013-06-15 14:04:04 -0400 | [diff] [blame] | 422 | PyObject *oldobj; |
Andrew Kuchling | 9290dd1 | 2013-06-22 14:50:56 -0400 | [diff] [blame] | 423 | int rc; |
Andrew Kuchling | 53e5ea7 | 2013-06-15 14:04:04 -0400 | [diff] [blame] | 424 | PyCursesInitialised; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 425 | Py_INCREF(obj); |
Andrew Kuchling | 9290dd1 | 2013-06-22 14:50:56 -0400 | [diff] [blame] | 426 | oldobj = (PyObject *) panel_userptr(self->pan); |
| 427 | rc = set_panel_userptr(self->pan, (void*)obj); |
| 428 | if (rc == ERR) { |
| 429 | /* In case of an ncurses error, decref the new object again */ |
| 430 | Py_DECREF(obj); |
| 431 | } |
| 432 | Py_XDECREF(oldobj); |
| 433 | return PyCursesCheckERR(rc, "set_panel_userptr"); |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 436 | /*[clinic input] |
| 437 | _curses_panel.panel.userptr |
| 438 | |
| 439 | Return the user pointer for the panel. |
| 440 | [clinic start generated code]*/ |
| 441 | |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 442 | static PyObject * |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 443 | _curses_panel_panel_userptr_impl(PyCursesPanelObject *self) |
| 444 | /*[clinic end generated code: output=e849c307b5dc9237 input=f78b7a47aef0fd50]*/ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 445 | { |
| 446 | PyObject *obj; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 447 | PyCursesInitialised; |
Fred Drake | 4e36d58 | 2000-12-23 05:46:23 +0000 | [diff] [blame] | 448 | obj = (PyObject *) panel_userptr(self->pan); |
Neal Norwitz | 5e3d862 | 2006-01-09 06:24:35 +0000 | [diff] [blame] | 449 | if (obj == NULL) { |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 450 | PyErr_SetString(_curses_panelstate_global->PyCursesError, "no userptr set"); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 451 | return NULL; |
Neal Norwitz | 5e3d862 | 2006-01-09 06:24:35 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 454 | Py_INCREF(obj); |
| 455 | return obj; |
| 456 | } |
| 457 | |
| 458 | |
| 459 | /* Module interface */ |
| 460 | |
| 461 | static PyMethodDef PyCursesPanel_Methods[] = { |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 462 | _CURSES_PANEL_PANEL_ABOVE_METHODDEF |
| 463 | _CURSES_PANEL_PANEL_BELOW_METHODDEF |
| 464 | _CURSES_PANEL_PANEL_BOTTOM_METHODDEF |
| 465 | _CURSES_PANEL_PANEL_HIDDEN_METHODDEF |
| 466 | _CURSES_PANEL_PANEL_HIDE_METHODDEF |
| 467 | _CURSES_PANEL_PANEL_MOVE_METHODDEF |
| 468 | _CURSES_PANEL_PANEL_REPLACE_METHODDEF |
| 469 | _CURSES_PANEL_PANEL_SET_USERPTR_METHODDEF |
| 470 | _CURSES_PANEL_PANEL_SHOW_METHODDEF |
| 471 | _CURSES_PANEL_PANEL_TOP_METHODDEF |
| 472 | _CURSES_PANEL_PANEL_USERPTR_METHODDEF |
| 473 | _CURSES_PANEL_PANEL_WINDOW_METHODDEF |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 474 | {NULL, NULL} /* sentinel */ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 475 | }; |
| 476 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 477 | /* -------------------------------------------------------*/ |
| 478 | |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 479 | static PyType_Slot PyCursesPanel_Type_slots[] = { |
| 480 | {Py_tp_dealloc, PyCursesPanel_Dealloc}, |
| 481 | {Py_tp_methods, PyCursesPanel_Methods}, |
| 482 | {0, 0}, |
| 483 | }; |
| 484 | |
| 485 | static PyType_Spec PyCursesPanel_Type_spec = { |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 486 | "_curses_panel.panel", |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 487 | sizeof(PyCursesPanelObject), |
| 488 | 0, |
| 489 | Py_TPFLAGS_DEFAULT, |
| 490 | PyCursesPanel_Type_slots |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 491 | }; |
| 492 | |
| 493 | /* Wrapper for panel_above(NULL). This function returns the bottom |
| 494 | panel of the stack, so it's renamed to bottom_panel(). |
| 495 | panel.above() *requires* a panel object in the first place which |
| 496 | may be undesirable. */ |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 497 | /*[clinic input] |
| 498 | _curses_panel.bottom_panel |
| 499 | |
| 500 | Return the bottom panel in the panel stack. |
| 501 | [clinic start generated code]*/ |
| 502 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 503 | static PyObject * |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 504 | _curses_panel_bottom_panel_impl(PyObject *module) |
| 505 | /*[clinic end generated code: output=3aba9f985f4c2bd0 input=634c2a8078b3d7e4]*/ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 506 | { |
| 507 | PANEL *pan; |
| 508 | PyCursesPanelObject *po; |
| 509 | |
| 510 | PyCursesInitialised; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 511 | |
| 512 | pan = panel_above(NULL); |
| 513 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 514 | if (pan == NULL) { /* valid output, it means |
| 515 | there's no panel at all */ |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 516 | Py_RETURN_NONE; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 517 | } |
| 518 | po = find_po(pan); |
| 519 | if (po == NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 520 | PyErr_SetString(PyExc_RuntimeError, |
| 521 | "panel_above: can't find Panel Object"); |
| 522 | return NULL; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 523 | } |
| 524 | Py_INCREF(po); |
| 525 | return (PyObject *)po; |
| 526 | } |
| 527 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 528 | /*[clinic input] |
| 529 | _curses_panel.new_panel |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 530 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 531 | win: object(type="PyCursesWindowObject *", subclass_of="&PyCursesWindow_Type") |
| 532 | / |
| 533 | |
| 534 | Return a panel object, associating it with the given window win. |
| 535 | [clinic start generated code]*/ |
| 536 | |
| 537 | static PyObject * |
| 538 | _curses_panel_new_panel_impl(PyObject *module, PyCursesWindowObject *win) |
| 539 | /*[clinic end generated code: output=45e948e0176a9bd2 input=74d4754e0ebe4800]*/ |
| 540 | { |
| 541 | PANEL *pan = new_panel(win->win); |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 542 | if (pan == NULL) { |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 543 | PyErr_SetString(_curses_panelstate_global->PyCursesError, catchall_NULL); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 544 | return NULL; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 545 | } |
| 546 | return (PyObject *)PyCursesPanel_New(pan, win); |
| 547 | } |
| 548 | |
| 549 | |
| 550 | /* Wrapper for panel_below(NULL). This function returns the top panel |
| 551 | of the stack, so it's renamed to top_panel(). panel.below() |
| 552 | *requires* a panel object in the first place which may be |
| 553 | undesirable. */ |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 554 | /*[clinic input] |
| 555 | _curses_panel.top_panel |
| 556 | |
| 557 | Return the top panel in the panel stack. |
| 558 | [clinic start generated code]*/ |
| 559 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 560 | static PyObject * |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 561 | _curses_panel_top_panel_impl(PyObject *module) |
| 562 | /*[clinic end generated code: output=86704988bea8508e input=e62d6278dba39e79]*/ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 563 | { |
| 564 | PANEL *pan; |
| 565 | PyCursesPanelObject *po; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 566 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 567 | PyCursesInitialised; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 568 | |
| 569 | pan = panel_below(NULL); |
| 570 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 571 | if (pan == NULL) { /* valid output, it means |
| 572 | there's no panel at all */ |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 573 | Py_RETURN_NONE; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 574 | } |
| 575 | po = find_po(pan); |
| 576 | if (po == NULL) { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 577 | PyErr_SetString(PyExc_RuntimeError, |
| 578 | "panel_below: can't find Panel Object"); |
| 579 | return NULL; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 580 | } |
| 581 | Py_INCREF(po); |
| 582 | return (PyObject *)po; |
| 583 | } |
| 584 | |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 585 | /*[clinic input] |
| 586 | _curses_panel.update_panels |
| 587 | |
| 588 | Updates the virtual screen after changes in the panel stack. |
| 589 | |
| 590 | This does not call curses.doupdate(), so you’ll have to do this yourself. |
| 591 | [clinic start generated code]*/ |
| 592 | |
| 593 | static PyObject * |
| 594 | _curses_panel_update_panels_impl(PyObject *module) |
| 595 | /*[clinic end generated code: output=2f3b4c2e03d90ded input=a127069202b0a097]*/ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 596 | { |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 597 | PyCursesInitialised; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 598 | update_panels(); |
Serhiy Storchaka | 228b12e | 2017-01-23 09:47:21 +0200 | [diff] [blame] | 599 | Py_RETURN_NONE; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | |
| 603 | /* List of functions defined in the module */ |
| 604 | |
| 605 | static PyMethodDef PyCurses_methods[] = { |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 606 | _CURSES_PANEL_BOTTOM_PANEL_METHODDEF |
| 607 | _CURSES_PANEL_NEW_PANEL_METHODDEF |
| 608 | _CURSES_PANEL_TOP_PANEL_METHODDEF |
| 609 | _CURSES_PANEL_UPDATE_PANELS_METHODDEF |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 610 | {NULL, NULL} /* sentinel */ |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 611 | }; |
| 612 | |
| 613 | /* Initialization function for the module */ |
| 614 | |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 615 | |
| 616 | static struct PyModuleDef _curses_panelmodule = { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 617 | PyModuleDef_HEAD_INIT, |
| 618 | "_curses_panel", |
| 619 | NULL, |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 620 | sizeof(_curses_panelstate), |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 621 | PyCurses_methods, |
| 622 | NULL, |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 623 | _curses_panel_traverse, |
| 624 | _curses_panel_clear, |
| 625 | _curses_panel_free |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 626 | }; |
| 627 | |
Mark Hammond | fe51c6d | 2002-08-02 02:27:13 +0000 | [diff] [blame] | 628 | PyMODINIT_FUNC |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 629 | PyInit__curses_panel(void) |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 630 | { |
| 631 | PyObject *m, *d, *v; |
| 632 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 633 | /* Create the module and add the functions */ |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 634 | m = PyModule_Create(&_curses_panelmodule); |
Neal Norwitz | 1ac754f | 2006-01-19 06:09:39 +0000 | [diff] [blame] | 635 | if (m == NULL) |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 636 | goto fail; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 637 | d = PyModule_GetDict(m); |
| 638 | |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 639 | /* Initialize object type */ |
Serhiy Storchaka | e3f1b09 | 2016-05-08 20:46:22 +0300 | [diff] [blame] | 640 | v = PyType_FromSpec(&PyCursesPanel_Type_spec); |
| 641 | if (v == NULL) |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 642 | goto fail; |
Serhiy Storchaka | e3f1b09 | 2016-05-08 20:46:22 +0300 | [diff] [blame] | 643 | ((PyTypeObject *)v)->tp_new = NULL; |
| 644 | _curses_panelstate(m)->PyCursesPanel_Type = v; |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 645 | |
| 646 | import_curses(); |
Victor Stinner | 569f364 | 2013-07-18 02:31:21 +0200 | [diff] [blame] | 647 | if (PyErr_Occurred()) |
| 648 | goto fail; |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 649 | |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 650 | /* For exception _curses_panel.error */ |
Martin v. Löwis | c838ec1 | 2012-06-14 16:00:24 +0200 | [diff] [blame] | 651 | _curses_panelstate(m)->PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL); |
| 652 | PyDict_SetItemString(d, "error", _curses_panelstate(m)->PyCursesError); |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 653 | |
| 654 | /* Make the version available */ |
Neal Norwitz | 53cbdaa | 2007-08-23 21:42:55 +0000 | [diff] [blame] | 655 | v = PyUnicode_FromString(PyCursesVersion); |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 656 | PyDict_SetItemString(d, "version", v); |
| 657 | PyDict_SetItemString(d, "__version__", v); |
| 658 | Py_DECREF(v); |
Serhiy Storchaka | b00854c | 2018-05-10 11:27:23 +0300 | [diff] [blame] | 659 | |
| 660 | Py_INCREF(_curses_panelstate(m)->PyCursesPanel_Type); |
| 661 | PyModule_AddObject(m, "panel", (PyObject *)_curses_panelstate(m)->PyCursesPanel_Type); |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 662 | return m; |
Martin v. Löwis | bc07cb8 | 2012-06-14 16:01:23 +0200 | [diff] [blame] | 663 | fail: |
| 664 | Py_XDECREF(m); |
| 665 | return NULL; |
Andrew M. Kuchling | 7b59ed2 | 2000-12-22 21:54:12 +0000 | [diff] [blame] | 666 | } |