Skip to content

Commit 56442a4

Browse files
committed
Basic Export System Added
1 parent dc2eb34 commit 56442a4

4 files changed

Lines changed: 108 additions & 17 deletions

File tree

Package/data_management.py

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from collections import Counter
2+
import os
23

34
import datetime
4-
from openpyxl.styles import Font
5+
import openpyxl as op
6+
from openpyxl.styles import Font, Alignment
7+
from openpyxl.utils import get_column_letter
58

69
import customtkinter as ctk
710
import darkdetect
@@ -435,4 +438,68 @@ def load_eye_care(self) -> None:
435438

436439
self.app.eye_care_checkbox.configure(variable=ctk.StringVar(value=checkbox))
437440

438-
self.app.WINDOW.after(0, self.app.eye_protection) # Schedule initial iteration for eye_protection
441+
self.app.WINDOW.after(60*20*1000, self.app.eye_protection) # Schedule initial iteration for eye_protection
442+
443+
444+
def export_data(self):
445+
def change_cell_width(cell_range: tuple, width: int = 15) -> None:
446+
start, end = cell_range
447+
for cell in range(start, end + 1):
448+
cell_letter = get_column_letter(cell)
449+
export_worksheet.column_dimensions[cell_letter].width = width
450+
451+
def align_cells(cell_range: str):
452+
for row in export_worksheet[cell_range]:
453+
for cell in row:
454+
cell.alignment = Alignment(horizontal='center', vertical='center')
455+
456+
export_workbook = op.Workbook()
457+
export_worksheet = export_workbook.active
458+
459+
export_worksheet.merge_cells("A1:E1")
460+
export_worksheet["A1"] = "Timer"
461+
export_worksheet["A1"].font = Font(bold=True, size=16)
462+
align_cells("A1:E1")
463+
464+
export_worksheet["A2"].value = "Start:"
465+
export_worksheet["A2"].font = Font(bold=True, size=12)
466+
export_worksheet["B2"].value = "End:"
467+
export_worksheet["B2"].font = Font(bold=True, size=12)
468+
export_worksheet["C2"].value = "Duration:"
469+
export_worksheet["C2"].font = Font(bold=True, size=12)
470+
export_worksheet["D2"].value = "Break Duration:"
471+
export_worksheet["D2"].font = Font(bold=True, size=12)
472+
export_worksheet["E2"].value = "Subject:"
473+
export_worksheet["E2"].font = Font(bold=True, size=12)
474+
change_cell_width((1, 5), 20)
475+
476+
export_worksheet.merge_cells("G1:I1")
477+
export_worksheet["G1"] = "Notes"
478+
export_worksheet["G1"].font = Font(bold=True, size=16)
479+
align_cells("G1:I1")
480+
481+
export_worksheet["G2"].value = "Date:"
482+
export_worksheet["G2"].font = Font(bold=True, size=12)
483+
export_worksheet["H2"].value = "Title:"
484+
export_worksheet["H2"].font = Font(bold=True, size=12)
485+
export_worksheet["I2"].value = "Text:"
486+
export_worksheet["I2"].font = Font(bold=True, size=12)
487+
change_cell_width((7, 9), 20)
488+
489+
for data in range(3, self.data_amount + 3):
490+
export_worksheet["A" + str(data)].value = self.worksheet["A" + str(data - 1)].value
491+
export_worksheet["B" + str(data)].value = self.worksheet["B" + str(data - 1)].value
492+
export_worksheet["C" + str(data)].value = str(round(self.worksheet["C" + str(data - 1)].value, 1)) + "m"
493+
export_worksheet["D" + str(data)].value = str(round(self.worksheet["D" + str(data - 1)].value, 1)) + "m"
494+
export_worksheet["E" + str(data)].value = self.worksheet["E" + str(data - 1)].value
495+
496+
for note in range(self.notes_amount + 12, 12, -1):
497+
if export_worksheet["M" + str(note-data-2)].value != "Yes":
498+
export_worksheet["G" + str(note-data-2)].value = self.worksheet["N" + str(note)].value
499+
export_worksheet["H" + str(note-data-2)].value = self.worksheet["O" + str(note)].value
500+
export_worksheet["I" + str(note-data-2)].value = self.worksheet["P" + str(note)].value
501+
export_worksheet["I" + str(note-data-2)].alignment = Alignment(wrap_text=True)
502+
503+
export_workbook.save(f"{os.path.join(os.path.expanduser("~"), "Desktop")}/timer_data_{datetime.datetime.now().date().strftime("%d.%m.%Y")}.xlsx")
504+
505+
print("File exported.")

Package/note_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def __init__(self, app, data_manager):
88
self.data_manager = data_manager
99

1010
def create_task(self, index):
11-
self.frame = ctk.CTkFrame(self.app.notes_data_frame, width=WIDTH + frame_padding * 2, fg_color=(light_frame_color, frame_color), height=button_height + frame_padding * 2)
11+
self.frame = ctk.CTkFrame(self.app.notes_data_frame, width=WIDTH, fg_color=(light_frame_color, frame_color), height=button_height + frame_padding * 2)
1212
self.frame.pack(pady=frame_padding/2)
1313
self.frame.grid_propagate(False)
1414

Package/timer_management.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ def initialize_variables(self):
1717
def timer_mechanism(self, timer_button, break_button, time_display_label):
1818
self.time_display_label = time_display_label
1919
if not self.timer_running:
20-
self.app.frequency_input.configure(state="disabled")
21-
self.app.frequency_input.insert("end", self.app.data_manager.autobreak_frequency)
22-
self.app.duration_input.configure(state="disabled")
23-
self.app.duration_input.insert("end", self.app.data_manager.autobreak_duration)
24-
self.app.autobreak_button.configure(state="disabled", fg_color="grey")
25-
if self.app.autobreak_switch.get() == "On":
26-
break_button.configure(state="disabled", fg_color = "grey", command=None, hover=False)
20+
self.app.lock_widgets()
2721

2822
self.timer_running = True
2923
self.break_running = False

main.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,14 @@ def _history_gui_setup(self) -> None:
369369

370370
def _settings_gui_setup(self) -> None:
371371
self.color_frame = ctk.CTkFrame(self.settings_frame, fg_color="transparent")
372-
self.color_frame.grid(column=0)
372+
self.color_frame.grid(column=0, row=0)
373373

374374
self.eye_care_export_frame = ctk.CTkFrame(self.settings_frame, fg_color="transparent")
375-
self.eye_care_export_frame.grid(column=1)
375+
self.eye_care_export_frame.grid(column=1, row=0)
376376

377377
self._color_gui_setup()
378378
self._eye_care_gui_setup()
379+
self._export_gui_setup()
379380

380381
reset_frame = ctk.CTkFrame(self.settings_frame, fg_color=(light_tab_color, tab_color))
381382
reset_frame.place(anchor="s", relx=0.5, rely=0.985)
@@ -409,7 +410,7 @@ def _color_gui_setup(self) -> None:
409410

410411
def _eye_care_gui_setup(self):
411412
eye_care_frame = ctk.CTkFrame(self.eye_care_export_frame, fg_color=(light_frame_color, frame_color), height=250, width=int(frame_width/1.25), corner_radius=10)
412-
eye_care_frame.grid(column=1, row=0, padx=frame_padding, pady=frame_padding)
413+
eye_care_frame.grid(column=0, row=0, padx=frame_padding, pady=frame_padding)
413414
eye_care_label = ctk.CTkLabel(eye_care_frame, text="Eye care", font=(font_family, font_size), text_color=(light_font_color, font_color))
414415
eye_care_label.place(anchor="nw", relx=0.05, rely=0.05)
415416
self.eye_care_selection = ctk.CTkComboBox(eye_care_frame, values=["On", "Off"], state="readonly", width=100, height=30, dropdown_font=(font_family, int(font_size*0.75)),
@@ -423,6 +424,20 @@ def _eye_care_gui_setup(self):
423424
eye_care_button.place(anchor="s", relx=0.5, rely=0.9)
424425

425426

427+
def _export_gui_setup(self):
428+
export_frame = ctk.CTkFrame(self.eye_care_export_frame, fg_color=(light_frame_color, frame_color), height=250, width=int(frame_width/1.25), corner_radius=10)
429+
export_frame.grid(row=1, column=0, padx=frame_padding, pady=frame_padding)
430+
export_label = ctk.CTkLabel(export_frame, text="Export data", font=(font_family, font_size), text_color=(light_font_color, font_color))
431+
export_label.place(anchor="nw", relx=0.05, rely=0.05)
432+
export_button = ctk.CTkButton(export_frame, text="Export", font=(font_family, font_size), text_color=button_font_color, fg_color=button_color,
433+
hover_color=button_highlight_color, height=button_height, command=self.export_data)
434+
export_button.place(anchor="s", relx=0.5, rely=0.9)
435+
436+
437+
def export_data(self):
438+
self.data_manager.export_data()
439+
440+
426441
def _subject_gui_setup(self) -> None:
427442
subject_frame = ctk.CTkFrame(self.subject_autobreak_frame, fg_color=(light_frame_color, frame_color), height=175, width=frame_width, corner_radius=10)
428443
subject_frame.pack(padx=frame_padding, pady=frame_padding)
@@ -433,9 +448,9 @@ def _subject_gui_setup(self) -> None:
433448
state="readonly", width=200, height=30, dropdown_font=(font_family, int(font_size*0.75)), border_color=(light_border_frame_color, border_frame_color),
434449
font=(font_family, int(font_size)), fg_color=(light_border_frame_color, border_frame_color), button_color=(light_border_frame_color, border_frame_color))
435450
self.subject_selection.place(anchor="center", relx=0.5, rely=0.45)
436-
subject_button = ctk.CTkButton(subject_frame, text="Save", font=(font_family, font_size), text_color=button_font_color, fg_color=button_color, hover_color=button_highlight_color,
451+
self.subject_button = ctk.CTkButton(subject_frame, text="Save", font=(font_family, font_size), text_color=button_font_color, fg_color=button_color, hover_color=button_highlight_color,
437452
height=button_height, command=self.select_subject)
438-
subject_button.place(anchor="s", relx=0.5, rely=0.9)
453+
self.subject_button.place(anchor="s", relx=0.5, rely=0.9)
439454

440455

441456
def _autobreak_gui_setup(self) -> None:
@@ -486,7 +501,7 @@ def _notes_gui_setup(self) -> None:
486501
new_note_frame.pack(pady=(frame_padding, 0))
487502
new_note_frame.grid_propagate(False)
488503

489-
self.notes_data_frame = ctk.CTkScrollableFrame(self.notes_frame_frame, fg_color="transparent", width=WIDTH, height=520+frame_padding*2, label_anchor="w")
504+
self.notes_data_frame = ctk.CTkScrollableFrame(self.notes_frame_frame, fg_color="transparent", width=WIDTH + frame_padding*4, height=520+frame_padding*2, label_anchor="w")
490505
self.notes_data_frame.pack()
491506

492507
new_note_button = ctk.CTkButton(new_note_frame, text="New note", font=(font_family, font_size), text_color=button_font_color, fg_color=button_color, hover_color=button_highlight_color,
@@ -781,6 +796,8 @@ def save_data(self) -> None:
781796
self.duration_input.delete("end")
782797
self.autobreak_button.configure(state="normal", fg_color=button_color)
783798
self.break_button.configure(state="normal", fg_color=button_color, command=lambda: self.timer_manager.break_mechanism(self.break_button, self.timer_button, self.break_display_label), hover=True)
799+
self.subject_button.configure(state="normal", fg_color=button_color)
800+
self.goal_button.configure(state="normal", fg_color=button_color)
784801

785802
if time_in_minutes >= self.goal:
786803
self.data_manager.increase_goal_streak()
@@ -847,7 +864,7 @@ def eye_protection(self):
847864
if self.eye_care_selection.get() == "On":
848865
if checkbox == "On" and self.timer_manager.timer_running:
849866
self.send_notification("Eye Protection", "It's time for a 20/20/20 break! Look away for 20 seconds at something 20 feet away.")
850-
elif checkbox == "Off":
867+
else:
851868
self.send_notification("Eye Protection", "It's time for a 20/20/20 break! Look away for 20 seconds at something 20 feet away.")
852869

853870
# Schedule the next iteration
@@ -966,6 +983,19 @@ def _get_widgets(frame):
966983
self.widget_list.append(widget)
967984

968985

986+
def lock_widgets(self):
987+
self.frequency_input.configure(state="disabled")
988+
self.frequency_input.insert("end", self.data_manager.autobreak_frequency)
989+
self.duration_input.configure(state="disabled")
990+
self.duration_input.insert("end", self.data_manager.autobreak_duration)
991+
992+
self.autobreak_button.configure(state="disabled", fg_color="grey")
993+
self.subject_button.configure(state="disabled", fg_color="grey")
994+
self.goal_button.configure(state="disabled", fg_color="grey")
995+
if self.autobreak_switch.get() == "On":
996+
self.break_button.configure(state="disabled", fg_color = "grey", command=None, hover=False)
997+
998+
969999
def save_on_quit(self) -> None:
9701000
self.save_data()
9711001
print("Data saved on exit.")

0 commit comments

Comments
 (0)