Refactor: Streamline MenuBar arguments and remove redundancy

- Replaced 'app_config' with 'app_version' to directly pass the application version,
  removing the need for 'app_config' as a whole.
- Reverted 'tooltips' argument and instead use 'msg_config' directly,
  aligning with existing project structure where 'Msg' class encapsulates
  both general strings (STR) and tooltips (TTIP).
- Updated all internal references to use 'self.app_version' and 'self.msg_config.TTIP'.
- This refactoring reduces argument redundancy and improves consistency with
  the project's configuration management.
This commit is contained in:
2025-08-13 18:31:17 +02:00
parent 3cf91ba58f
commit fb794538d8

View File

@@ -29,12 +29,11 @@ class MenuBar(ttk.Frame):
tooltip_state: 'BooleanVar',
on_theme_toggle: 'Callable[[], None]',
toggle_log_window: 'Callable[[], None]',
app_config: 'Any', # Should have .UPDATE_URL and .VERSION attributes
msg_config: 'Any', # Should have .STR and .TTIP dictionaries
app_version: str, # Replaces app_config.VERSION
msg_config: 'Any', # Contains .STR and .TTIP
about_icon_path: str,
about_url: str,
gitea_api_url: str, # New: Gitea API URL for update checks
tooltips: dict[str, str], # New: Dictionary of tooltips
gitea_api_url: str,
**kwargs: 'Any',
) -> None:
"""
@@ -46,24 +45,22 @@ class MenuBar(ttk.Frame):
tooltip_state: A tkinter BooleanVar to control tooltip visibility.
on_theme_toggle: Callback function to toggle the application's theme.
toggle_log_window: Callback function to show/hide the log window.
app_config: Project-specific config. Must have UPDATE_URL and VERSION.
app_version: The current version string of the application.
msg_config: Project-specific messages. Must have STR and TTIP dicts.
about_icon_path: Filesystem path to the icon for the 'About' dialog.
about_url: URL for the project's repository or website.
gitea_api_url: The Gitea API URL for update checks.
tooltips: A dictionary containing tooltip messages.
**kwargs: Additional keyword arguments for the ttk.Frame.
"""
super().__init__(container, **kwargs)
self.image_manager = image_manager
self.tooltip_state = tooltip_state
self.on_theme_toggle_callback = on_theme_toggle
self.app_config = app_config
self.msg_config = msg_config
self.app_version = app_version # Store the application version
self.msg_config = msg_config # Store the messages and tooltips object
self.about_icon_path = about_icon_path
self.about_url = about_url
self.gitea_api_url = gitea_api_url # Store the Gitea API URL
self.tooltips = tooltips # Store the tooltips dictionary
self.gitea_api_url = gitea_api_url
self.update_status: str = ""
# --- Horizontal button frame for settings ---
@@ -76,7 +73,7 @@ class MenuBar(ttk.Frame):
)
self.theme_btn.grid(column=0, row=0, padx=(0, 2))
self.update_theme_icon()
Tooltip(self.theme_btn, self.tooltips["theme_toggle"],
Tooltip(self.theme_btn, self.msg_config.TTIP["theme_toggle"],
state_var=self.tooltip_state)
# --- Tooltip Button ---
@@ -85,7 +82,7 @@ class MenuBar(ttk.Frame):
)
self.tooltip_btn.grid(column=1, row=0, padx=(0, 2))
self.update_tooltip_icon()
Tooltip(self.tooltip_btn, self.tooltips["tooltips_toggle"],
Tooltip(self.tooltip_btn, self.msg_config.TTIP["tooltips_toggle"],
state_var=self.tooltip_state)
# --- Update Button ---
@@ -96,7 +93,7 @@ class MenuBar(ttk.Frame):
)
self.update_btn.grid(column=2, row=0)
self.update_update_icon()
Tooltip(self.update_btn, self.tooltips["updates_toggle"],
Tooltip(self.update_btn, self.msg_config.TTIP["updates_toggle"],
state_var=self.tooltip_state)
# --- Animated Icon for Updates ---
@@ -128,7 +125,7 @@ class MenuBar(ttk.Frame):
command=toggle_log_window,
)
self.log_btn.grid(column=2, row=0, sticky="e")
Tooltip(self.log_btn, self.tooltips["show_log"], state_var=self.tooltip_state)
Tooltip(self.log_btn, self.msg_config.TTIP["show_log"], state_var=self.tooltip_state)
# --- About Button ---
self.about_btn = ttk.Button(
@@ -139,7 +136,7 @@ class MenuBar(ttk.Frame):
)
self.about_btn.grid(column=3, row=0)
Tooltip(self.about_btn,
self.tooltips["about_app"], state_var=self.tooltip_state)
self.msg_config.TTIP["about_app"], state_var=self.tooltip_state)
# --- Start background update check ---
self.update_thread = threading.Thread(
@@ -201,7 +198,7 @@ class MenuBar(ttk.Frame):
# Use the GiteaUpdater to check for updates
new_version = GiteaUpdater.check_for_update(
self.gitea_api_url,
self.app_config.VERSION,
self.app_version,
)
# Pass the result (new_version string or None) to update_ui_for_update
self.after(0, self.update_ui_for_update, new_version)
@@ -227,16 +224,16 @@ class MenuBar(ttk.Frame):
tooltip_msg = ""
if new_version == "DISABLED":
tooltip_msg = self.tooltips["updates_disabled"]
tooltip_msg = self.msg_config.TTIP["updates_disabled"]
self.animated_icon.stop()
elif new_version == "ERROR":
tooltip_msg = self.tooltips["no_server_conn_tt"]
tooltip_msg = self.msg_config.TTIP["no_server_conn_tt"]
self.animated_icon.stop(status="DISABLE")
elif new_version is None:
tooltip_msg = self.tooltips["up_to_date"]
tooltip_msg = self.msg_config.TTIP["up_to_date"]
self.animated_icon.stop()
else: # A new version string is returned, meaning an update is available
tooltip_msg = self.tooltips["install_new_version"].format(version=new_version)
tooltip_msg = self.msg_config.TTIP["install_new_version"].format(version=new_version)
self.animated_icon.start()
Tooltip(self.update_btn, tooltip_msg, state_var=self.tooltip_state)