feat: enhance menu theming with comprehensive documentation and testing support
Build and Push Docker Image / build-and-push (push) Has been cancelled
Build and Push Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
+5
-5
@@ -178,11 +178,11 @@ class MedTrackerApp:
|
||||
|
||||
def _setup_menu(self) -> None:
|
||||
"""Set up the menu bar."""
|
||||
menubar = tk.Menu(self.root)
|
||||
menubar = self.theme_manager.create_themed_menu(self.root)
|
||||
self.root.config(menu=menubar)
|
||||
|
||||
# File menu
|
||||
file_menu = tk.Menu(menubar, tearoff=0)
|
||||
file_menu = self.theme_manager.create_themed_menu(menubar, tearoff=0)
|
||||
menubar.add_cascade(label="File", menu=file_menu)
|
||||
file_menu.add_command(
|
||||
label="Export Data...",
|
||||
@@ -195,7 +195,7 @@ class MedTrackerApp:
|
||||
)
|
||||
|
||||
# Tools menu
|
||||
tools_menu = tk.Menu(menubar, tearoff=0)
|
||||
tools_menu = self.theme_manager.create_themed_menu(menubar, tearoff=0)
|
||||
menubar.add_cascade(label="Tools", menu=tools_menu)
|
||||
tools_menu.add_command(
|
||||
label="Manage Pathologies...",
|
||||
@@ -216,7 +216,7 @@ class MedTrackerApp:
|
||||
)
|
||||
|
||||
# Theme menu
|
||||
theme_menu = tk.Menu(menubar, tearoff=0)
|
||||
theme_menu = self.theme_manager.create_themed_menu(menubar, tearoff=0)
|
||||
menubar.add_cascade(label="Theme", menu=theme_menu)
|
||||
|
||||
# Add quick theme options
|
||||
@@ -237,7 +237,7 @@ class MedTrackerApp:
|
||||
)
|
||||
|
||||
# Help menu
|
||||
help_menu = tk.Menu(menubar, tearoff=0)
|
||||
help_menu = self.theme_manager.create_themed_menu(menubar, tearoff=0)
|
||||
menubar.add_cascade(label="Help", menu=help_menu)
|
||||
help_menu.add_command(
|
||||
label="Settings...",
|
||||
|
||||
@@ -213,6 +213,71 @@ class ThemeManager:
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to configure custom styles: {e}")
|
||||
|
||||
def get_menu_colors(self) -> dict[str, str]:
|
||||
"""Get colors specifically for menu theming."""
|
||||
colors = self.get_theme_colors()
|
||||
|
||||
# Use slightly different colors for menus to make them stand out
|
||||
try:
|
||||
# For menu background, use a slightly darker/lighter shade
|
||||
if colors["bg"].startswith("#"):
|
||||
rgb = tuple(int(colors["bg"][i : i + 2], 16) for i in (1, 3, 5))
|
||||
if sum(rgb) > 384: # Light theme - make menu slightly darker
|
||||
menu_bg = (
|
||||
f"#{max(0, rgb[0] - 8):02x}"
|
||||
f"{max(0, rgb[1] - 8):02x}"
|
||||
f"{max(0, rgb[2] - 8):02x}"
|
||||
)
|
||||
else: # Dark theme - make menu slightly lighter
|
||||
menu_bg = (
|
||||
f"#{min(255, rgb[0] + 15):02x}"
|
||||
f"{min(255, rgb[1] + 15):02x}"
|
||||
f"{min(255, rgb[2] + 15):02x}"
|
||||
)
|
||||
else:
|
||||
menu_bg = colors["bg"]
|
||||
except (ValueError, IndexError):
|
||||
menu_bg = colors["bg"]
|
||||
|
||||
return {
|
||||
"bg": menu_bg,
|
||||
"fg": colors["fg"],
|
||||
"active_bg": colors["select_bg"],
|
||||
"active_fg": colors["select_fg"],
|
||||
"disabled_fg": colors.get("disabled_fg", "#888888"),
|
||||
}
|
||||
|
||||
def configure_menu(self, menu: "tk.Menu") -> None:
|
||||
"""Apply theme colors to a menu widget."""
|
||||
try:
|
||||
menu_colors = self.get_menu_colors()
|
||||
|
||||
menu.configure(
|
||||
background=menu_colors["bg"],
|
||||
foreground=menu_colors["fg"],
|
||||
activebackground=menu_colors["active_bg"],
|
||||
activeforeground=menu_colors["active_fg"],
|
||||
disabledforeground=menu_colors["disabled_fg"],
|
||||
relief="flat",
|
||||
borderwidth=1,
|
||||
)
|
||||
|
||||
self.logger.debug(f"Applied theme to menu: {menu_colors}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to configure menu theme: {e}")
|
||||
|
||||
def create_themed_menu(self, parent: "tk.Widget", **kwargs) -> "tk.Menu":
|
||||
"""Create a new menu with theme colors already applied."""
|
||||
try:
|
||||
menu = tk.Menu(parent, **kwargs)
|
||||
self.configure_menu(menu)
|
||||
return menu
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create themed menu: {e}")
|
||||
# Fallback to regular menu if theming fails
|
||||
return tk.Menu(parent, **kwargs)
|
||||
|
||||
def configure_widget_style(self, widget: tk.Widget, style_name: str) -> None:
|
||||
"""Apply a specific style to a widget."""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user