diff options
| author | tassaron | 2017-07-02 21:38:19 -0400 |
|---|---|---|
| committer | tassaron | 2017-07-02 21:38:19 -0400 |
| commit | 3a6d7ae421ad2b650cac7f17d43be313787f0e61 (patch) | |
| tree | 1788ad881bb621d6d3bc2962d3d8b65e9f952522 /src/frame.py | |
| parent | 0da275bf1b1dd2c956fed9d4a1051dcf3365c382 (diff) | |
frame-drawing tools for components to share
Diffstat (limited to 'src/frame.py')
| -rw-r--r-- | src/frame.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/frame.py b/src/frame.py new file mode 100644 index 0000000..6d6d299 --- /dev/null +++ b/src/frame.py @@ -0,0 +1,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)) |
