From 656db5c430a978a5a435508c355719e6638a78b6 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Thu, 16 May 2024 10:44:55 +0200 Subject: [PATCH] feat: add the MVC model in gui package --- src/antares_web_installer/gui/__init__.py | 0 src/antares_web_installer/gui/__main__.py | 14 +++++ src/antares_web_installer/gui/mvc.py | 61 +++++++++++++++++++ .../gui/wizard_controller.py | 12 ++++ src/antares_web_installer/gui/wizard_model.py | 5 ++ src/antares_web_installer/gui/wizard_view.py | 7 +++ 6 files changed, 99 insertions(+) create mode 100644 src/antares_web_installer/gui/__init__.py create mode 100644 src/antares_web_installer/gui/__main__.py create mode 100644 src/antares_web_installer/gui/mvc.py create mode 100644 src/antares_web_installer/gui/wizard_controller.py create mode 100644 src/antares_web_installer/gui/wizard_model.py create mode 100644 src/antares_web_installer/gui/wizard_view.py diff --git a/src/antares_web_installer/gui/__init__.py b/src/antares_web_installer/gui/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/antares_web_installer/gui/__main__.py b/src/antares_web_installer/gui/__main__.py new file mode 100644 index 0000000..8b6af43 --- /dev/null +++ b/src/antares_web_installer/gui/__main__.py @@ -0,0 +1,14 @@ +""" +Main entrypoint for the GUI application. +""" + +from antares_web_installer.gui.wizard_controller import WizardController + + +def main(): + controller = WizardController() + controller.run() + + +if __name__ == "__main__": + main() diff --git a/src/antares_web_installer/gui/mvc.py b/src/antares_web_installer/gui/mvc.py new file mode 100644 index 0000000..a76e15c --- /dev/null +++ b/src/antares_web_installer/gui/mvc.py @@ -0,0 +1,61 @@ +import tkinter as tk + + +class Model: + """ + Base class of the MVC model. + + Attributes: + controller: The controller of the MVC. + """ + + def __init__(self, controller: "Controller"): + self.controller = controller + + +class View(tk.Tk): + """ + Base class of the MVC view. + + Attributes: + controller: The controller of the MVC. + """ + + def __init__(self, controller: "Controller"): + super().__init__() + self.controller = controller + self.init_window() + self.init_handlers() + + def init_window(self) -> None: + self.title("MVC Demo") + + def init_handlers(self) -> None: + self.protocol("WM_DELETE_WINDOW", self.controller.quit) + self.bind("", lambda e: self.controller.quit()) + + +class Controller: + """ + Base class of the MVC controller. + + Attributes: + model: The model of the MVC. + view: The view of the MVC. + """ + + def __init__(self): + self.model = self.init_model() + self.view = self.init_view() + + def init_model(self) -> Model: + return Model(self) + + def init_view(self) -> View: + return View(self) + + def run(self) -> None: + self.view.mainloop() + + def quit(self) -> None: + self.view.destroy() diff --git a/src/antares_web_installer/gui/wizard_controller.py b/src/antares_web_installer/gui/wizard_controller.py new file mode 100644 index 0000000..9bbd208 --- /dev/null +++ b/src/antares_web_installer/gui/wizard_controller.py @@ -0,0 +1,12 @@ +from .mvc import Controller, Model, View +from .wizard_model import WizardModel +from .wizard_view import WizardView + + +class WizardController(Controller): + + def init_model(self) -> Model: + return WizardModel(self) + + def init_view(self) -> View: + return WizardView(self) diff --git a/src/antares_web_installer/gui/wizard_model.py b/src/antares_web_installer/gui/wizard_model.py new file mode 100644 index 0000000..312d249 --- /dev/null +++ b/src/antares_web_installer/gui/wizard_model.py @@ -0,0 +1,5 @@ +from .mvc import Model + + +class WizardModel(Model): + pass diff --git a/src/antares_web_installer/gui/wizard_view.py b/src/antares_web_installer/gui/wizard_view.py new file mode 100644 index 0000000..a77a128 --- /dev/null +++ b/src/antares_web_installer/gui/wizard_view.py @@ -0,0 +1,7 @@ +from .mvc import View + + +class WizardView(View): + def init_window(self) -> None: + super().init_window() + self.title("Antares Web Installer")