feat(Python): establish proper inheritance hierarchy for UI types
All UIDrawable-derived Python types now properly inherit from the Drawable base class in Python, matching the C++ inheritance structure. Changes: - Add Py_TPFLAGS_BASETYPE to PyDrawableType to allow inheritance - Set tp_base = &mcrfpydef::PyDrawableType for all UI types - Add PyDrawable.h include to UI type headers - Rename _Drawable to Drawable and update error message This enables proper Python inheritance: Frame, Caption, Sprite, Grid, and Entity all inherit from Drawable, allowing shared functionality and isinstance() checks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e1c6c53157
commit
1d90cdab1d
6 changed files with 14 additions and 7 deletions
|
|
@ -154,14 +154,14 @@ static PyMethodDef PyDrawable_methods[] = {
|
|||
// Type initialization
|
||||
static int PyDrawable_init(PyDrawableObject* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "_Drawable is an abstract base class and cannot be instantiated directly");
|
||||
PyErr_SetString(PyExc_TypeError, "Drawable is an abstract base class and cannot be instantiated directly");
|
||||
return -1;
|
||||
}
|
||||
|
||||
namespace mcrfpydef {
|
||||
PyTypeObject PyDrawableType = {
|
||||
.ob_base = {.ob_base = {.ob_refcnt = 1, .ob_type = NULL}, .ob_size = 0},
|
||||
.tp_name = "mcrfpy._Drawable",
|
||||
.tp_name = "mcrfpy.Drawable",
|
||||
.tp_basicsize = sizeof(PyDrawableObject),
|
||||
.tp_itemsize = 0,
|
||||
.tp_dealloc = (destructor)[](PyObject* self) {
|
||||
|
|
@ -169,7 +169,7 @@ namespace mcrfpydef {
|
|||
obj->data.reset();
|
||||
Py_TYPE(self)->tp_free(self);
|
||||
},
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT, // | Py_TPFLAGS_BASETYPE,
|
||||
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
||||
.tp_doc = PyDoc_STR("Base class for all drawable UI elements"),
|
||||
.tp_methods = PyDrawable_methods,
|
||||
.tp_getset = PyDrawable_getsetters,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue