From 5bff74b55b1fd73465ce0fafa27eabd9dff9f549 Mon Sep 17 00:00:00 2001 From: freeram Date: Sat, 4 May 2024 03:45:55 -0600 Subject: [PATCH] Show error if user tries to plot with no data --- src/frames/stats_frame.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/frames/stats_frame.py b/src/frames/stats_frame.py index 7a75c92..4f57578 100644 --- a/src/frames/stats_frame.py +++ b/src/frames/stats_frame.py @@ -1,5 +1,6 @@ import customtkinter as ctk from datetime import datetime +from CTkMessagebox import CTkMessagebox from src.reusable.stats_reusable import StatisticFrame, ButtonFrame from src.utils import load_data from src.logic.graphs import graph_pomodoro_sessions, graph_hours_studied @@ -51,8 +52,20 @@ def update_total_pomodoros(self, data): total_pomodoros = data.get('total_pomodoro_sessions', 0) self.total_pomodoros.set_value(f"{total_pomodoros} session{'s' if total_pomodoros != 1 else ''}") + def _ensure_exists(self, param, msg): + data = load_data() + value = data.get(param, 0) + if value == 0: + CTkMessagebox(title="Error", message=msg, icon="cancel") + return False + return True + def show_sessions_graph(self): + if not self._ensure_exists('total_pomodoro_sessions', 'Cannot graph pomodoro sessions: none recorded'): + return graph_pomodoro_sessions(load_data()) def show_hours_graph(self): + if not self._ensure_exists('total_seconds_studied', 'Cannot graph hours studied: none recorded'): + return graph_hours_studied(load_data())