mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 03:08:29 +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",
|
"COPY_FUNCTION_FORBIDDEN": "Copying functions is forbidden",
|
||||||
"GET_METHOD_FORBIDDEN": "Using getattr on a method 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_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",
|
"COPY_FUNCTION_FORBIDDEN": "Impossible de copier une fonction",
|
||||||
"GET_METHOD_FORBIDDEN": "Impossible d'utiliser getattr sur une méthode",
|
"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_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
|
self.root = master.root
|
||||||
|
|
||||||
master.add_cascade(label=_("ADVANCED_CONFIGURATION"), menu=self)
|
master.add_cascade(label=_("ADVANCED_CONFIGURATION"), menu=self)
|
||||||
self.add_command(label=_("OPEN_MYSTUFF_SETTINGS"),
|
self.add_command(
|
||||||
command=lambda: mystuff.Window(self.root.mod_config, self.root.options))
|
label=_("OPEN_MYSTUFF_SETTINGS"),
|
||||||
|
command=lambda: mystuff.Window(self.root.mod_config, self.root.options)
|
||||||
|
)
|
||||||
self.threads_used = self.ThreadsUsed(self)
|
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):
|
class ThreadsUsed(tkinter.Menu):
|
||||||
def __init__(self, master: tkinter.Menu):
|
def __init__(self, master: tkinter.Menu):
|
||||||
super().__init__(master, tearoff=False)
|
super().__init__(master, tearoff=False)
|
||||||
|
|
|
@ -3,6 +3,7 @@ from tkinter import ttk
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from source.translation import translate as _, translate_external
|
from source.translation import translate as _, translate_external
|
||||||
|
from source.mkw import ModSettings
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from source.mkw.ModConfig import ModConfig
|
from source.mkw.ModConfig import ModConfig
|
||||||
|
@ -37,6 +38,12 @@ class Window(tkinter.Toplevel):
|
||||||
self.mod_config.specific_settings
|
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.
|
# add at the end a message from the mod creator where he can put some additional note about the settings.
|
||||||
if text := translate_external(
|
if text := translate_external(
|
||||||
self.mod_config,
|
self.mod_config,
|
||||||
|
@ -68,7 +75,6 @@ class FrameSettings(ttk.Frame):
|
||||||
self.columnconfigure(1, weight=1)
|
self.columnconfigure(1, weight=1)
|
||||||
language = self.root.options.language.get()
|
language = self.root.options.language.get()
|
||||||
|
|
||||||
index: int = 0
|
|
||||||
for index, (settings_name, settings_data) in enumerate(settings.items()):
|
for index, (settings_name, settings_data) in enumerate(settings.items()):
|
||||||
text = translate_external(self.root.mod_config, language, settings_data.text)
|
text = translate_external(self.root.mod_config, language, settings_data.text)
|
||||||
description = translate_external(self.root.mod_config, language, settings_data.description)
|
description = translate_external(self.root.mod_config, language, settings_data.description)
|
||||||
|
@ -90,3 +96,25 @@ class FrameSettings(ttk.Frame):
|
||||||
foreground="gray", justify=tkinter.CENTER)
|
foreground="gray", justify=tkinter.CENTER)
|
||||||
description_label.grid(row=2, column=1)
|
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 _
|
from source.translation import translate as _
|
||||||
|
|
||||||
|
|
||||||
class Choices(AbstractModSettings):
|
class Boolean(AbstractModSettings):
|
||||||
"""
|
"""
|
||||||
This setting type allow you to input a string text.
|
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.
|
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"
|
type = "boolean"
|
||||||
|
|
||||||
def tkinter_show(self, master, checkbox) -> None:
|
def tkinter_show(self, master, checkbox=None) -> None:
|
||||||
import tkinter
|
import tkinter
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Choices(AbstractModSettings):
|
||||||
self.choices = choices
|
self.choices = choices
|
||||||
if self.default is None: self.default = self.choices[0]
|
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
|
import tkinter
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class String(AbstractModSettings):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.preview = preview
|
self.preview = preview
|
||||||
|
|
||||||
def tkinter_show(self, master, checkbox) -> None:
|
def tkinter_show(self, master, checkbox=None) -> None:
|
||||||
import tkinter
|
import tkinter
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
|
|
|
@ -45,12 +45,15 @@ class AbstractModSettings(ABC):
|
||||||
return self.value == self.default
|
return self.value == self.default
|
||||||
|
|
||||||
@abstractmethod
|
@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
|
Show the option inside a tkinter widget
|
||||||
:master: master widget
|
:master: master widget
|
||||||
:checkbox: checkbox inside the labelframe allowing to enable or disable the setting
|
: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.set(self.enabled)
|
||||||
enabled_variable.trace_add("write", lambda *_: setattr(self, "enabled", enabled_variable.get()))
|
enabled_variable.trace_add("write", lambda *_: setattr(self, "enabled", enabled_variable.get()))
|
||||||
...
|
...
|
||||||
|
@ -66,13 +69,15 @@ class AbstractModSettings(ABC):
|
||||||
return variable
|
return variable
|
||||||
|
|
||||||
@staticmethod
|
@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
|
Bind all widget of the master so that clicking on the frame enable automatically the option
|
||||||
:param master: the frame containing the elements
|
:param master: the frame containing the elements
|
||||||
:param enabled_variable: the variable associated with the enable state
|
:param enabled_variable: the variable associated with the enable state
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
if enabled_variable is None: return
|
||||||
|
|
||||||
for child in master.winfo_children():
|
for child in master.winfo_children():
|
||||||
child.bind("<Button-1>", lambda e: enabled_variable.set(True))
|
child.bind("<Button-1>", lambda e: enabled_variable.set(True))
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ class Options:
|
||||||
"mystuff_pack_selected": Option(self, value=None),
|
"mystuff_pack_selected": Option(self, value=None),
|
||||||
"mystuff_packs": Option(self, value={}),
|
"mystuff_packs": Option(self, value={}),
|
||||||
"extension": Option(self, value="WBFS"),
|
"extension": Option(self, value="WBFS"),
|
||||||
|
"developer_mode": Option(self, value=False),
|
||||||
}
|
}
|
||||||
|
|
||||||
for option_name, option_value in options.items():
|
for option_name, option_value in options.items():
|
||||||
|
|
Loading…
Reference in a new issue