python: Started with NcPlane

This commit is contained in:
igo95862 2021-04-17 11:14:04 +03:00
parent 4e820c779d
commit f88dededc0
No known key found for this signature in database
GPG Key ID: F1A55E62951B2143
4 changed files with 59 additions and 0 deletions

View File

@ -36,9 +36,11 @@ PyInit_notcurses(void)
// Type ready?
GNU_PY_TYPE_READY(&Notcurses_Type);
GNU_PY_TYPE_READY(&NcPlane_Type);
// Add objects
GNU_PY_MODULE_ADD_OBJECT(py_module, (PyObject *)&Notcurses_Type, "Notcurses");
GNU_PY_MODULE_ADD_OBJECT(py_module, (PyObject *)&NcPlane_Type, "NcPlane");
// background cannot be highcontrast, only foreground
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_ALPHA_HIGHCONTRAST));

View File

@ -34,8 +34,11 @@ typedef struct
{
PyObject_HEAD;
struct ncplane *ncplane_ptr;
bool is_stdplane;
} NcPlaneObject;
extern PyTypeObject NcPlane_Type;
typedef struct
{
PyObject_HEAD;

53
python/notcurses/plane.c Normal file
View File

@ -0,0 +1,53 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright 2020, 2021 igo95862
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "notcurses-python.h"
static void
NcPlane_dealloc(NcPlaneObject *self)
{
if (NULL != self->ncplane_ptr && !self->is_stdplane)
{
ncplane_destroy(self->ncplane_ptr);
}
Py_TYPE(self)->tp_free(self);
}
static PyObject *
NcPlane_new(PyTypeObject *Py_UNUSED(subtype), PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds))
{
PyErr_SetString(PyExc_ValueError, "NcPlane should NOT be initialied directly.");
return NULL;
}
static PyMethodDef NcPlane_methods[] = {
{NULL, NULL, 0, NULL},
};
PyTypeObject NcPlane_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "notcurses.NcPlane",
.tp_doc = "Notcurses Plane",
.tp_basicsize = sizeof(NcPlaneObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = NcPlane_new,
.tp_dealloc = (destructor)NcPlane_dealloc,
.tp_methods = NcPlane_methods,
};

View File

@ -39,6 +39,7 @@ setup(
'notcurses/context.c',
'notcurses/main.c',
'notcurses/misc.c',
'notcurses/plane.c',
],
libraries=['notcurses'],
language='c',