mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-05 12:18:21 +02:00
added a button to extract modpack with the .mkwf.pack extension
This commit is contained in:
parent
5dfaa35595
commit
2e5c7ec773
4 changed files with 110 additions and 12 deletions
|
@ -3,6 +3,7 @@ from source.Option import Option
|
||||||
from source.Game import Game
|
from source.Game import Game
|
||||||
from source.Gui.Main import Main
|
from source.Gui.Main import Main
|
||||||
from source.Gui.TrackConfiguration import TrackConfiguration
|
from source.Gui.TrackConfiguration import TrackConfiguration
|
||||||
|
from source.Gui.SelectPack import SelectPack
|
||||||
from source.Translation import Translator
|
from source.Translation import Translator
|
||||||
from source.Error import ErrorLogger
|
from source.Error import ErrorLogger
|
||||||
|
|
||||||
|
@ -27,4 +28,5 @@ class Common:
|
||||||
self.gui_main = Main(common=self)
|
self.gui_main = Main(common=self)
|
||||||
|
|
||||||
def show_gui_track_configuration(self): TrackConfiguration(common=self)
|
def show_gui_track_configuration(self): TrackConfiguration(common=self)
|
||||||
|
def show_gui_add_pack(self): SelectPack(common=self)
|
||||||
def mainloop(self): self.gui_main.mainloop()
|
def mainloop(self): self.gui_main.mainloop()
|
||||||
|
|
|
@ -29,11 +29,11 @@ class Main:
|
||||||
self.common.translate("Error"),
|
self.common.translate("Error"),
|
||||||
self.common.translate("There is no pack in the ./Pack/ directory.")
|
self.common.translate("There is no pack in the ./Pack/ directory.")
|
||||||
)
|
)
|
||||||
self.quit()
|
#self.quit()
|
||||||
|
|
||||||
self.is_dev_version = False # Is this installer version a dev ?
|
self.is_dev_version = False # Is this installer version a dev ?
|
||||||
self.is_track_configuration_edited = False
|
self.is_track_configuration_edited = False
|
||||||
self.stringvar_ctconfig = StringVar(value=self.available_packs[0])
|
self.stringvar_ctconfig = StringVar(value=self.available_packs[0] if self.available_packs else None)
|
||||||
self.stringvar_language = StringVar(value=self.common.option.language)
|
self.stringvar_language = StringVar(value=self.common.option.language)
|
||||||
self.stringvar_game_format = StringVar(value=self.common.option.format)
|
self.stringvar_game_format = StringVar(value=self.common.option.format)
|
||||||
self.boolvar_dont_check_for_update = BooleanVar(value=self.common.option.dont_check_for_update)
|
self.boolvar_dont_check_for_update = BooleanVar(value=self.common.option.dont_check_for_update)
|
||||||
|
@ -60,9 +60,17 @@ class Main:
|
||||||
textvariable=self.stringvar_ctconfig,
|
textvariable=self.stringvar_ctconfig,
|
||||||
width=30
|
width=30
|
||||||
)
|
)
|
||||||
self.combobox_ctconfig_path.grid(row=1, column=1, sticky="NEWS", columnspan=2)
|
self.combobox_ctconfig_path.grid(row=1, column=1, sticky="NEWS")
|
||||||
self.combobox_ctconfig_path.bind("<<ComboboxSelected>>", lambda x=None: self.reload_ctconfig())
|
self.combobox_ctconfig_path.bind("<<ComboboxSelected>>", lambda x=None: self.reload_ctconfig())
|
||||||
self.reload_ctconfig()
|
|
||||||
|
self.button_add_mod = Button(
|
||||||
|
self.frame_ctconfig,
|
||||||
|
text="+",
|
||||||
|
relief=RIDGE,
|
||||||
|
command=self.common.show_gui_add_pack,
|
||||||
|
width=2
|
||||||
|
)
|
||||||
|
self.button_add_mod.grid(row=1, column=2)
|
||||||
|
|
||||||
# Jeu
|
# Jeu
|
||||||
self.frame_game_path = LabelFrame(self.root, text=self.common.translate("Original game"))
|
self.frame_game_path = LabelFrame(self.root, text=self.common.translate("Original game"))
|
||||||
|
@ -249,10 +257,19 @@ class Main:
|
||||||
self.menu_help.add_command(label="Github Wiki", command=lambda: webbrowser.open(GITHUB_HELP_PAGE_URL))
|
self.menu_help.add_command(label="Github Wiki", command=lambda: webbrowser.open(GITHUB_HELP_PAGE_URL))
|
||||||
self.menu_help.add_command(label="Discord", command=lambda: webbrowser.open(DISCORD_URL))
|
self.menu_help.add_command(label="Discord", command=lambda: webbrowser.open(DISCORD_URL))
|
||||||
|
|
||||||
|
self.reload_ctconfig()
|
||||||
|
|
||||||
def reload_ctconfig(self) -> None:
|
def reload_ctconfig(self) -> None:
|
||||||
self.common.ct_config.load_ctconfig_file(
|
self.available_packs = self.get_available_packs()
|
||||||
ctconfig_file=self.get_ctconfig_path_pack(self.stringvar_ctconfig.get())
|
if self.available_packs: self.state_button(enable=True)
|
||||||
)
|
else: self.state_button(enable=False)
|
||||||
|
|
||||||
|
self.combobox_ctconfig_path.configure(values=self.available_packs)
|
||||||
|
|
||||||
|
if self.stringvar_ctconfig.get():
|
||||||
|
self.common.ct_config.load_ctconfig_file(
|
||||||
|
ctconfig_file=self.get_ctconfig_path_pack(self.stringvar_ctconfig.get())
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_available_packs() -> list:
|
def get_available_packs() -> list:
|
||||||
|
@ -352,9 +369,9 @@ class Main:
|
||||||
:param enable: are the button enabled ?
|
:param enable: are the button enabled ?
|
||||||
"""
|
"""
|
||||||
button = [
|
button = [
|
||||||
self.button_do_everything,
|
|
||||||
self.button_select_path,
|
|
||||||
self.combobox_ctconfig_path,
|
self.combobox_ctconfig_path,
|
||||||
|
self.button_select_path,
|
||||||
|
self.button_do_everything
|
||||||
]
|
]
|
||||||
for widget in button:
|
for widget in button:
|
||||||
if enable: widget.config(state=NORMAL)
|
if enable: widget.config(state=NORMAL)
|
||||||
|
|
|
@ -1,3 +1,77 @@
|
||||||
|
from tkinter import *
|
||||||
|
from tkinter import ttk
|
||||||
|
from tkinter import filedialog
|
||||||
|
from tkinter import messagebox
|
||||||
|
import zipfile
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class SelectPack:
|
class SelectPack:
|
||||||
def __init__(self):
|
def __init__(self, common):
|
||||||
pass
|
self.common = common
|
||||||
|
|
||||||
|
self.root = Toplevel(self.common.gui_main.root)
|
||||||
|
self.root.title(self.common.translate("Add a pack"))
|
||||||
|
self.root.iconbitmap("./icon.ico")
|
||||||
|
self.root.resizable(False, False)
|
||||||
|
self.root.grab_set()
|
||||||
|
|
||||||
|
self.entry_modpack_path = Entry(self.root, width=50)
|
||||||
|
self.entry_modpack_path.grid(row=1, column=1, sticky="NEWS")
|
||||||
|
|
||||||
|
def select_path():
|
||||||
|
path = filedialog.askopenfilename(
|
||||||
|
filetypes=((self.common.translate("MKW Pack"), r"*.mkwf.pack"),)
|
||||||
|
)
|
||||||
|
if os.path.exists(path):
|
||||||
|
self.entry_modpack_path.delete(0, END)
|
||||||
|
self.entry_modpack_path.insert(0, path)
|
||||||
|
|
||||||
|
self.button_select_path = Button(
|
||||||
|
self.root,
|
||||||
|
text="...",
|
||||||
|
relief=RIDGE,
|
||||||
|
command=lambda: self.root.after(0, select_path)
|
||||||
|
)
|
||||||
|
self.button_select_path.grid(row=1, column=2)
|
||||||
|
|
||||||
|
def extract_pack():
|
||||||
|
self.progressbar_extract.grid(row=3, column=1, columnspan=2, sticky="NEWS")
|
||||||
|
try:
|
||||||
|
path = self.entry_modpack_path.get()
|
||||||
|
*packname, _, _ = os.path.basename(path).split(".")
|
||||||
|
packname = ".".join(packname)
|
||||||
|
|
||||||
|
with zipfile.ZipFile(path) as zip_pack:
|
||||||
|
zip_pack.extractall(f"./Pack/{packname}/")
|
||||||
|
|
||||||
|
self.common.gui_main.reload_ctconfig()
|
||||||
|
|
||||||
|
messagebox.showinfo(
|
||||||
|
self.common.translate("Extraction"),
|
||||||
|
self.common.translate("The mod have been extracted !")
|
||||||
|
)
|
||||||
|
self.root.destroy()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.progressbar_extract.grid_forget()
|
||||||
|
raise e
|
||||||
|
|
||||||
|
self.button_extract_modpack = Button(
|
||||||
|
self.root,
|
||||||
|
text=self.common.translate("Extract the modpack"),
|
||||||
|
relief=RIDGE,
|
||||||
|
command=extract_pack
|
||||||
|
)
|
||||||
|
self.button_extract_modpack.grid(row=2, column=1, columnspan=2, sticky="NEWS")
|
||||||
|
|
||||||
|
self.progressbar_extract = ttk.Progressbar(self.root)
|
||||||
|
self.progressbar_extract.configure(mode="indeterminate")
|
||||||
|
self.progressbar_extract.start(50)
|
||||||
|
|
||||||
|
def state_button(self, enable=True):
|
||||||
|
for button in [
|
||||||
|
self.button_extract_modpack
|
||||||
|
]:
|
||||||
|
if enable: button.config(state=NORMAL)
|
||||||
|
else: button.config(state=DISABLED)
|
||||||
|
|
|
@ -110,6 +110,11 @@
|
||||||
"value2": "valeur2",
|
"value2": "valeur2",
|
||||||
"Save track configuration": "Sauvegarder la configuration de course",
|
"Save track configuration": "Sauvegarder la configuration de course",
|
||||||
"track configuration": "configuration de course",
|
"track configuration": "configuration de course",
|
||||||
"Load track configuration": "Charger la configuration de course"
|
"Load track configuration": "Charger la configuration de course",
|
||||||
|
"Add a pack": "Ajouter un pack",
|
||||||
|
"Extract the modpack": "Extraire le modpack",
|
||||||
|
"MKW Pack": "Pack MKW",
|
||||||
|
"Extraction": "Extraction",
|
||||||
|
"The mod have been extracted !": "Le mod à bien été extrait !"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue