mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-02 02:38:30 +02:00
added a developer mode enabling a testing frame in the ModSettings
This commit is contained in:
parent
777acb7cbf
commit
2edb82939c
9 changed files with 60 additions and 12 deletions
|
@ -103,6 +103,8 @@
|
|||
"COPY_FUNCTION_FORBIDDEN": "Copying functions is forbidden",
|
||||
"GET_METHOD_FORBIDDEN": "Using getattr on a method is forbidden",
|
||||
"CAN_ONLY_CALL_METHOD_OF_CONSTANT": "You can only call methods on constant",
|
||||
"CAN_ONLY_CALL_FUNCTION_IN_ENV": "You can only call function from the environment"
|
||||
"CAN_ONLY_CALL_FUNCTION_IN_ENV": "You can only call function from the environment",
|
||||
"ENABLE_DEVELOPER_MODE": "Enable the developer mode",
|
||||
"TESTING_MOD_SETTINGS": "Test mod settings"
|
||||
}
|
||||
}
|
|
@ -104,6 +104,8 @@
|
|||
"COPY_FUNCTION_FORBIDDEN": "Impossible de copier une fonction",
|
||||
"GET_METHOD_FORBIDDEN": "Impossible d'utiliser getattr sur une méthode",
|
||||
"CAN_ONLY_CALL_METHOD_OF_CONSTANT": "Vous ne pouvez appeler que des méthodes sur des constantes",
|
||||
"CAN_ONLY_CALL_FUNCTION_IN_ENV": "Vous ne pouvez appeler que des fonctions dans l'environnement"
|
||||
"CAN_ONLY_CALL_FUNCTION_IN_ENV": "Vous ne pouvez appeler que des fonctions dans l'environnement",
|
||||
"ENABLE_DEVELOPER_MODE": "Activer le mode développeur",
|
||||
"TESTING_MOD_SETTINGS": "Paramètre de test"
|
||||
}
|
||||
}
|
|
@ -173,11 +173,21 @@ class Menu(tkinter.Menu):
|
|||
self.root = master.root
|
||||
|
||||
master.add_cascade(label=_("ADVANCED_CONFIGURATION"), menu=self)
|
||||
self.add_command(label=_("OPEN_MYSTUFF_SETTINGS"),
|
||||
command=lambda: mystuff.Window(self.root.mod_config, self.root.options))
|
||||
|
||||
self.add_command(
|
||||
label=_("OPEN_MYSTUFF_SETTINGS"),
|
||||
command=lambda: mystuff.Window(self.root.mod_config, self.root.options)
|
||||
)
|
||||
self.threads_used = self.ThreadsUsed(self)
|
||||
|
||||
self.add_separator()
|
||||
|
||||
self.variable_developer_mode = tkinter.BooleanVar(value=self.root.options.developer_mode.get())
|
||||
self.add_checkbutton(
|
||||
label=_("ENABLE_DEVELOPER_MODE"),
|
||||
variable=self.variable_developer_mode,
|
||||
command=lambda: self.root.options.developer_mode.set(self.variable_developer_mode.get())
|
||||
)
|
||||
|
||||
class ThreadsUsed(tkinter.Menu):
|
||||
def __init__(self, master: tkinter.Menu):
|
||||
super().__init__(master, tearoff=False)
|
||||
|
|
|
@ -3,6 +3,7 @@ from tkinter import ttk
|
|||
from typing import TYPE_CHECKING
|
||||
|
||||
from source.translation import translate as _, translate_external
|
||||
from source.mkw import ModSettings
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from source.mkw.ModConfig import ModConfig
|
||||
|
@ -37,6 +38,12 @@ class Window(tkinter.Toplevel):
|
|||
self.mod_config.specific_settings
|
||||
)
|
||||
|
||||
if self.options.developer_mode.get():
|
||||
self.frame_testing_settings = FrameTesting(
|
||||
self.panel_window,
|
||||
_("TESTING_MOD_SETTINGS")
|
||||
)
|
||||
|
||||
# add at the end a message from the mod creator where he can put some additional note about the settings.
|
||||
if text := translate_external(
|
||||
self.mod_config,
|
||||
|
@ -68,7 +75,6 @@ class FrameSettings(ttk.Frame):
|
|||
self.columnconfigure(1, weight=1)
|
||||
language = self.root.options.language.get()
|
||||
|
||||
index: int = 0
|
||||
for index, (settings_name, settings_data) in enumerate(settings.items()):
|
||||
text = translate_external(self.root.mod_config, language, settings_data.text)
|
||||
description = translate_external(self.root.mod_config, language, settings_data.description)
|
||||
|
@ -90,3 +96,25 @@ class FrameSettings(ttk.Frame):
|
|||
foreground="gray", justify=tkinter.CENTER)
|
||||
description_label.grid(row=2, column=1)
|
||||
|
||||
|
||||
class FrameTesting(ttk.Frame):
|
||||
def __init__(self, master, text: str):
|
||||
super().__init__(master)
|
||||
master.add(self, text=text)
|
||||
self.root = self.master.root
|
||||
|
||||
self.columnconfigure(1, weight=1)
|
||||
|
||||
for index, (settings_name, settings_data) in enumerate({
|
||||
"TEST_PREVIEW_FORMATTING": ModSettings.String.String(preview="track_formatting"),
|
||||
"TEST_PREVIEW_SELECTING": ModSettings.String.String(preview="track_selecting"),
|
||||
"TEST_PREVIEW_SORTING": ModSettings.String.String(preview="track_sorting"),
|
||||
|
||||
"TEST_STRING": ModSettings.String.String(),
|
||||
"TEST_CHOICES": ModSettings.Choices.Choices(["test1", "test2", "test3"]),
|
||||
"TEST_BOOLEAN": ModSettings.Boolean.Boolean(),
|
||||
}.items()):
|
||||
frame = ttk.LabelFrame(self, text=settings_name)
|
||||
frame.root = self.root
|
||||
frame.grid(row=index, column=1, sticky="NEWS")
|
||||
settings_data.tkinter_show(frame)
|
||||
|
|
|
@ -2,7 +2,7 @@ from source.mkw.ModSettings import AbstractModSettings
|
|||
from source.translation import translate as _
|
||||
|
||||
|
||||
class Choices(AbstractModSettings):
|
||||
class Boolean(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.
|
||||
|
@ -10,7 +10,7 @@ class Choices(AbstractModSettings):
|
|||
|
||||
type = "boolean"
|
||||
|
||||
def tkinter_show(self, master, checkbox) -> None:
|
||||
def tkinter_show(self, master, checkbox=None) -> None:
|
||||
import tkinter
|
||||
from tkinter import ttk
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class Choices(AbstractModSettings):
|
|||
self.choices = choices
|
||||
if self.default is None: self.default = self.choices[0]
|
||||
|
||||
def tkinter_show(self, master, checkbox) -> None:
|
||||
def tkinter_show(self, master, checkbox=None) -> None:
|
||||
import tkinter
|
||||
from tkinter import ttk
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class String(AbstractModSettings):
|
|||
super().__init__(**kwargs)
|
||||
self.preview = preview
|
||||
|
||||
def tkinter_show(self, master, checkbox) -> None:
|
||||
def tkinter_show(self, master, checkbox=None) -> None:
|
||||
import tkinter
|
||||
from tkinter import ttk
|
||||
|
||||
|
|
|
@ -45,12 +45,15 @@ class AbstractModSettings(ABC):
|
|||
return self.value == self.default
|
||||
|
||||
@abstractmethod
|
||||
def tkinter_show(self, master, enabled_variable: "tkinter.BooleanVar") -> None:
|
||||
def tkinter_show(self, master, enabled_variable: "tkinter.BooleanVar" = None) -> None:
|
||||
"""
|
||||
Show the option inside a tkinter widget
|
||||
:master: master widget
|
||||
:checkbox: checkbox inside the labelframe allowing to enable or disable the setting
|
||||
"""
|
||||
import tkinter
|
||||
if enabled_variable is None: enabled_variable = tkinter.BooleanVar()
|
||||
|
||||
enabled_variable.set(self.enabled)
|
||||
enabled_variable.trace_add("write", lambda *_: setattr(self, "enabled", enabled_variable.get()))
|
||||
...
|
||||
|
@ -66,13 +69,15 @@ class AbstractModSettings(ABC):
|
|||
return variable
|
||||
|
||||
@staticmethod
|
||||
def tkinter_bind(master, enabled_variable: "tkinter.BooleanVar") -> None:
|
||||
def tkinter_bind(master, enabled_variable: "tkinter.BooleanVar" = None) -> None:
|
||||
"""
|
||||
Bind all widget of the master so that clicking on the frame enable automatically the option
|
||||
:param master: the frame containing the elements
|
||||
:param enabled_variable: the variable associated with the enable state
|
||||
:return:
|
||||
"""
|
||||
if enabled_variable is None: return
|
||||
|
||||
for child in master.winfo_children():
|
||||
child.bind("<Button-1>", lambda e: enabled_variable.set(True))
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ class Options:
|
|||
"mystuff_pack_selected": Option(self, value=None),
|
||||
"mystuff_packs": Option(self, value={}),
|
||||
"extension": Option(self, value="WBFS"),
|
||||
"developer_mode": Option(self, value=False),
|
||||
}
|
||||
|
||||
for option_name, option_value in options.items():
|
||||
|
|
Loading…
Reference in a new issue