zooui.tilesystem.tile module

Class for representing image tiles.

class zooui.tilesystem.tile.Tile(image)[source]

Bases: object

Constructor:

Tile(image)

Parameters :

image : QImage

Tile(image) –> None

A simple wrapper around image data (PIL/QImage) with operations:
  • crop(), resize(), save(), draw()

  • merged() - Combines 4 tiles into one (2×2 grid layout)

Constructor:

Tile(image)

Parameters :

image : Any

Tile(image) –> None

Create a new tile with the given image. checks if image type is ImageQt of QtGui.QImage if not calls ImageQt.ImageQt to try convert given image to ImageQt type.

crop(bbox)[source]
Method :

Tile.crop(bbox)

Parameters :

bbox : Tuple[int, int, int, int]

Tile.crop(bbox) –> Tile

Return the region of the tile contained in the bounding box bbox (x1,y1,x2,y2).

resize(width, height)[source]
Method :

Tile.resize(width, height)

Parameters :

width : int height : int

Tile.resize(width, height) –> Tile

Return a resized copy of the tile by calling ImageQt.scaled() method.

save(filename)[source]
Method :

Tile.save(filename)

Parameters :

filename : str

Tile.save(filename) –> None

Save the tile to the location given by filename.

Converts the QImage to a PIL Image and saves via Pillow, avoiding QImage.save() which can segfault when a QApplication is live (known PySide6 issue when tiling runs after a QApplication is created, e.g. in test suites).

draw(painter, x, y)[source]
Method :

Tile.draw(painter, x, y)

Parameters :

painter : QPainter x : int y : int

Tile.draw(painter, x, y) –> None

Draw the tile on the given painter: ‘QtGui.QPainter’ at the given position.

property size
Property:

Tile.size

Parameters :

None

Tile.size –> Tuple[int, int]

Returns the dimensions of the tile calling ImageQt.width and ImageQt.height methods.

zooui.tilesystem.tile.new(width, height)[source]
Function :

new(width, height)

Parameters :

width : int height : int

new(width, height) –> Tile

Create a new tile with the given dimensions calling QtGui.QImage() istance.

zooui.tilesystem.tile.fromstring(string, width, height)[source]
Function :

fromstring(string, width, height)

Parameters :

string : str width : int height : int

fromstring(string, width, height) –> Tile

Create a new tile from a string of raw pixels, with the given dimensions, calling Image.frombytes() class instance.

zooui.tilesystem.tile.merged(t1, t2, t3, t4)[source]
Function :

merged(t1, t2, t3, t4)

Parameters :

t1 : Tile t2 : Optional[Tile] t3 : Optional[Tile] t4 : Optional[Tile]

merged(t1, t2, t3, t4) –> Tile

Merge the given tiles into a single tile by freating new size ImageQt with QtGui.QImage class instance and then drawing merged tiles with QtGui.QPainter() class instance.

t1 must be a Tile, but any or all of t2,`t3`,`t4` may be None, in which case they will be ignored.