Skip to content

Commit

Permalink
Show error if user tries to plot with no data
Browse files Browse the repository at this point in the history
  • Loading branch information
jake158 committed May 4, 2024
1 parent e0a3520 commit 5bff74b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/frames/stats_frame.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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())

0 comments on commit 5bff74b

Please sign in to comment.