Skip to content

Commit

Permalink
feat(application): refactoring and first GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
maugde committed May 13, 2024
1 parent 8479e2e commit f0e1b83
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/antares_web_installer/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Main entrypoint for the CLI application.
"""

import sys

from antares_web_installer.cli import install_cli
Expand Down
64 changes: 56 additions & 8 deletions src/antares_web_installer/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import dataclasses
import os
from pathlib import Path

import psutil
import tkinter as tk

from tkinter import ttk
from pathlib import Path
from antares_web_installer.installer import install


Expand All @@ -13,17 +14,64 @@ class App:
target_dir: Path
app_name: str = "AntaresWebInstaller"
os_name: str = os.name
window_width: int = 800
window_height: int = 600

# def __post_init__(self):
# self.source_dir = Path(self.source_dir)
# self.target_dir = Path(self.target_dir)

def install(self) -> None:
self.server_running_handler()
self.install_files()
self.create_icons()
self.start_server()
self.open_web_browser()
def run(self) -> None:
window = self.init_window()
# self.server_running_handler()
# self.install_files()
# self.create_icons()
# self.start_server()
# self.open_web_browser()
window.mainloop()

def init_window(self) -> tk.Tk:
window = tk.Tk()

center_x = int(window.winfo_screenwidth()/2) - int(self.window_width/2)
center_y = int(window.winfo_screenheight()/2) - int(self.window_height/2)

window.title("Antares Web Installer")
window.geometry(f"{self.window_width}x{self.window_height}+{center_x}+{center_y}")
window.rowconfigure(0, minsize=int(self.window_height/5*4), weight=5)
window.rowconfigure(1, minsize=int(self.window_height/5), weight=1)

# Side Frame
side = ttk.Frame(window)
side.grid(column=0, row=0, rowspan=4)
side['borderwidth'] = 3
side['relief'] = 'solid'
ttk.Label(side, text="Side", foreground="white", background="blue")

# Main Frame
main = ttk.Frame(window)
main.grid(column=1, row=0, columnspan=1, rowspan=4)
main['borderwidth'] = 3
main['relief'] = 'solid'
ttk.Label(main, text="Main", foreground="white", background="orange")


# Footer Frame
footer = ttk.Frame(window)
footer.grid(column=0, row=1, columnspan=2, sticky="se", padx=5, pady=5)

# Buttons
buttons = dict()
# Back
buttons["Back"] = ttk.Button(master=footer, text="Back")
# Next
buttons["next"] = ttk.Button(master=footer, text="Next")
# Cancel
buttons["cancel"] = ttk.Button(master=footer, text="Cancel", command=window.destroy)

for index, btn in enumerate(buttons.values()):
btn.grid(column=index, row=0, sticky="se")
return window

def server_running_handler(self) -> None:
"""
Expand Down
5 changes: 3 additions & 2 deletions src/antares_web_installer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import click
import psutil

from antares_web_installer.installer import install
from antares_web_installer.app import App

if os.name == "posix":
TARGET_DIR = "/opt/antares-web/"
Expand Down Expand Up @@ -45,7 +45,8 @@ def install_cli(src_dir: str, target_dir: str) -> None:
server_running_handler()

print(f"Starting installation in directory: '{target_dir}'...")
install(src_dir, target_dir)
app = App(src_dir, target_dir)
app.run()
print("Done.")


Expand Down
2 changes: 1 addition & 1 deletion src/antares_web_installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def install(src_dir: Path, target_dir: Path) -> None:
if target_dir.is_dir() and list(target_dir.iterdir()):
# check app version
version = check_version(target_dir)
print(f"Version actuelle de l'application : {version}")
print(f"Current application version : {version}")

# update config file
config_path = target_dir.joinpath("config.yaml")
Expand Down
1 change: 0 additions & 1 deletion tests/samples/initial/posix/AntaresWeb/AntaresWebServer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os

import click

OLD_ANTARES_VERSION = os.environ.get("ANTARES_VERSION", "2.17")
Expand Down

0 comments on commit f0e1b83

Please sign in to comment.