diff --git a/time_tracker.py b/time_tracker.py index 7ff0afb..bd82aee 100644 --- a/time_tracker.py +++ b/time_tracker.py @@ -1,10 +1,6 @@ #!/usr/bin/env python3 -#TODO: -# - alternating colors for each hour -# - more compact user interface -# - button to open the archive csv in text editor (vim) -# - make sure it runs on windows + import tkinter as tk from tkinter import ttk, messagebox, filedialog @@ -24,14 +20,26 @@ drag_info = { } class ClickableCell(tk.Frame): - def __init__(self, parent, row_col_key, callback, width=5, height=2): + def __init__(self, parent, row_col_key, callback, width=5, height=2, start_hour=9): super().__init__(parent, relief="solid", borderwidth=1, width=width, height=height) self.row_col_key = row_col_key self.callback = callback self.checked = False - - # Create label - self.label = tk.Label(self, text=" ", bg="white", width=width, height=height) + self.start_hour = start_hour + + # Calculate which hour this cell represents based on column index + col_idx = row_col_key[1] + hour_offset = col_idx // 4 # 4 cells per hour (15-minute intervals) + current_hour = start_hour + hour_offset + + # Determine background color based on hour (alternating pattern) + if current_hour % 2 == 0: + self.default_bg = "#e8e8e8" # Medium gray for even hours + else: + self.default_bg = "#f5f5f5" # Light gray for odd hours + + # Create label with hour-based background + self.label = tk.Label(self, text=" ", bg=self.default_bg, width=width, height=height) self.label.pack(fill="both", expand=True) # Bind only click events for now @@ -51,7 +59,7 @@ class ClickableCell(tk.Frame): if self.checked: self.label.config(bg="lightblue", text="✓") else: - self.label.config(bg="white", text=" ") + self.label.config(bg=self.default_bg, text=" ") self.callback(self.row_col_key, self.checked) drag_info['last_cell'] = self.row_col_key @@ -68,7 +76,7 @@ class ClickableCell(tk.Frame): return True elif mode == 'erase' and self.checked: self.checked = False - self.label.config(bg="white", text=" ") + self.label.config(bg=self.default_bg, text=" ") self.callback(self.row_col_key, False) return True return False @@ -78,7 +86,7 @@ class ClickableCell(tk.Frame): if checked: self.label.config(bg="lightblue", text="✓") else: - self.label.config(bg="white", text=" ") + self.label.config(bg=self.default_bg, text=" ") class TimeTracker: def __init__(self, root): @@ -388,7 +396,7 @@ class TimeTracker: self.time_cells[row_num] = {} time_slots = self.work_hours * 4 # Calculate based on current settings for i in range(time_slots): - cell = ClickableCell(self.scrollable_frame, (row_num, i), self.on_time_cell_clicked, width=5, height=1) + cell = ClickableCell(self.scrollable_frame, (row_num, i), self.on_time_cell_clicked, width=5, height=1, start_hour=self.start_hour) cell.grid(row=row_num, column=4 + i, sticky="nsew", padx=1, pady=1) self.time_cells[row_num][i] = cell @@ -469,7 +477,7 @@ class TimeTracker: if cell.checked: cell.label.config(bg="lightblue", text="✓") else: - cell.label.config(bg="white", text=" ") + cell.label.config(bg=cell.default_bg, text=" ") self.update_total_hours(row_num) self.update_day_total()