コード例 #1
0
ファイル: tile.py プロジェクト: davidar/pyzui
class Tile(object):
    """Tile objects allow storage and manipulation of image tiles.

    Constructor: Tile(Image or QImage)
    """
    def __init__(self, image):
        """Create a new tile with the given image."""
        if image.__class__ is ImageQt or type(image) is QtGui.QImage:
            self.__image = image
        else:
            self.__image = ImageQt(image)


    def crop(self, bbox):
        """Return the region of the tile contained in the bounding box `bbox`
        (x1,y1,x2,y2).

        crop(tuple<int,int,int,int>) -> Tile
        """
        x, y, x2, y2 = bbox
        w = x2 - x
        h = y2 - y
        return Tile(self.__image.copy(x, y, w, h))


    def resize(self, width, height):
        """Return a resized copy of the tile.

        resize(int, int) -> Tile
        """
        return Tile(self.__image.scaled(width, height,
            QtCore.Qt.IgnoreAspectRatio,
            QtCore.Qt.SmoothTransformation))


    def save(self, filename):
        """Save the tile to the location given by `filename`.

        save(string) -> None
        """
        self.__image.save(filename)


    def draw(self, painter, x, y):
        """Draw the tile on the given `painter` at the given position.

        paint(QPainter, int, int) -> None
        """
        painter.drawImage(x, y, self.__image)


    @property
    def size(self):
        """The dimensions of the tile."""
        return (self.__image.width(), self.__image.height())
コード例 #2
0
ファイル: tile.py プロジェクト: davidar/pyzui
 def __init__(self, image):
     """Create a new tile with the given image."""
     if image.__class__ is ImageQt or type(image) is QtGui.QImage:
         self.__image = image
     else:
         self.__image = ImageQt(image)