Skip to content

Commit

Permalink
feat(Brush): add set_style method
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Apr 11, 2023
1 parent 9374440 commit 52d8136
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions prettyqt/gui/brush.py
Expand Up @@ -2,6 +2,7 @@

from prettyqt import constants, core, gui
from prettyqt.qt import QtGui
from prettyqt.utils import InvalidParamError


class Brush(QtGui.QBrush):
Expand Down Expand Up @@ -33,6 +34,11 @@ def get_color(self) -> gui.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()
Expand Down
4 changes: 4 additions & 0 deletions tests/test_gui.py
Expand Up @@ -35,6 +35,10 @@ def test_repr(name, cls, qapp):
def test_brush():
brush = gui.Brush()
bytes(brush)
brush.set_style("cross")
with pytest.raises(InvalidParamError):
brush.set_style("test")
assert brush.get_style() == "cross"


@pytest.mark.skipif(sys.platform == "darwin", reason="Somehow fails on OSX")
Expand Down

0 comments on commit 52d8136

Please sign in to comment.