-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainMenuGUI.py
More file actions
206 lines (163 loc) · 7.87 KB
/
Copy pathMainMenuGUI.py
File metadata and controls
206 lines (163 loc) · 7.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import wx
from datetime import datetime
from AddHabit import AddHabitFrame
from UserSelection import UserSelectionFrame
import logging
import Analyzer
import HabitAnalyzerGUI
class MainMenuGUIFrame(wx.Frame):
"""
The main menu frame of the application, providing an interface to manage and track habits.
This frame contains a list of habits with details such as name, frequency, start date,
last performed date, next due date, days until due, and current streak. It also includes
options to perform a habit now, add a new habit, edit an existing habit, remove a habit,
and access analytics for a specific habit.
Parameters:
parent (wx.Window): The parent window for this frame.
title (str): The title of the frame.
Orchestrator (Orchestrator): An instance of the Orchestrator class, used for habit management.
"""
def __init__(self, parent, title, Orchestrator):
"""Initialize the MainMenuGUIFrame with a given title and orchestrator."""
super(MainMenuGUIFrame, self).__init__(parent, title=title, size=(800, 400))
self.Orchestrator = Orchestrator
panel = wx.Panel(self)
box = wx.BoxSizer(wx.VERTICAL)
# 1. Reihe: Text in Überschrift Größe "Habit Hero"
header = wx.StaticText(panel, label="Habit Hero")
header.SetFont(wx.Font(18, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
box.Add(header, flag=wx.EXPAND | wx.ALL, border=10)
# 2. Reihe: Today: <Aktuelles Datum>
today = datetime.now().strftime('%Y-%m-%d')
date_label = wx.StaticText(panel, label=f"Today: {today}")
box.Add(date_label, flag=wx.EXPAND | wx.ALL, border=10)
# 3. Reihe: List_Ctrl
self.data_view = wx.ListCtrl(panel, style=wx.LC_REPORT)
self.data_view.InsertColumn(0, "Habit")
self.data_view.InsertColumn(1, "Frequency")
self.data_view.InsertColumn(2, "Start Date")
self.data_view.InsertColumn(3, "Last Date")
self.data_view.InsertColumn(4, "Next Due Date")
self.data_view.InsertColumn(5, "Days until Due")
self.data_view.InsertColumn(6, "Streak")
self.data_view.SetColumnWidth(0, 300)
self.data_view.SetColumnWidth(2, 100)
self.data_view.SetColumnWidth(3, 100)
self.data_view.SetColumnWidth(4, 100)
box.Add(self.data_view, 1, flag=wx.EXPAND | wx.ALL, border=10) # Note the "1" here
# 4. Reihe: Buttons
button_box = wx.BoxSizer(wx.HORIZONTAL)
perform_now_button = wx.Button(panel, label="Perform Now")
perform_now_button.Bind(wx.EVT_BUTTON, self.on_perform)
button_box.Add(perform_now_button, proportion=1)
# Todo Add a button to select a date to perform.
# perform_on_date = wx.Button(panel, label="Perform on Date")
# perform_on_date_button.Bind(wx.EVT_Button,)
new_button = wx.Button(panel, label="New Habit")
new_button.Bind(wx.EVT_BUTTON, self.on_new)
button_box.Add(new_button, proportion=1)
edit_button = wx.Button(panel, label="Edit")
edit_button.Bind(wx.EVT_BUTTON, self.on_edit)
button_box.Add(edit_button, proportion=1)
remove_button = wx.Button(panel, label="Remove")
remove_button.Bind(wx.EVT_BUTTON, self.on_remove)
button_box.Add(remove_button, proportion=1)
analyze_button = wx.Button(panel, label="Analytics")
analyze_button.Bind(wx.EVT_BUTTON, self.on_analyze)
button_box.Add(analyze_button, proportion=1)
box.Add(button_box, flag=wx.EXPAND | wx.ALL, border=10)
panel.SetSizer(box)
UserSelectionFrame(self, self.Orchestrator)
self.Centre()
# elf.Show(True)
def add_habit_to_data_view(self, habit):
"""
Adds a habit to the DataViewListCtrl.
Parameters:
habit (Habit): The habit object containing the details to be added.
"""
# Extract the attributes from the habit object.
name = habit.name
frequency = habit.frequency
start_date = habit.start_date
last_perfomed = habit.get_last_performed()
next_due_date = habit.next_due_date
days_until_due = Analyzer.days_until_date(next_due_date)
if days_until_due < 0:
streak = 0
habit.streak = 0
self.Orchestrator.save_data()
else:
streak = habit.streak
# Append a new row to the DataViewListCtrl.
self.data_view.Append([name, frequency, start_date, last_perfomed, next_due_date, days_until_due, streak])
self.data_view.SetColumnWidth(0, wx.LIST_AUTOSIZE)
self.data_view.SetColumnWidth(1, wx.LIST_AUTOSIZE) # Assuming you have a second column
self.data_view.SetColumnWidth(2, wx.LIST_AUTOSIZE)
self.data_view.SetColumnWidth(3, wx.LIST_AUTOSIZE)
self.data_view.SetColumnWidth(4, wx.LIST_AUTOSIZE)
def on_analyze(self, event):
"""
This method opens the analytics GUI for the selected habit.
If no habit is selected, it shows a warning message.
Parameters:
event (wx.Event): The event object.
"""
selection = self.data_view.GetNextSelected(-1)
if selection == -1: # Check if no row is selected
wx.MessageBox("Please select a habit to edit!", "Warning", wx.OK | wx.ICON_WARNING)
return
selected_habit = self.Orchestrator.get_habit_by_index(selection)
HabitAnalyzerGUI.AnalyzeGUI(selected_habit, title=selected_habit.name)
def on_new(self, event):
"""
Opens the frame to add a new habit.
Parameters:
event (wx.Event): The event object.
"""
AddHabitFrame(self, self.Orchestrator, title="Add new habbit")
def on_edit(self, event):
"""
Opens the frame to edit the selected habit.
Parameters:
event (wx.Event): The event object.
"""
selection = self.data_view.GetNextSelected(-1)
if selection == -1: # Check if no row is selected
wx.MessageBox("Please select a habit to edit!", "Warning", wx.OK | wx.ICON_WARNING)
return
AddHabitFrame(self, self.Orchestrator, habit=self.Orchestrator.habits[selection], title="Edit habbit")
def on_remove(self, event):
"""
This method prompts for confirmation before removing the habit.
If no habit is selected, it shows a warning message.
Parameters:
event (wx.Event): The event object.
"""
# Get the selected habit
selection = self.data_view.GetNextSelected(-1)
if selection == -1: # Check if no row is selected
wx.MessageBox("Please select a habit to remove!", "Warning", wx.OK | wx.ICON_WARNING)
return
# Confirm the removal with the user
dlg = wx.MessageDialog(self, "Are you sure you want to remove this habit? You can't restore the data once it's deleted.",
"Confirm Deletion", wx.YES_NO | wx.NO_DEFAULT | wx.ICON_WARNING)
if dlg.ShowModal() == wx.ID_YES:
self.data_view.DeleteItem(selection)
self.Orchestrator.delete_habit(selection)
dlg.Destroy()
def on_perform(self, event):
"""
Marks the selected habit as performed for the current day.
If no habit is selected, it shows a warning message. Logs the 'Perform Now' action.
Parameters:
event (wx.Event): The event object.
"""
logging.info("Perform Now button pressed.")
# Get the selected habit
selection = self.data_view.GetNextSelected(-1)
if selection == -1: # Check if no row is selected
wx.MessageBox("Please select a habit to perform now!", "Warning", wx.OK | wx.ICON_WARNING)
return
logging.info(f"Performing habit at row: {selection}")
self.Orchestrator.perform_habit_today(selection)