Skip to content

Commit

Permalink
feat: add the MVC model in gui package
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent-laporte-pro committed May 16, 2024
1 parent f6807b0 commit 656db5c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
Empty file.
14 changes: 14 additions & 0 deletions src/antares_web_installer/gui/__main__.py
Original file line number Diff line number Diff line change
@@ -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()
61 changes: 61 additions & 0 deletions src/antares_web_installer/gui/mvc.py
Original file line number Diff line number Diff line change
@@ -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("<Escape>", 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()
12 changes: 12 additions & 0 deletions src/antares_web_installer/gui/wizard_controller.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions src/antares_web_installer/gui/wizard_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .mvc import Model


class WizardModel(Model):
pass
7 changes: 7 additions & 0 deletions src/antares_web_installer/gui/wizard_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .mvc import View


class WizardView(View):
def init_window(self) -> None:
super().init_window()
self.title("Antares Web Installer")

0 comments on commit 656db5c

Please sign in to comment.