aboutsummaryrefslogtreecommitdiff
path: root/src/frame.py
blob: 6d6d29919f8cd6faa7bdce87a54b32c5898bdb8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'''
    Common tools for drawing compatible frames in a Component's frameRender()
'''
from PyQt5 import QtGui
from PIL import Image
from PIL.ImageQt import ImageQt
import sys


class FramePainter(QtGui.QPainter):
    def __init__(self, width, height):
        image = BlankFrame(width, height)
        self.image = ImageQt(image)
        super().__init__(self.image)

    def setPen(self, RgbTuple):
        if sys.byteorder == 'big':
            color = QtGui.QColor(*RgbTuple)
        else:
            color = QtGui.QColor(*RgbTuple[::-1])
        super().setPen(QtGui.QColor(color))

    def finalize(self):
        self.end()
        imBytes = self.image.bits().asstring(self.image.byteCount())

        return Image.frombytes(
            'RGBA', (self.image.width(), self.image.height()), imBytes
        )

class PaintColor(QtGui.QColor):
    def __init__(self, r, g, b, a=255):
        if sys.byteorder == 'big':
            super().__init__(r, g, b, a)
        else:
            super().__init__(b, g, r, a)

def FloodFrame(width, height, RgbaTuple):
    return Image.new("RGBA", (width, height), RgbaTuple)

def BlankFrame(width, height):
    return FloodFrame(width, height, (0, 0, 0, 0))