Skip to content

Commit

Permalink
♻️ Refactor:Using more class instead of using all in home_page
Browse files Browse the repository at this point in the history
  • Loading branch information
NTGNguyen committed Sep 9, 2024
1 parent 715c2aa commit 1c2a759
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 21 deletions.
20 changes: 20 additions & 0 deletions src/GUI/screen/form_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""The Form to input num of points"""
import tkinter as tk


class FormFrame(tk.Frame):
"""The Form Class
Args:
tk (Frame): Frame modules in tkinter
"""

def __init__(self, controller):
super().__init__(controller)
self.pack(side=tk.RIGHT, padx=10, pady=10)

self.label = tk.Label(self, text="Number of Points:")
self.label.pack(side=tk.TOP, padx=5)

self.entry = tk.Entry(self)
self.entry.pack(side=tk.TOP, padx=5)
12 changes: 7 additions & 5 deletions src/GUI/screen/home_page.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""The Home Page element(parent is app)"""
import tkinter as tk

from src.constants import BANNER
from src.constants import BANNER_IMG_PATH_REMOVEBG

from .start_button import StartButton
from .button import StartButton


class HomePage(tk.Frame):
Expand All @@ -18,8 +18,10 @@ def __init__(self, parent, controller):
super().__init__(parent)
self.controller = controller

label = tk.Label(self, text=BANNER)
label.pack(pady=20)
self.banner_image = tk.PhotoImage(file=BANNER_IMG_PATH_REMOVEBG)
label = tk.Label(self, image=self.banner_image)
label.pack(side="top", fill="both", expand=True)

button = StartButton(self, controller, "MainPage")
button.pack()
button.config(width=20, height=3)
button.pack(side="bottom", pady=150)
59 changes: 43 additions & 16 deletions src/GUI/screen/main_page.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
from src.constants import DRAW_POINTS_TEXT, NEXT_STEP_BUTTON_TEXT
import tkinter as tk
from tkinter import messagebox

from src.GUI.coordinate_system.coordinate_system import CoordinateSystem

from .form_frame import FormFrame

from .button import ButtonInFrame2


class MainPage(tk.Frame):
"""MainPage class heritant from Frame in tkinter modules
Args:
tk (Frame): Frame from Tkinter modules
"""

def __init__(self, parent, controller):
super().__init__(parent)
self.controller = controller
Expand All @@ -13,27 +24,37 @@ def __init__(self, parent, controller):
self, bg='white')
self.coordinate_system.pack(fill=tk.BOTH, expand=True, padx=300)

self.form_frame = tk.Frame(self)
self.form_frame.pack(side=tk.RIGHT, padx=10, pady=10)
self.form_frame = FormFrame(self)
self.form_frame.pack()
# self.form_frame = tk.Frame(self)
# self.form_frame.pack(side=tk.RIGHT, padx=10, pady=10)

# self.label = tk.Label(self.form_frame, text="Number of Points:")
# self.label.pack(side=tk.TOP, padx=5)

self.label = tk.Label(self.form_frame, text="Number of Points:")
self.label.pack(side=tk.TOP, padx=5)
# self.entry = tk.Entry(self.form_frame)
# self.entry.pack(side=tk.TOP, padx=5)

self.entry = tk.Entry(self.form_frame)
self.entry.pack(side=tk.TOP, padx=5)
# self.button = tk.Button(
# self.form_frame, text="Draw Points", command=self.draw_points)
# self.button.pack(side=tk.TOP, padx=5)
self.add_points_button = ButtonInFrame2(DRAW_POINTS_TEXT, self.form_frame, self.draw_points)
self.next_step_button = ButtonInFrame2(NEXT_STEP_BUTTON_TEXT, self.form_frame, self.start_algo)
# self.next_step_button = tk.Button(
# self.form_frame, text="Next Step", command=self.start_algo)
# self.next_step_button.pack(side=tk.TOP, padx=5)

self.button = tk.Button(
self.form_frame, text="Draw Points", command=self.draw_points)
self.button.pack(side=tk.TOP, padx=5)
def draw_points(self) -> None:
"""Reads the number of clusters from the entry and draws them.
self.next_step_button = tk.Button(
self.form_frame, text="Next Step", command=self.start_algo)
self.next_step_button.pack(side=tk.TOP, padx=5)
Args:
self(MainPage)
def draw_points(self):
"""Reads the number of clusters from the entry and draws them."""
Returns:
None
"""
try:
num_points = int(self.entry.get())
num_points = int(self.form_frame.entry.get())
if num_points > 0 and num_points < 6:
self.coordinate_system.draw_random_points(num_points)
else:
Expand All @@ -44,5 +65,11 @@ def draw_points(self):
"Invalid input", "Please enter a valid number of points.")

def start_algo(self):
"""Triggers the next step in the process."""
"""Triggers the next step in the process.
Args:
self(MainPage)
Returns:
None
"""
self.coordinate_system.start_algor()

0 comments on commit 1c2a759

Please sign in to comment.