Skip to content

Commit 141f41e

Browse files
authored
Merge pull request #35 from Satanarious/Satanarious/issue34
Fix Alpha Value Bug
2 parents edc7a92 + c213868 commit 141f41e

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

Widgets/color_picker.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010

1111
class ColorPicker:
1212
vColorPicker = vcolorpicker.ColorPicker(useAlpha=True)
13+
vColorPicker.ui.alpha.textEdited.disconnect() # type:ignore
14+
vColorPicker.ui.alpha.textEdited.connect(lambda: ColorPicker.alphaChanged()) # type:ignore
15+
16+
@staticmethod
17+
def alphaChanged() -> None:
18+
alpha = ColorPicker.vColorPicker.i(ColorPicker.vColorPicker.ui.alpha.text()) # type:ignore
19+
oldalpha = alpha
20+
if alpha < 0:
21+
alpha = 0
22+
if alpha > 255:
23+
alpha = 255
24+
if alpha != oldalpha or alpha == 0:
25+
ColorPicker.vColorPicker.ui.alpha.setText(str(alpha)) # type:ignore
26+
ColorPicker.vColorPicker.ui.alpha.selectAll() # type:ignore
27+
ColorPicker.vColorPicker.alpha = alpha
1328

1429
@staticmethod
1530
def changeButtonColor(color: tuple | str, pushButton: QPushButton) -> None:
@@ -77,19 +92,6 @@ def connectWidgets() -> None:
7792
- Open QColorDialog and choose the color
7893
- Set the color in the QLineEdit provided
7994
"""
80-
81-
def alphaChanged(vColorPicker: vcolorpicker.ColorPicker):
82-
alpha = vColorPicker.i(vColorPicker.ui.alpha.text()) # type:ignore
83-
oldalpha = alpha
84-
if alpha < 0:
85-
alpha = 0
86-
if alpha > 255:
87-
alpha = 255
88-
if alpha != oldalpha or alpha == 0:
89-
vColorPicker.ui.alpha.setText(str(alpha)) # type:ignore
90-
vColorPicker.ui.alpha.selectAll() # type:ignore
91-
vColorPicker.alpha = alpha
92-
9395
global cancelled
9496
cancelled = False # type:ignore
9597

@@ -101,9 +103,6 @@ def ok():
101103
global cancelled
102104
cancelled = False # type:ignore
103105

104-
ColorPicker.vColorPicker.ui.alpha.textEdited.connect(lambda: alphaChanged(ColorPicker.vColorPicker)) # type:ignore
105-
ColorPicker.vColorPicker.ui.alpha.textEdited.disconnect() # type:ignore
106-
107106
ColorPicker.vColorPicker.rejected.connect(cancel) # type:ignore
108107
ColorPicker.vColorPicker.accepted.connect(ok) # type:ignore
109108

0 commit comments

Comments
 (0)