Fix the alpha sliders not taking the correct value on startup and not syncing bidirectionally.
This commit is contained in:
@@ -11,7 +11,7 @@ if '_' not in builtins.__dict__:
|
||||
|
||||
from flatcamGUI.preferences.OptionUI import OptionUI, CheckboxOptionUI, RadioSetOptionUI, \
|
||||
SeparatorOptionUI, HeadingOptionUI, ComboboxOptionUI, ColorOptionUI, FullWidthButtonOptionUI, \
|
||||
SliderWithSpinnerOptionUI
|
||||
SliderWithSpinnerOptionUI, ColorAlphaSliderOptionUI
|
||||
|
||||
|
||||
class GeneralGUIPrefGroupUI(OptionsGroupUI2):
|
||||
@@ -41,16 +41,6 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2):
|
||||
self.hdpi_field.set_value(False)
|
||||
self.hdpi_field.stateChanged.connect(self.handle_hdpi)
|
||||
|
||||
self.sel_line_field = self.option_dict()["global_sel_line"].get_field()
|
||||
self.sel_fill_field = self.option_dict()["global_sel_fill"].get_field()
|
||||
self.sel_alpha_field = self.option_dict()["_global_sel_alpha"].get_field()
|
||||
self.sel_alpha_field.spinner.valueChanged.connect(self.on_sel_alpha_change)
|
||||
|
||||
self.alt_sel_line_field = self.option_dict()["global_alt_sel_line"].get_field()
|
||||
self.alt_sel_fill_field = self.option_dict()["global_alt_sel_fill"].get_field()
|
||||
self.alt_sel_alpha_field = self.option_dict()["_global_alt_sel_alpha"].get_field()
|
||||
self.alt_sel_alpha_field.spinner.valueChanged.connect(self.on_alt_sel_alpha_change)
|
||||
|
||||
def build_options(self) -> [OptionUI]:
|
||||
return [
|
||||
RadioSetOptionUI(
|
||||
@@ -127,11 +117,11 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2):
|
||||
"First 6 digits are the color and the last 2\n"
|
||||
"digits are for alpha (transparency) level."
|
||||
),
|
||||
SliderWithSpinnerOptionUI(
|
||||
option="_global_sel_alpha",
|
||||
ColorAlphaSliderOptionUI(
|
||||
applies_to=["global_sel_line", "global_sel_fill"],
|
||||
group=self,
|
||||
label_text="Alpha",
|
||||
label_tooltip="Set the fill transparency for the 'left to right' selection box.",
|
||||
min_value=0, max_value=255, step=1
|
||||
label_tooltip="Set the fill transparency for the 'left to right' selection box."
|
||||
),
|
||||
SeparatorOptionUI(),
|
||||
|
||||
@@ -149,11 +139,11 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2):
|
||||
"First 6 digits are the color and the last 2\n"
|
||||
"digits are for alpha (transparency) level."
|
||||
),
|
||||
SliderWithSpinnerOptionUI(
|
||||
option="_global_alt_sel_alpha",
|
||||
ColorAlphaSliderOptionUI(
|
||||
applies_to=["global_alt_sel_line", "global_alt_sel_fill"],
|
||||
group=self,
|
||||
label_text="Alpha",
|
||||
label_tooltip="Set the fill transparency for the 'right to left' selection box.",
|
||||
min_value=0, max_value=255, step=1
|
||||
label_tooltip="Set the fill transparency for the 'right to left' selection box."
|
||||
),
|
||||
SeparatorOptionUI(),
|
||||
|
||||
@@ -191,32 +181,6 @@ class GeneralGUIPrefGroupUI(OptionsGroupUI2):
|
||||
),
|
||||
]
|
||||
|
||||
def on_sel_alpha_change(self):
|
||||
alpha = self.sel_alpha_field.get_value()
|
||||
fill = self._modify_color_alpha(color=self.sel_fill_field.get_value(), alpha=alpha)
|
||||
self.sel_fill_field.set_value(fill)
|
||||
line = self._modify_color_alpha(color=self.sel_line_field.get_value(), alpha=alpha)
|
||||
self.sel_line_field.set_value(line)
|
||||
|
||||
def on_alt_sel_alpha_change(self):
|
||||
alpha = self.alt_sel_alpha_field.get_value()
|
||||
fill = self._modify_color_alpha(color=self.alt_sel_fill_field.get_value(), alpha=alpha)
|
||||
self.alt_sel_fill_field.set_value(fill)
|
||||
line = self._modify_color_alpha(color=self.alt_sel_line_field.get_value(), alpha=alpha)
|
||||
self.alt_sel_line_field.set_value(line)
|
||||
|
||||
def _modify_color_alpha(self, color: str, alpha: int):
|
||||
color_without_alpha = color[:7]
|
||||
if alpha > 255:
|
||||
return color_without_alpha + "FF"
|
||||
elif alpha < 0:
|
||||
return color_without_alpha + "00"
|
||||
else:
|
||||
hexalpha = hex(alpha)[2:]
|
||||
if len(hexalpha) == 1:
|
||||
hexalpha = "0" + hexalpha
|
||||
return color_without_alpha + hexalpha
|
||||
|
||||
def on_theme_change(self):
|
||||
# FIXME: this should be moved out to a view model
|
||||
val = self.theme_field.get_value()
|
||||
|
||||
Reference in New Issue
Block a user