Only emit settings changed signal when it really has been changed.

This commit is contained in:
jupfi 2024-03-13 12:02:52 +01:00
parent 8806e9553c
commit 038bc8c0ef

View file

@ -146,11 +146,10 @@ class IntSetting(Setting):
def value(self, value): def value(self, value):
try: try:
self._value = int(value) self._value = int(value)
self.settings_changed.emit()
except ValueError: except ValueError:
raise ValueError("Value must be an int") raise ValueError("Value must be an int")
self.settings_changed.emit()
class BooleanSetting(Setting): class BooleanSetting(Setting):
"""A setting that is a Boolean.""" """A setting that is a Boolean."""
@ -168,9 +167,10 @@ class BooleanSetting(Setting):
def value(self, value): def value(self, value):
try: try:
self._value = bool(value) self._value = bool(value)
self.settings_changed.emit()
except ValueError: except ValueError:
raise ValueError("Value must be a bool") raise ValueError("Value must be a bool")
self.settings_changed.emit()
def get_widget(self): def get_widget(self):
"""Return a widget for the setting. """Return a widget for the setting.
@ -212,14 +212,14 @@ class SelectionSetting(Setting):
try: try:
if value in self.options: if value in self.options:
self._value = value self._value = value
self.settings_changed.emit()
else: else:
raise ValueError("Value must be one of the options") raise ValueError("Value must be one of the options")
# This fixes a bug when creating the widget when the options are not yet set # This fixes a bug when creating the widget when the options are not yet set
except AttributeError: except AttributeError:
self._value = value self._value = value
self.options = [value] self.options = [value]
self.settings_changed.emit()
self.settings_changed.emit()
def get_widget(self): def get_widget(self):
"""Return a widget for the setting. """Return a widget for the setting.
@ -272,7 +272,8 @@ class StringSetting(Setting):
def value(self, value): def value(self, value):
try: try:
self._value = str(value) self._value = str(value)
self.settings_changed.emit()
except ValueError: except ValueError:
raise ValueError("Value must be a string") raise ValueError("Value must be a string")
self.settings_changed.emit()