Skip to content

Commit

Permalink
Python plugin: Added Tileset.sharedPointer() function
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bjorn committed Sep 11, 2019
1 parent 8c0ad00 commit 75833c4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/libtiled/logginginterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down
18 changes: 17 additions & 1 deletion src/plugins/python/pythonbind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/plugins/python/tiledbinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down

0 comments on commit 75833c4

Please sign in to comment.