menu design + translation system

This commit is contained in:
Faraphel 2022-06-08 00:23:08 +02:00
parent 599b520780
commit 404111948d
10 changed files with 150 additions and 8 deletions

View file

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

6
assets/language/en.json Normal file
View file

@ -0,0 +1,6 @@
{
"name": "English",
"translation": {
"INSTALLER_TITLE": "MKWF-Install"
}
}

6
assets/language/fr.json Normal file
View file

@ -0,0 +1,6 @@
{
"name": "Français",
"translation": {
}
}

View file

@ -0,0 +1,3 @@
from source.gui import install
install.Window().mainloop()

View file

@ -1,2 +1 @@
pillow
cx_Freeze
pillow

View file

@ -3,11 +3,8 @@ import sys
import json
include_files = [
"./icon.ico",
"./LICENSE",
"./README.md",
"./version",
"./translation.json",
"./assets",
"./tools",
@ -19,9 +16,9 @@ include_files = [
options = {
"build_exe": {
"include_files": include_files,
"includes": ["tkinter", "requests", "PIL", "distutils"],
"includes": ["tkinter", "PIL"],
"include_msvcr": True,
"packages": ["tkinter", "distutils"],
"packages": ["tkinter"],
}
}
@ -37,7 +34,7 @@ setup(
executables=[
Executable(
"./main.pyw",
icon="./icon.ico",
icon="./assets/icon.ico",
base="win32gui",
target_name="MKWF-Install.exe",
shortcut_name="MKWF-Install",

0
source/__init__.py Normal file
View file

0
source/gui/__init__.py Normal file
View file

122
source/gui/install.py Normal file
View file

@ -0,0 +1,122 @@
import tkinter
from pathlib import Path
import json
from tkinter import ttk
from source.translation import translate as _
class Window(tkinter.Tk):
def __init__(self):
super().__init__()
self.title(_("INSTALLER_TITLE"))
self.resizable(False, False)
self.iconbitmap("./assets/icon.ico")
self.menu = Menu(self)
self.config(menu=self.menu)
self.select_pack = SelectPack(self)
self.select_pack.grid(row=1, column=1, sticky="w")
self.source_game = SourceGame(self)
self.source_game.grid(row=2, column=1, sticky="nsew")
self.destination_game = DestinationGame(self)
self.destination_game.grid(row=3, column=1, sticky="nsew")
self.button_install = ButtonInstall(self)
self.button_install.grid(row=4, column=1, sticky="nsew")
self.progress_bar = ProgressBar(self)
self.progress_bar.grid(row=5, column=1, sticky="nsew")
class Menu(tkinter.Menu):
def __init__(self, master):
super().__init__(master)
self.language = self.Language(self)
self.track_configuration = self.TrackConfiguration(self)
self.advanced = self.Advanced(self)
self.help = self.Help(self)
class Language(tkinter.Menu):
def __init__(self, master: tkinter.Menu):
super().__init__(master, tearoff=False)
master.add_cascade(label="Language", menu=self)
for file in Path("./assets/language/").iterdir():
self.add_command(label=json.loads(file.read_text(encoding="utf8"))["name"])
class TrackConfiguration(tkinter.Menu):
def __init__(self, master: tkinter.Menu):
super().__init__(master, tearoff=False)
master.add_cascade(label="Track Configuration", menu=self)
self.add_command(label="Change configuration")
class Advanced(tkinter.Menu):
def __init__(self, master: tkinter.Menu):
super().__init__(master, tearoff=False)
master.add_cascade(label="Advanced", menu=self)
self.add_command(label="Debug mode")
class Help(tkinter.Menu):
def __init__(self, master: tkinter.Menu):
super().__init__(master, tearoff=False)
master.add_cascade(label="Help", menu=self)
self.add_command(label="Discord")
self.add_command(label="Github Wiki")
class SourceGame(ttk.LabelFrame):
def __init__(self, master: tkinter.Tk):
super().__init__(master, text="Original Game")
self.entry = ttk.Entry(self, width=50)
self.entry.grid(row=1, column=1, sticky="nsew")
ttk.Button(self, text="...", width=2).grid(row=1, column=2, sticky="nsew")
class DestinationGame(ttk.LabelFrame):
def __init__(self, master: tkinter.Tk):
super().__init__(master, text="Game Destination")
self.entry = ttk.Entry(self, width=50)
self.entry.grid(row=1, column=1, sticky="nsew")
ttk.Button(self, text="...", width=2).grid(row=1, column=2, sticky="nsew")
class ButtonInstall(ttk.Button):
def __init__(self, master: tkinter.Tk):
super().__init__(master, text="Install", command=self.install)
def install(self):
...
class ProgressBar(ttk.Frame):
def __init__(self, master: tkinter.Tk):
super().__init__()
self.progress_bar = ttk.Progressbar(self)
self.progress_bar.grid(row=1, column=1, sticky="nsew")
self.description = tkinter.Label(self, text="test")
self.description.grid(row=2, column=1, sticky="nsew")
class SelectPack(ttk.Combobox):
def __init__(self, master: tkinter.Tk):
super().__init__()
for pack in Path("./Pack/").iterdir():
self.insert(tkinter.END, pack.name)

9
source/translation.py Normal file
View file

@ -0,0 +1,9 @@
import json
from pathlib import Path
language_data = json.loads(Path("./assets/language/en.json").read_text(encoding="utf8"))
def translate(*text):
return "".join([language_data["translation"].get(word, word) for word in text])