mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
[py] Add NcInput type.
This commit is contained in:
parent
9d648e9457
commit
ed2a459b6f
@ -15,7 +15,8 @@
|
||||
# limitations under the License.
|
||||
|
||||
from .notcurses import (
|
||||
NcPlane, Notcurses, ncchannel_alpha, ncchannel_b, ncchannel_default_p,
|
||||
NcPlane, Notcurses, NcInput,
|
||||
ncchannel_alpha, ncchannel_b, ncchannel_default_p,
|
||||
ncchannel_g, ncchannel_palindex, ncchannel_palindex_p, ncchannel_r,
|
||||
ncchannel_rgb8, ncchannel_rgb_initializer, ncchannel_set,
|
||||
ncchannel_set_alpha, ncchannel_set_default, ncchannel_set_palindex,
|
||||
|
@ -36,6 +36,28 @@ static struct PyModuleDef NotcursesMiscModule = {
|
||||
.m_free = (freefunc)Notcurses_module_free,
|
||||
};
|
||||
|
||||
static PyStructSequence_Field NcInput_fields[] = {
|
||||
{"id", "Unicode codepoint or synthesized NCKEY event"},
|
||||
{"y", "y cell coordinate of event, -1 for undefined"},
|
||||
{"x", "x cell coordinate of event, -1 for undefined"},
|
||||
{"utf8", "utf8 representation, if one exists"},
|
||||
// Note: alt, shift, ctrl fields deprecated in C API are omitted.
|
||||
{"evtype", NULL},
|
||||
{"modifiers", "bitmask over NCKEY_MOD_*"},
|
||||
{"ypx", "y pixel offset within cell, -1 for undefined"},
|
||||
{"xpx", "x pixel offset within cell, -1 for undefined"},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
static struct PyStructSequence_Desc NcInput_desc = {
|
||||
.name = "NcInput",
|
||||
.doc = "Notcurses input event",
|
||||
.fields = NcInput_fields,
|
||||
.n_in_sequence = 8,
|
||||
};
|
||||
|
||||
PyTypeObject *NcInput_Type;
|
||||
|
||||
PyMODINIT_FUNC
|
||||
PyInit_notcurses(void)
|
||||
{
|
||||
@ -53,6 +75,11 @@ PyInit_notcurses(void)
|
||||
GNU_PY_MODULE_ADD_OBJECT(py_module, (PyObject *)&Notcurses_Type, "Notcurses");
|
||||
GNU_PY_MODULE_ADD_OBJECT(py_module, (PyObject *)&NcPlane_Type, "NcPlane");
|
||||
|
||||
NcInput_Type = PyStructSequence_NewType(&NcInput_desc);
|
||||
if (NcInput_Type == NULL)
|
||||
return NULL;
|
||||
GNU_PY_MODULE_ADD_OBJECT(py_module, (PyObject *)NcInput_Type, "NcInput");
|
||||
|
||||
// background cannot be highcontrast, only foreground
|
||||
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NCALPHA_HIGHCONTRAST));
|
||||
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NCALPHA_TRANSPARENT));
|
||||
|
@ -122,12 +122,6 @@ typedef struct
|
||||
struct nccell nccell;
|
||||
} NcCellObject;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD;
|
||||
struct ncinput ncinput;
|
||||
} NcInputObject;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD;
|
||||
@ -140,6 +134,8 @@ typedef struct
|
||||
struct ncpalette ncpalette;
|
||||
} Palette256Object;
|
||||
|
||||
extern PyTypeObject *NcInput_Type;
|
||||
|
||||
// Imports
|
||||
|
||||
extern PyObject *traceback_format_exception;
|
||||
|
Loading…
x
Reference in New Issue
Block a user