added a "Check" type for mod_settings (used for balancing option in MKWF)

This commit is contained in:
Faraphel 2022-08-17 20:37:36 +02:00
parent 23149d30da
commit 1b579bec4c
6 changed files with 40 additions and 9 deletions

View file

@ -47,12 +47,8 @@
"en": "Balancing *",
"fr": "Équilibrage *"
},
"type": "choices",
"choices": [
"Enabled",
"Disabled"
],
"default": "Enabled"
"type": "check",
"default": true
}
},
"lpar_template": "{{ mode if (mode := ## SETTINGS_MODE ##) is not None else 'normal' }}.lpar",

View file

@ -1,3 +1,3 @@
{
"if": "## SETTINGS_BALANCING ## == 'Enabled'"
"if": "## SETTINGS_BALANCING ## is True"
}

View file

@ -33,6 +33,7 @@
"SPECIFIC_MOD_SETTINGS": "Specific mod settings",
"CONFIGURE_MYSTUFF_PATCH": "Configure the MyStuff patchs",
"DISABLED": "Disabled",
"ENABLED": "Enabled",
"NEW_PROFILE": "New Profile",
"DELETE_PROFILE": "Delete Profile",
"ADD_MYSTUFF": "Add MyStuff patch",

View file

@ -34,6 +34,7 @@
"SPECIFIC_MOD_SETTINGS": "Paramètre spécifique de mod",
"CONFIGURE_MYSTUFF_PATCH": "Configurer les patchs MyStuff",
"DISABLED": "Désactiver",
"ENABLED": "Activer",
"NEW_PROFILE": "Nouveau profil",
"DELETE_PROFILE": "Retirer un Profil",
"ADD_MYSTUFF": "Ajouter un patch MyStuff",

View file

@ -0,0 +1,33 @@
import tkinter
from tkinter import ttk
from source.mkw.ModSettings import AbstractModSettings
from source.translation import translate as _
class Choices(AbstractModSettings):
"""
This setting type allow you to input a string text.
You can optionally add a "preview" to allow the user to use a window to select the value.
"""
type = "check"
def __init__(self, enabled: bool = False,
default: bool | None = None, text: dict[str] = None):
self._value = default if default is not None else False
self.default = default
self.enabled = enabled
self.text = text if text is not None else {}
def tkinter_show(self, master: ttk.LabelFrame, checkbox) -> None:
super().tkinter_show(master, checkbox)
value_variable = tkinter.BooleanVar(master, value=self._value)
value_variable.trace_add("write", lambda *_: setattr(self, "_value", value_variable.get()))
radiobutton_on = ttk.Radiobutton(master, text=_("DISABLED"), variable=value_variable, value=False)
radiobutton_on.grid(row=1, column=1, sticky="NEWS")
radiobutton_off = ttk.Radiobutton(master, text=_("ENABLED"), variable=value_variable, value=True)
radiobutton_off.grid(row=1, column=2, sticky="NEWS")

View file

@ -19,7 +19,7 @@ class AbstractModSettings(ABC):
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
_value: any # value for the settings
@property
def value(self) -> "any | None":
@ -69,4 +69,4 @@ class AbstractModSettings(ABC):
# these import load the different ModSettings, and so get_mod_settings will be able to fetch them with __subclasses__
from source.mkw.ModSettings import Choices, String
from source.mkw.ModSettings import Choices, String, Check