Refactor method names for clarity and consistency across the application
Build and Push Docker Image / build-and-push (push) Has been cancelled

- Renamed `initialize_csv` to `_initialize_csv_file` in `DataManager` for better clarity.
- Updated method calls in `GraphManager` from `_create_toggle_controls` to `_create_chart_toggles` and `_on_toggle_changed` to `_handle_toggle_changed`.
- Changed method names in `MedTrackerApp` from `on_closing` to `handle_window_closing`, `add_entry` to `add_new_entry`, and `load_data` to `refresh_data_display`.
- Adjusted corresponding test method names in `TestMedTrackerApp` to reflect the new method names.
- Updated `UIManager` method names from `setup_icon` to `setup_application_icon` and adjusted related tests accordingly.
This commit is contained in:
William Valentin
2025-07-30 12:32:17 -07:00
parent e0faf20a56
commit b7c01bc373
6 changed files with 106 additions and 575 deletions
+14 -14
View File
@@ -19,7 +19,7 @@ class MedTrackerApp:
self.root: tk.Tk = root
self.root.resizable(True, True)
self.root.title("Thechart - medication tracker")
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
self.root.protocol("WM_DELETE_WINDOW", self.handle_window_closing)
# Set up data file
self.filename: str = "thechart_data.csv"
@@ -49,7 +49,7 @@ class MedTrackerApp:
icon_path: str = "chart-671.png"
if not os.path.exists(icon_path) and os.path.exists("./chart-671.png"):
icon_path = "./chart-671.png"
self.ui_manager.setup_icon(img_path=icon_path)
self.ui_manager.setup_application_icon(img_path=icon_path)
# Set up the main application UI
self._setup_main_ui()
@@ -85,28 +85,28 @@ class MedTrackerApp:
self.date_var: tk.StringVar = input_ui["date_var"]
# Add buttons to input frame
self.ui_manager.add_buttons(
self.ui_manager.add_action_buttons(
self.input_frame,
[
{
"text": "Add Entry",
"command": self.add_entry,
"command": self.add_new_entry,
"fill": "both",
"expand": True,
},
{"text": "Quit", "command": self.on_closing},
{"text": "Quit", "command": self.handle_window_closing},
],
)
# --- Create Table Frame ---
table_ui: dict[str, Any] = self.ui_manager.create_table_frame(main_frame)
self.tree: ttk.Treeview = table_ui["tree"]
self.tree.bind("<Double-1>", self.on_double_click)
self.tree.bind("<Double-1>", self.handle_double_click)
# Load data
self.load_data()
self.refresh_data_display()
def on_double_click(self, event: tk.Event) -> None:
def handle_double_click(self, event: tk.Event) -> None:
"""Handle double-click event to edit an entry."""
logger.debug("Double-click event triggered on treeview.")
if len(self.tree.get_children()) > 0:
@@ -198,7 +198,7 @@ class MedTrackerApp:
"Success", "Entry updated successfully!", parent=self.root
)
self._clear_entries()
self.load_data()
self.refresh_data_display()
else:
# Check if it's a duplicate date issue
df = self.data_manager.load_data()
@@ -212,14 +212,14 @@ class MedTrackerApp:
else:
messagebox.showerror("Error", "Failed to save changes", parent=edit_win)
def on_closing(self) -> None:
def handle_window_closing(self) -> None:
if messagebox.askokcancel(
"Quit", "Do you want to quit the application?", parent=self.root
):
self.graph_manager.close()
self.root.destroy()
def add_entry(self) -> None:
def add_new_entry(self) -> None:
"""Add a new entry to the CSV file."""
# Get current doses for today
today = self.date_var.get()
@@ -278,7 +278,7 @@ class MedTrackerApp:
"Success", "Entry added successfully!", parent=self.root
)
self._clear_entries()
self.load_data()
self.refresh_data_display()
else:
# Check if it's a duplicate date by trying to load existing data
df = self.data_manager.load_data()
@@ -309,7 +309,7 @@ class MedTrackerApp:
messagebox.showinfo(
"Success", "Entry deleted successfully!", parent=self.root
)
self.load_data()
self.refresh_data_display()
else:
messagebox.showerror("Error", "Failed to delete entry", parent=edit_win)
@@ -323,7 +323,7 @@ class MedTrackerApp:
self.medicine_vars[key][0].set(0)
self.note_var.set("")
def load_data(self) -> None:
def refresh_data_display(self) -> None:
"""Load data from the CSV file into the table and graph."""
logger.debug("Loading data from CSV.")