Extra members of tmxlib classes

To avoid clutter, some members aren’t mentioned in their respective classes’ documentation. This page documents such members, so that they can be linked.

(And also to make the doc coverage tool happy.)

class tmxlib.layer.TileLayer

Layer methods

TileLayer.to_dict()

Export to a dict compatible with Tiled’s JSON plugin

classmethod TileLayer.from_dict(dct, *args, **kwargs)

Import from a dict compatible with Tiled’s JSON plugin

class tmxlib.layer.ObjectLayer

NamedList methods

ObjectLayer.__getitem__(index_or_name)

Same as list’s, except non-slice indices may be names.

ObjectLayer.__setitem__(index_or_name, value)

Same as list’s, but non-slice indices may be names instead of ints.

ObjectLayer.__contains__(item_or_name)

item_or_name in self

NamedElementLists can be queried either by name or by item.

ObjectLayer.count(value) → integer -- return number of occurrences of value
ObjectLayer.append(value)

S.append(object) – append object to the end of the sequence

ObjectLayer.extend(values)

S.extend(iterable) – extend sequence by appending elements from the iterable

ObjectLayer.pop([index]) → item -- remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

ObjectLayer.remove(value)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

ObjectLayer.reverse()

S.reverse() – reverse IN PLACE

ObjectLayer.insert(index_or_name, value)

Same as list.insert, except indices may be names instead of ints.

ObjectLayer.insert_after(index_or_name, value)

Insert the new value after the position specified by index_or_name

For numerical indexes, the same as insert(index + 1, value). Useful when indexing by strings.

ObjectLayer.move(index_or_name, amount)

Move an item by the specified number of indexes

amount can be negative. For example, “move layer down” translates to layers.move(idx, -1)

The method will clamp out-of range amounts, so, for eample, lst.move(0, -1) will do nothing.

ObjectLayer.retrieved_value(item)

Called when an item is being retrieved from the list.

Return the object that will actually be retrieved.

This method must undo any modifications that stored_value does.

ObjectLayer.stored_value(item)[source]

Layer methods

ObjectLayer.to_dict()[source]

Export to a dict compatible with Tiled’s JSON plugin

classmethod ObjectLayer.from_dict(dct, *args, **kwargs)[source]

Import from a dict compatible with Tiled’s JSON plugin

class tmxlib.layer.ImageLayer

Layer methods

ImageLayer.to_dict()

Export to a dict compatible with Tiled’s JSON plugin

classmethod ImageLayer.from_dict(dct, *args, **kwargs)

Import from a dict compatible with Tiled’s JSON plugin

class tmxlib.layer.LayerList

NamedList methods

LayerList.__getitem__(index_or_name)

Same as list’s, except non-slice indices may be names.

LayerList.__setitem__(index_or_name, value)

Same as list’s, but non-slice indices may be names instead of ints.

LayerList.__contains__(item_or_name)

item_or_name in self

NamedElementLists can be queried either by name or by item.

LayerList.index(value) → integer -- return first index of value.

Raises ValueError if the value is not present.

LayerList.count(value) → integer -- return number of occurrences of value
LayerList.append(value)

S.append(object) – append object to the end of the sequence

LayerList.extend(values)

S.extend(iterable) – extend sequence by appending elements from the iterable

LayerList.pop([index]) → item -- remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

LayerList.remove(value)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

LayerList.reverse()

S.reverse() – reverse IN PLACE

LayerList.insert(index_or_name, value)

Same as list.insert, except indices may be names instead of ints.

LayerList.insert_after(index_or_name, value)

Insert the new value after the position specified by index_or_name

For numerical indexes, the same as insert(index + 1, value). Useful when indexing by strings.

LayerList.move(index_or_name, amount)

Move an item by the specified number of indexes

amount can be negative. For example, “move layer down” translates to layers.move(idx, -1)

The method will clamp out-of range amounts, so, for eample, lst.move(0, -1) will do nothing.

LayerList.modification_context(*args, **kwds)

Context in which all modifications take place.

The default implementation nullifies the modifications if an exception is raised.

Note that the manager may nest, in which case the outermost one should be treated as an atomic operation.

LayerList.retrieved_value(item)

Called when an item is being retrieved from the list.

Return the object that will actually be retrieved.

This method must undo any modifications that stored_value does.

LayerList.stored_value(layer)[source]

Prevent layers that aren’t from this map.

class tmxlib.tileset.TilesetList

NamedList methods

TilesetList.__getitem__(index_or_name)

Same as list’s, except non-slice indices may be names.

TilesetList.__setitem__(index_or_name, value)

Same as list’s, but non-slice indices may be names instead of ints.

TilesetList.__contains__(item_or_name)

item_or_name in self

NamedElementLists can be queried either by name or by item.

TilesetList.index(value) → integer -- return first index of value.

Raises ValueError if the value is not present.

TilesetList.count(value) → integer -- return number of occurrences of value
TilesetList.append(value)

S.append(object) – append object to the end of the sequence

TilesetList.extend(values)

S.extend(iterable) – extend sequence by appending elements from the iterable

TilesetList.pop([index]) → item -- remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

TilesetList.remove(value)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

TilesetList.reverse()

S.reverse() – reverse IN PLACE

TilesetList.insert(index_or_name, value)

Same as list.insert, except indices may be names instead of ints.

TilesetList.insert_after(index_or_name, value)

Insert the new value after the position specified by index_or_name

For numerical indexes, the same as insert(index + 1, value). Useful when indexing by strings.

TilesetList.move(index_or_name, amount)

Move an item by the specified number of indexes

amount can be negative. For example, “move layer down” translates to layers.move(idx, -1)

The method will clamp out-of range amounts, so, for eample, lst.move(0, -1) will do nothing.

TilesetList.retrieved_value(item)

Called when an item is being retrieved from the list.

Return the object that will actually be retrieved.

This method must undo any modifications that stored_value does.

TilesetList.stored_value(item)

Called when an item is being inserted into the list.

Return the object that will actually be stored.

To prevent incompatible items, subclasses may raise an exception here.

This method must undo any modifications that retrieved_value does.

class tmxlib.tileset.ImageTileset

Load/save methods (see tmxlib.fileio.ReadWriteBase):

classmethod ImageTileset.open(filename, shared=False)

Load an object of this class from a file

Parameters:
  • filename – The file from which to load
  • shared – Objects loaded from a single file with shared=True will be reused. Modifications to this shared object will, naturally, be visible from all variables that reference it. (External tilesets are loaded as shared by default.)
classmethod ImageTileset.load(string)

Load an object of this class from a string.

Parameters:string – String containing the XML description of the object, as it would be read from a file.
ImageTileset.save(filename)

Save this object to a file

Parameters:filename – Name of the file to save to.
ImageTileset.dump(string)

Save this object as a string

Returns:String with the representation of the object, suitable for writing to a file.
ImageTileset.to_dict(**kwargs)[source]

Export to a dict compatible with Tiled’s JSON plugin

classmethod ImageTileset.from_dict(dct, *args, **kwargs)[source]

Import from a dict compatible with Tiled’s JSON plugin

Overridden methods (see tmxlib.tileset.Tileset):

ImageTileset.tile_image(number)

Return the image used by the given tile

GID calculation methods (see tmxlib.tileset.Tileset):

Note

TilesetList depends on the specific GID calculation algorithm provided by these methods to renumber a map’s tiles when tilesets are moved around. Don’t override these unless your subclass is not used with vanilla TilesetLists.

ImageTileset.first_gid(map)

Return the first gid used by this tileset in the given map

ImageTileset.end_gid(map)

Return the first gid after this tileset in the given map

class tmxlib.mapobject.RectangleObject

MapObject methods

RectangleObject.to_dict()[source]
classmethod RectangleObject.from_dict(dct, *args, **kwargs)[source]

class tmxlib.mapobject.EllipseObject

MapObject methods

EllipseObject.to_dict()[source]
classmethod EllipseObject.from_dict(dct, *args, **kwargs)[source]

class tmxlib.draw.DrawImageCommand

DrawCommand methods

DrawImageCommand.draw(canvas)[source]

Previous topic

The tmxlib.helpers module

This Page