/* * Interface to the ncurses panel library * * Original version by Thomas Gellekum */ /* Release Number */ static const char PyCursesVersion[] = …; /* Includes */ // clinic/_curses_panel.c.h uses internal pycore_modsupport.h API #ifndef Py_BUILD_CORE_BUILTIN #define Py_BUILD_CORE_MODULE … #endif #include "Python.h" #include "py_curses.h" #if defined(HAVE_NCURSESW_PANEL_H) # include <ncursesw/panel.h> #elif defined(HAVE_NCURSES_PANEL_H) # include <ncurses/panel.h> #elif defined(HAVE_PANEL_H) # include <panel.h> #endif _curses_panel_state; static inline _curses_panel_state * get_curses_panel_state(PyObject *module) { … } static int _curses_panel_clear(PyObject *mod) { … } static int _curses_panel_traverse(PyObject *mod, visitproc visit, void *arg) { … } static void _curses_panel_free(void *mod) { … } /* Utility Functions */ /* * Check the return code from a curses function and return None * or raise an exception as appropriate. */ static PyObject * PyCursesCheckERR(_curses_panel_state *state, int code, const char *fname) { … } /***************************************************************************** The Panel Object ******************************************************************************/ /* Definition of the panel object and panel type */ PyCursesPanelObject; /* Some helper functions. The problem is that there's always a window associated with a panel. To ensure that Python's GC doesn't pull this window from under our feet we need to keep track of references to the corresponding window object within Python. We can't use dupwin(oldwin) to keep a copy of the curses WINDOW because the contents of oldwin is copied only once; code like win = newwin(...) pan = win.panel() win.addstr(some_string) pan.window().addstr(other_string) will fail. */ /* We keep a linked list of PyCursesPanelObjects, lop. A list should suffice, I don't expect more than a handful or at most a few dozens of panel objects within a typical program. */ list_of_panels; /* list anchor */ static list_of_panels *lop; /* Insert a new panel object into lop */ static int insert_lop(PyCursesPanelObject *po) { … } /* Remove the panel object from lop */ static void remove_lop(PyCursesPanelObject *po) { … } /* Return the panel object that corresponds to pan */ static PyCursesPanelObject * find_po(PANEL *pan) { … } /*[clinic input] module _curses_panel class _curses_panel.panel "PyCursesPanelObject *" "&PyCursesPanel_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=2f4ef263ca850a31]*/ #include "clinic/_curses_panel.c.h" /* ------------- PANEL routines --------------- */ /*[clinic input] _curses_panel.panel.bottom cls: defining_class Push the panel to the bottom of the stack. [clinic start generated code]*/ static PyObject * _curses_panel_panel_bottom_impl(PyCursesPanelObject *self, PyTypeObject *cls) /*[clinic end generated code: output=8ec7fbbc08554021 input=6b7d2c0578b5a1c4]*/ { … } /*[clinic input] _curses_panel.panel.hide cls: defining_class Hide the panel. This does not delete the object, it just makes the window on screen invisible. [clinic start generated code]*/ static PyObject * _curses_panel_panel_hide_impl(PyCursesPanelObject *self, PyTypeObject *cls) /*[clinic end generated code: output=cc6ab7203cdc1450 input=1bfc741f473e6055]*/ { … } /*[clinic input] _curses_panel.panel.show cls: defining_class Display the panel (which might have been hidden). [clinic start generated code]*/ static PyObject * _curses_panel_panel_show_impl(PyCursesPanelObject *self, PyTypeObject *cls) /*[clinic end generated code: output=dc3421de375f0409 input=8122e80151cb4379]*/ { … } /*[clinic input] _curses_panel.panel.top cls: defining_class Push panel to the top of the stack. [clinic start generated code]*/ static PyObject * _curses_panel_panel_top_impl(PyCursesPanelObject *self, PyTypeObject *cls) /*[clinic end generated code: output=10a072e511e873f7 input=1f372d597dda3379]*/ { … } /* Allocation and deallocation of Panel Objects */ static PyObject * PyCursesPanel_New(_curses_panel_state *state, PANEL *pan, PyCursesWindowObject *wo) { … } static void PyCursesPanel_Dealloc(PyCursesPanelObject *po) { … } /* panel_above(NULL) returns the bottom panel in the stack. To get this behaviour we use curses.panel.bottom_panel(). */ /*[clinic input] _curses_panel.panel.above Return the panel above the current panel. [clinic start generated code]*/ static PyObject * _curses_panel_panel_above_impl(PyCursesPanelObject *self) /*[clinic end generated code: output=70ac06d25fd3b4da input=c059994022976788]*/ { … } /* panel_below(NULL) returns the top panel in the stack. To get this behaviour we use curses.panel.top_panel(). */ /*[clinic input] _curses_panel.panel.below Return the panel below the current panel. [clinic start generated code]*/ static PyObject * _curses_panel_panel_below_impl(PyCursesPanelObject *self) /*[clinic end generated code: output=282861122e06e3de input=cc08f61936d297c6]*/ { … } /*[clinic input] _curses_panel.panel.hidden Return True if the panel is hidden (not visible), False otherwise. [clinic start generated code]*/ static PyObject * _curses_panel_panel_hidden_impl(PyCursesPanelObject *self) /*[clinic end generated code: output=66eebd1ab4501a71 input=453d4b4fce25e21a]*/ { … } /*[clinic input] _curses_panel.panel.move cls: defining_class y: int x: int / Move the panel to the screen coordinates (y, x). [clinic start generated code]*/ static PyObject * _curses_panel_panel_move_impl(PyCursesPanelObject *self, PyTypeObject *cls, int y, int x) /*[clinic end generated code: output=ce546c93e56867da input=60a0e7912ff99849]*/ { … } /*[clinic input] _curses_panel.panel.window Return the window object associated with the panel. [clinic start generated code]*/ static PyObject * _curses_panel_panel_window_impl(PyCursesPanelObject *self) /*[clinic end generated code: output=5f05940d4106b4cb input=6067353d2c307901]*/ { … } /*[clinic input] _curses_panel.panel.replace cls: defining_class win: object(type="PyCursesWindowObject *", subclass_of="&PyCursesWindow_Type") / Change the window associated with the panel to the window win. [clinic start generated code]*/ static PyObject * _curses_panel_panel_replace_impl(PyCursesPanelObject *self, PyTypeObject *cls, PyCursesWindowObject *win) /*[clinic end generated code: output=c71f95c212d58ae7 input=dbec7180ece41ff5]*/ { … } /*[clinic input] _curses_panel.panel.set_userptr cls: defining_class obj: object / Set the panel's user pointer to obj. [clinic start generated code]*/ static PyObject * _curses_panel_panel_set_userptr_impl(PyCursesPanelObject *self, PyTypeObject *cls, PyObject *obj) /*[clinic end generated code: output=db74f3db07b28080 input=e3fee2ff7b1b8e48]*/ { … } /*[clinic input] _curses_panel.panel.userptr cls: defining_class Return the user pointer for the panel. [clinic start generated code]*/ static PyObject * _curses_panel_panel_userptr_impl(PyCursesPanelObject *self, PyTypeObject *cls) /*[clinic end generated code: output=eea6e6f39ffc0179 input=f22ca4f115e30a80]*/ { … } /* Module interface */ static PyMethodDef PyCursesPanel_Methods[] = …; /* -------------------------------------------------------*/ static PyType_Slot PyCursesPanel_Type_slots[] = …; static PyType_Spec PyCursesPanel_Type_spec = …; /* Wrapper for panel_above(NULL). This function returns the bottom panel of the stack, so it's renamed to bottom_panel(). panel.above() *requires* a panel object in the first place which may be undesirable. */ /*[clinic input] _curses_panel.bottom_panel Return the bottom panel in the panel stack. [clinic start generated code]*/ static PyObject * _curses_panel_bottom_panel_impl(PyObject *module) /*[clinic end generated code: output=3aba9f985f4c2bd0 input=634c2a8078b3d7e4]*/ { … } /*[clinic input] _curses_panel.new_panel win: object(type="PyCursesWindowObject *", subclass_of="&PyCursesWindow_Type") / Return a panel object, associating it with the given window win. [clinic start generated code]*/ static PyObject * _curses_panel_new_panel_impl(PyObject *module, PyCursesWindowObject *win) /*[clinic end generated code: output=45e948e0176a9bd2 input=74d4754e0ebe4800]*/ { … } /* Wrapper for panel_below(NULL). This function returns the top panel of the stack, so it's renamed to top_panel(). panel.below() *requires* a panel object in the first place which may be undesirable. */ /*[clinic input] _curses_panel.top_panel Return the top panel in the panel stack. [clinic start generated code]*/ static PyObject * _curses_panel_top_panel_impl(PyObject *module) /*[clinic end generated code: output=86704988bea8508e input=e62d6278dba39e79]*/ { … } /*[clinic input] _curses_panel.update_panels Updates the virtual screen after changes in the panel stack. This does not call curses.doupdate(), so you'll have to do this yourself. [clinic start generated code]*/ static PyObject * _curses_panel_update_panels_impl(PyObject *module) /*[clinic end generated code: output=2f3b4c2e03d90ded input=5299624c9a708621]*/ { … } /* List of functions defined in the module */ static PyMethodDef PyCurses_methods[] = …; /* Initialization function for the module */ static int _curses_panel_exec(PyObject *mod) { … } static PyModuleDef_Slot _curses_slots[] = …; static struct PyModuleDef _curses_panelmodule = …; PyMODINIT_FUNC PyInit__curses_panel(void) { … }