-
Notifications
You must be signed in to change notification settings - Fork 3
/
brush.py
45 lines (32 loc) · 1.22 KB
/
brush.py
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
43
44
45
from __future__ import annotations
from prettyqt import constants, core, gui
from prettyqt.qt import QtGui
from prettyqt.utils import InvalidParamError
class Brush(QtGui.QBrush):
def __repr__(self):
return f"{type(self).__name__}({self.get_color()!r}, {self.get_style()!r})"
def __getstate__(self):
return bytes(self)
def __setstate__(self, ba):
core.DataStream.write_bytearray(ba, self)
def __reduce__(self):
return type(self), (), self.__getstate__()
def __bytes__(self):
ba = core.DataStream.create_bytearray(self)
return bytes(ba)
def get_texture_image(self) -> gui.Image | None:
img = self.textureImage()
if img.isNull():
return None
return gui.Image(img)
def get_color(self) -> gui.Color:
return gui.Color(self.color())
def get_style(self) -> constants.BrushStyleStr:
return constants.BRUSH_STYLE.inverse[self.style()]
def set_style(self, style: constants.BrushStyleStr):
if style not in constants.BRUSH_STYLE:
raise InvalidParamError(style, constants.BRUSH_STYLE)
self.setStyle(constants.BRUSH_STYLE[style])
if __name__ == "__main__":
b = Brush()
print(repr(b))