Added alternating colors on the grid
This commit is contained in:
@@ -1,10 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/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
|
import tkinter as tk
|
||||||
from tkinter import ttk, messagebox, filedialog
|
from tkinter import ttk, messagebox, filedialog
|
||||||
@@ -24,14 +20,26 @@ drag_info = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ClickableCell(tk.Frame):
|
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)
|
super().__init__(parent, relief="solid", borderwidth=1, width=width, height=height)
|
||||||
self.row_col_key = row_col_key
|
self.row_col_key = row_col_key
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.checked = False
|
self.checked = False
|
||||||
|
self.start_hour = start_hour
|
||||||
# Create label
|
|
||||||
self.label = tk.Label(self, text=" ", bg="white", width=width, height=height)
|
# 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)
|
self.label.pack(fill="both", expand=True)
|
||||||
|
|
||||||
# Bind only click events for now
|
# Bind only click events for now
|
||||||
@@ -51,7 +59,7 @@ class ClickableCell(tk.Frame):
|
|||||||
if self.checked:
|
if self.checked:
|
||||||
self.label.config(bg="lightblue", text="✓")
|
self.label.config(bg="lightblue", text="✓")
|
||||||
else:
|
else:
|
||||||
self.label.config(bg="white", text=" ")
|
self.label.config(bg=self.default_bg, text=" ")
|
||||||
self.callback(self.row_col_key, self.checked)
|
self.callback(self.row_col_key, self.checked)
|
||||||
drag_info['last_cell'] = self.row_col_key
|
drag_info['last_cell'] = self.row_col_key
|
||||||
|
|
||||||
@@ -68,7 +76,7 @@ class ClickableCell(tk.Frame):
|
|||||||
return True
|
return True
|
||||||
elif mode == 'erase' and self.checked:
|
elif mode == 'erase' and self.checked:
|
||||||
self.checked = False
|
self.checked = False
|
||||||
self.label.config(bg="white", text=" ")
|
self.label.config(bg=self.default_bg, text=" ")
|
||||||
self.callback(self.row_col_key, False)
|
self.callback(self.row_col_key, False)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@@ -78,7 +86,7 @@ class ClickableCell(tk.Frame):
|
|||||||
if checked:
|
if checked:
|
||||||
self.label.config(bg="lightblue", text="✓")
|
self.label.config(bg="lightblue", text="✓")
|
||||||
else:
|
else:
|
||||||
self.label.config(bg="white", text=" ")
|
self.label.config(bg=self.default_bg, text=" ")
|
||||||
|
|
||||||
class TimeTracker:
|
class TimeTracker:
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
@@ -388,7 +396,7 @@ class TimeTracker:
|
|||||||
self.time_cells[row_num] = {}
|
self.time_cells[row_num] = {}
|
||||||
time_slots = self.work_hours * 4 # Calculate based on current settings
|
time_slots = self.work_hours * 4 # Calculate based on current settings
|
||||||
for i in range(time_slots):
|
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)
|
cell.grid(row=row_num, column=4 + i, sticky="nsew", padx=1, pady=1)
|
||||||
self.time_cells[row_num][i] = cell
|
self.time_cells[row_num][i] = cell
|
||||||
|
|
||||||
@@ -469,7 +477,7 @@ class TimeTracker:
|
|||||||
if cell.checked:
|
if cell.checked:
|
||||||
cell.label.config(bg="lightblue", text="✓")
|
cell.label.config(bg="lightblue", text="✓")
|
||||||
else:
|
else:
|
||||||
cell.label.config(bg="white", text=" ")
|
cell.label.config(bg=cell.default_bg, text=" ")
|
||||||
|
|
||||||
self.update_total_hours(row_num)
|
self.update_total_hours(row_num)
|
||||||
self.update_day_total()
|
self.update_day_total()
|
||||||
|
|||||||
Reference in New Issue
Block a user