mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-03 11:18:26 +02:00
optimised the main window code by moving source and destination path to variable instead of getter in the frame class
This commit is contained in:
parent
2edb82939c
commit
f1a9a9bd1c
1 changed files with 13 additions and 54 deletions
|
@ -46,6 +46,9 @@ class Window(tkinter.Tk):
|
||||||
self.mod_config: ModConfig | None = None
|
self.mod_config: ModConfig | None = None
|
||||||
self.options: Options = options
|
self.options: Options = options
|
||||||
|
|
||||||
|
self.source_path = tkinter.StringVar()
|
||||||
|
self.destination_path = tkinter.StringVar()
|
||||||
|
|
||||||
self.title(_("INSTALLER_TITLE"))
|
self.title(_("INSTALLER_TITLE"))
|
||||||
self.resizable(False, False)
|
self.resizable(False, False)
|
||||||
self.iconbitmap("./assets/icon.ico")
|
self.iconbitmap("./assets/icon.ico")
|
||||||
|
@ -84,7 +87,6 @@ class Window(tkinter.Tk):
|
||||||
def run_after() -> None:
|
def run_after() -> None:
|
||||||
"""
|
"""
|
||||||
Run after the installer has been initialised, can be used to add plugins
|
Run after the installer has been initialised, can be used to add plugins
|
||||||
:return:
|
|
||||||
"""
|
"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -100,7 +102,6 @@ class Window(tkinter.Tk):
|
||||||
def progress_function(self, func_gen: Generator[Progress, None, None]) -> None:
|
def progress_function(self, func_gen: Generator[Progress, None, None]) -> None:
|
||||||
"""
|
"""
|
||||||
Run a generator function that yield status for the progress bar
|
Run a generator function that yield status for the progress bar
|
||||||
:return:
|
|
||||||
"""
|
"""
|
||||||
# get the generator data yield by the generator function
|
# get the generator data yield by the generator function
|
||||||
for progress in func_gen:
|
for progress in func_gen:
|
||||||
|
@ -115,27 +116,6 @@ class Window(tkinter.Tk):
|
||||||
if progress.max_step is not None: self.progress_bar.set_max_step(progress.max_step)
|
if progress.max_step is not None: self.progress_bar.set_max_step(progress.max_step)
|
||||||
if progress.determinate is not None: self.progress_bar.set_determinate(progress.determinate)
|
if progress.determinate is not None: self.progress_bar.set_determinate(progress.determinate)
|
||||||
|
|
||||||
def get_source_path(self) -> Path:
|
|
||||||
"""
|
|
||||||
Get the path of the source game
|
|
||||||
:return: path of the source game
|
|
||||||
"""
|
|
||||||
return self.source_game.get_path()
|
|
||||||
|
|
||||||
def get_destination_path(self) -> Path:
|
|
||||||
"""
|
|
||||||
Get the path of the destination game
|
|
||||||
:return: path of the destination game
|
|
||||||
"""
|
|
||||||
return self.destination_game.get_path()
|
|
||||||
|
|
||||||
def get_output_type(self) -> Extension:
|
|
||||||
"""
|
|
||||||
Get the output type
|
|
||||||
:return: output type
|
|
||||||
"""
|
|
||||||
return self.destination_game.get_output_type()
|
|
||||||
|
|
||||||
|
|
||||||
# Menu bar
|
# Menu bar
|
||||||
class Menu(tkinter.Menu):
|
class Menu(tkinter.Menu):
|
||||||
|
@ -250,7 +230,7 @@ class SourceGame(ttk.LabelFrame):
|
||||||
|
|
||||||
self.columnconfigure(1, weight=1)
|
self.columnconfigure(1, weight=1)
|
||||||
|
|
||||||
self.entry = ttk.Entry(self, width=55)
|
self.entry = ttk.Entry(self, width=55, textvariable=self.root.source_path)
|
||||||
self.entry.grid(row=1, column=1, sticky="nsew")
|
self.entry.grid(row=1, column=1, sticky="nsew")
|
||||||
|
|
||||||
self.button = ttk.Button(self, text="...", width=2, command=self.select)
|
self.button = ttk.Button(self, text="...", width=2, command=self.select)
|
||||||
|
@ -286,17 +266,10 @@ class SourceGame(ttk.LabelFrame):
|
||||||
self.entry.delete(0, tkinter.END)
|
self.entry.delete(0, tkinter.END)
|
||||||
self.entry.insert(0, str(path.absolute()))
|
self.entry.insert(0, str(path.absolute()))
|
||||||
|
|
||||||
|
# if the selected path is an extracted game, use 2 directory upper
|
||||||
if path.suffix == ".dol": path = path.parent.parent
|
if path.suffix == ".dol": path = path.parent.parent
|
||||||
self.root.destination_game.set_path(path.parent)
|
|
||||||
|
|
||||||
def get_path(self) -> Path:
|
self.root.destination_game.set_path(path.parent)
|
||||||
"""
|
|
||||||
Get the source game path
|
|
||||||
:return: the game path
|
|
||||||
"""
|
|
||||||
path = Path(self.entry.get())
|
|
||||||
if not path.exists(): raise SourceGameError(path)
|
|
||||||
return path
|
|
||||||
|
|
||||||
def set_state(self, state: InstallerState) -> None:
|
def set_state(self, state: InstallerState) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -318,12 +291,12 @@ class DestinationGame(ttk.LabelFrame):
|
||||||
|
|
||||||
self.columnconfigure(1, weight=1)
|
self.columnconfigure(1, weight=1)
|
||||||
|
|
||||||
self.entry = ttk.Entry(self)
|
self.entry = ttk.Entry(self, textvariable=self.root.destination_path)
|
||||||
self.entry.grid(row=1, column=1, sticky="nsew")
|
self.entry.grid(row=1, column=1, sticky="nsew")
|
||||||
|
|
||||||
self.output_type = ttk.Combobox(self, width=5, values=[extension.name for extension in Extension])
|
self.output_type = ttk.Combobox(self, width=5, values=[extension.name for extension in Extension])
|
||||||
self.output_type.set(self.root.options.extension.get())
|
|
||||||
self.output_type.bind("<<ComboboxSelected>>", lambda _: self.root.options.extension.set(self.output_type.get()))
|
self.output_type.bind("<<ComboboxSelected>>", lambda _: self.root.options.extension.set(self.output_type.get()))
|
||||||
|
self.output_type.set(self.root.options.extension.get())
|
||||||
self.output_type.grid(row=1, column=2, sticky="nsew")
|
self.output_type.grid(row=1, column=2, sticky="nsew")
|
||||||
|
|
||||||
self.button = ttk.Button(self, text="...", width=2, command=self.select)
|
self.button = ttk.Button(self, text="...", width=2, command=self.select)
|
||||||
|
@ -353,22 +326,6 @@ class DestinationGame(ttk.LabelFrame):
|
||||||
self.entry.delete(0, tkinter.END)
|
self.entry.delete(0, tkinter.END)
|
||||||
self.entry.insert(0, str(path.absolute()))
|
self.entry.insert(0, str(path.absolute()))
|
||||||
|
|
||||||
def get_path(self) -> Path:
|
|
||||||
"""
|
|
||||||
Get the destination game path
|
|
||||||
:return: the game path
|
|
||||||
"""
|
|
||||||
path = Path(self.entry.get())
|
|
||||||
if not path.exists(): raise DestinationGameError(path)
|
|
||||||
return path
|
|
||||||
|
|
||||||
def get_output_type(self) -> Extension:
|
|
||||||
"""
|
|
||||||
Get the output type
|
|
||||||
:return: the output type
|
|
||||||
"""
|
|
||||||
return Extension[self.output_type.get()]
|
|
||||||
|
|
||||||
def set_state(self, state: InstallerState) -> None:
|
def set_state(self, state: InstallerState) -> None:
|
||||||
"""
|
"""
|
||||||
Set the progress bar state when the installer change state
|
Set the progress bar state when the installer change state
|
||||||
|
@ -396,13 +353,15 @@ class ButtonInstall(ttk.Button):
|
||||||
self.root.set_state(InstallerState.INSTALLING)
|
self.root.set_state(InstallerState.INSTALLING)
|
||||||
|
|
||||||
# check if the user entered a source path
|
# check if the user entered a source path
|
||||||
source_path = self.root.get_source_path()
|
source_path = Path(self.root.source_path.get())
|
||||||
|
if not source_path.exists(): raise SourceGameError(source_path)
|
||||||
if str(source_path) == ".":
|
if str(source_path) == ".":
|
||||||
messagebox.showerror(_("ERROR"), _("ERROR_INVALID_SOURCE_GAME"))
|
messagebox.showerror(_("ERROR"), _("ERROR_INVALID_SOURCE_GAME"))
|
||||||
return
|
return
|
||||||
|
|
||||||
# check if the user entered a destination path
|
# check if the user entered a destination path
|
||||||
destination_path = self.root.get_destination_path()
|
destination_path = Path(self.root.destination_path.get())
|
||||||
|
if not destination_path.exists(): raise DestinationGameError(destination_path)
|
||||||
if str(destination_path) == ".":
|
if str(destination_path) == ".":
|
||||||
messagebox.showerror(_("ERROR"), _("ERROR_INVALID_DESTINATION_GAME"))
|
messagebox.showerror(_("ERROR"), _("ERROR_INVALID_DESTINATION_GAME"))
|
||||||
return
|
return
|
||||||
|
@ -418,7 +377,7 @@ class ButtonInstall(ttk.Button):
|
||||||
return
|
return
|
||||||
|
|
||||||
game = Game(source_path)
|
game = Game(source_path)
|
||||||
output_type = self.root.get_output_type()
|
output_type = Extension[self.root.options.extension.get()]
|
||||||
|
|
||||||
self.root.progress_function(
|
self.root.progress_function(
|
||||||
game.install_mod(
|
game.install_mod(
|
||||||
|
|
Loading…
Reference in a new issue