From 75833c4d1407b1380bfc0baa14479a42662caf68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Wed, 11 Sep 2019 11:19:14 +0200 Subject: [PATCH] Python plugin: Added Tileset.sharedPointer() function To get the shared pointer from a Tileset* value, since this is needed to pass it as an arguement to Map.indexOfTileset(). Also added trimming of trailing whitespace, which was causing empty lines in the Issues view (affecting Python script output). See issue #2191 --- src/libtiled/logginginterface.cpp | 7 ++++++- src/plugins/python/pythonbind.cpp | 18 +++++++++++++++++- src/plugins/python/tiledbinding.py | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/libtiled/logginginterface.cpp b/src/libtiled/logginginterface.cpp index 7166e4f01b..ac4e6fb239 100644 --- a/src/libtiled/logginginterface.cpp +++ b/src/libtiled/logginginterface.cpp @@ -121,7 +121,12 @@ void LoggingInterface::log(OutputType type, const QString &message) break; } - report(Issue(severity, message)); + // Remove any trailing newlines + QString messageCopy = message; + while (messageCopy.endsWith(QLatin1Char('\n'))) + messageCopy.chop(1); + + report(Issue(severity, messageCopy)); } diff --git a/src/plugins/python/pythonbind.cpp b/src/plugins/python/pythonbind.cpp index 932cc19350..5a81f239d7 100644 --- a/src/plugins/python/pythonbind.cpp +++ b/src/plugins/python/pythonbind.cpp @@ -3980,6 +3980,21 @@ _wrap_PyTiledTileset_setTransparentColor(PyTiledTileset *self, PyObject *args, P } +PyObject * +_wrap_PyTiledTileset_sharedPointer(PyTiledTileset *self) +{ + PyObject *py_retval; + PyTiledSharedTileset *py_SharedTileset; + + Tiled::SharedTileset retval = self->obj->sharedPointer(); + py_SharedTileset = PyObject_New(PyTiledSharedTileset, &PyTiledSharedTileset_Type); + py_SharedTileset->flags = PYBINDGEN_WRAPPER_FLAG_NONE; + py_SharedTileset->obj = new Tiled::SharedTileset(retval); + py_retval = Py_BuildValue((char *) "N", py_SharedTileset); + return py_retval; +} + + PyObject * _wrap_PyTiledTileset_tileAt(PyTiledTileset *self, PyObject *args, PyObject *kwargs) { @@ -4104,6 +4119,7 @@ static PyMethodDef PyTiledTileset_methods[] = { {(char *) "setName", (PyCFunction) _wrap_PyTiledTileset_setName, METH_KEYWORDS|METH_VARARGS, "setName(name)\n\ntype: name: QString" }, {(char *) "setTileOffset", (PyCFunction) _wrap_PyTiledTileset_setTileOffset, METH_KEYWORDS|METH_VARARGS, "setTileOffset(offset)\n\ntype: offset: QPoint" }, {(char *) "setTransparentColor", (PyCFunction) _wrap_PyTiledTileset_setTransparentColor, METH_KEYWORDS|METH_VARARGS, "setTransparentColor(col)\n\ntype: col: QColor" }, + {(char *) "sharedPointer", (PyCFunction) _wrap_PyTiledTileset_sharedPointer, METH_NOARGS, "sharedPointer()\n\n" }, {(char *) "tileAt", (PyCFunction) _wrap_PyTiledTileset_tileAt, METH_KEYWORDS|METH_VARARGS, "tileAt(id)\n\ntype: id: int" }, {(char *) "tileCount", (PyCFunction) _wrap_PyTiledTileset_tileCount, METH_NOARGS, "tileCount()\n\n" }, {(char *) "tileHeight", (PyCFunction) _wrap_PyTiledTileset_tileHeight, METH_NOARGS, "tileHeight()\n\n" }, @@ -7872,7 +7888,7 @@ PyTypeObject PyPythonPythonScript_Type = { (getattrofunc)NULL, /* tp_getattro */ (setattrofunc)NULL, /* tp_setattro */ (PyBufferProcs*)NULL, /* tp_as_buffer */ - Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ + Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_DEFAULT, /* tp_flags */ "", /* Documentation string */ (traverseproc)PyPythonPythonScript__tp_traverse, /* tp_traverse */ (inquiry)PyPythonPythonScript__tp_clear, /* tp_clear */ diff --git a/src/plugins/python/tiledbinding.py b/src/plugins/python/tiledbinding.py index dfeb7543fe..5d8a744607 100755 --- a/src/plugins/python/tiledbinding.py +++ b/src/plugins/python/tiledbinding.py @@ -143,6 +143,7 @@ def _decorate(obj, *args, **kwargs): cls_tileset.add_method('imageSourceString', 'QString', []) cls_tileset.add_method('setImageSource', None, [('QString','source')]) cls_tileset.add_method('isCollection', 'bool', []) +cls_tileset.add_method('sharedPointer', 'Tiled::SharedTileset', []) cls_tile.add_constructor([param('const QPixmap&','image'), param('int','id'), param('Tileset*','tileset',transfer_ownership=False)])