mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-10-31 15:20:13 +00:00
python: Started with NcPlane
This commit is contained in:
parent
4e820c779d
commit
f88dededc0
@ -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));
|
||||
|
@ -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
53
python/notcurses/plane.c
Normal 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,
|
||||
};
|
@ -39,6 +39,7 @@ setup(
|
||||
'notcurses/context.c',
|
||||
'notcurses/main.c',
|
||||
'notcurses/misc.c',
|
||||
'notcurses/plane.c',
|
||||
],
|
||||
libraries=['notcurses'],
|
||||
language='c',
|
||||
|
Loading…
Reference in New Issue
Block a user