mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 03:08:29 +02:00
there is now a default options in the settings, allowing for default value if the option is disabled (instead of always None)
This commit is contained in:
parent
d3ff94b940
commit
e46acba9a6
3 changed files with 16 additions and 10 deletions
|
@ -12,10 +12,13 @@ class Choices(AbstractModSettings):
|
|||
|
||||
type = "choices"
|
||||
|
||||
def __init__(self, choices: list[str], value: str = None, enabled: bool = False, text: dict[str] = None):
|
||||
self._value = value if value is not None else choices[0]
|
||||
self.text = text if text is not None else {}
|
||||
def __init__(self, choices: list[str], enabled: bool = False,
|
||||
default: str | None = None, text: dict[str] = None):
|
||||
self._value = default if default is not None else choices[0]
|
||||
self.default = default
|
||||
self.enabled = enabled
|
||||
|
||||
self.text = text if text is not None else {}
|
||||
self.choices = choices
|
||||
|
||||
def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None:
|
||||
|
|
|
@ -13,10 +13,13 @@ class String(AbstractModSettings):
|
|||
|
||||
type = "string"
|
||||
|
||||
def __init__(self, value: str = None, preview: str = None, enabled: bool = False, text: dict[str] = None):
|
||||
self._value: str = value if value is not None else ""
|
||||
self.text = text if text is not None else {}
|
||||
def __init__(self, preview: str = None, enabled: bool = False,
|
||||
default: str | None = None, text: dict[str] = None):
|
||||
self._value: str = default if default is not None else ""
|
||||
self.default = default
|
||||
self.enabled = enabled
|
||||
|
||||
self.text = text if text is not None else {}
|
||||
self.preview: str | None = preview
|
||||
|
||||
def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None:
|
||||
|
|
|
@ -16,15 +16,16 @@ class AbstractModSettings(ABC):
|
|||
type: str # type name of the settings
|
||||
text: dict[str] # text to display in the settings window depending on the language
|
||||
enabled: bool # is the settings enabled
|
||||
default: str | None # default value of the settings (used is disabled)
|
||||
_value: str # value for the settings
|
||||
|
||||
@property
|
||||
def value(self) -> "any | None":
|
||||
"""
|
||||
If the option is enabled, return the value, else return None
|
||||
:return:
|
||||
If the option is enabled, return the value, else return the default value
|
||||
:return: value if the setting is enabled, default otherwise
|
||||
"""
|
||||
return self._value if self.enabled else None
|
||||
return self._value if self.enabled else self.default
|
||||
|
||||
@abstractmethod
|
||||
def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None:
|
||||
|
@ -38,7 +39,6 @@ class AbstractModSettings(ABC):
|
|||
|
||||
enabled_variable = tkinter.BooleanVar(master, value=self.enabled)
|
||||
enabled_variable.trace_add("write", lambda *_: setattr(self, "enabled", enabled_variable.get()))
|
||||
checkbox.configure(variable=enabled_variable)
|
||||
...
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Reference in a new issue