optimize performance 06-05-2025-23:00

This commit is contained in:
2025-05-07 08:14:46 +02:00
parent dba6138aa7
commit 9a4d8b3506
4 changed files with 146 additions and 122 deletions

140
wirepy.py
View File

@ -29,17 +29,22 @@ class Wirepy(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Hide the window initially
self.withdraw()
self.my_tool_tip = None
self.x_width = AppConfig.UI_CONFIG["window_size"][0]
self.y_height = AppConfig.UI_CONFIG["window_size"][1]
self.monitor_center_x = int(self.winfo_screenwidth() / 2 - (self.x_width / 2))
self.monitor_center_y = int(self.winfo_screenheight() / 2 - (self.y_height / 2))
self.resizable(AppConfig.UI_CONFIG["resizable_window"][0], AppConfig.UI_CONFIG["resizable_window"][1])
# Set the window size
self.geometry(f"{self.x_width}x{self.y_height}")
self.resizable(AppConfig.UI_CONFIG["resizable_window"][0],
AppConfig.UI_CONFIG["resizable_window"][1])
self.title(AppConfig.UI_CONFIG["window_title"])
self.geometry(f"{self.x_width}x{self.y_height}+{self.monitor_center_x}+{self.monitor_center_y}")
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.tk.call("source", f"{AppConfig.SYSTEM_PATHS["tcl_path"]}/water.tcl")
self.tk.call("source", f"{AppConfig.SYSTEM_PATHS['tcl_path']}/water.tcl")
ConfigManager.init(AppConfig.SETTINGS_FILE)
theme = ConfigManager.get("theme")
ThemeManager.change_theme(self, theme)
@ -50,7 +55,14 @@ class Wirepy(tk.Tk):
# Set it as the window icon
self.iconphoto(True, self.wg_icon)
# Add the widgets
FrameWidgets(self).grid()
# Center the window on the primary monitor
LxTools.center_window_cross_platform(self, self.x_width, self.y_height)
# Now show the window after it has been positioned
self.after(10, self.deiconify)
class FrameWidgets(ttk.Frame):
@ -362,18 +374,7 @@ class FrameWidgets(ttk.Frame):
AppConfig.IMAGE_PATHS["icon_error"],
AppConfig.IMAGE_PATHS["icon_msg"]
)
)
def tooltip(self, tip) -> None:
"""
Aktualisiert die Tooltip-Einstellung im ConfigManager
Args:
tip (bool): True zum Deaktivieren, False zum Aktivieren von Tooltips
"""
# Beachten Sie die umgekehrte Logik: tip=True bedeutet Tooltips deaktivieren
ConfigManager.set("tooltip", not tip)
# Aktualisieren Sie die lokale Variable für sofortige Wirkung
self.tooltip_state = not tip
)
@staticmethod
def about() -> None:
@ -389,107 +390,6 @@ class FrameWidgets(ttk.Frame):
"Use without warranty!\n")
LxTools.msg_window(AppConfig.IMAGE_PATHS["icon_vpn"], AppConfig.IMAGE_PATHS["icon_vpn"], _("Info"), msg_t, _("Go to Wire-Py git"), link_btn)
def update_ui_for_update_status(self, res):
"""Update UI elements based on update check result"""
print(f"Updating UI for result: {res}") # Debug output
# First, clean up any existing UI elements
if hasattr(self, 'update_btn') and self.update_btn.winfo_exists():
self.update_btn.grid_forget()
# Reset all variables to ensure fresh state
self.update_label.set("")
self.update_tooltip.set("")
self.update_foreground.set("black")
if res == "False":
self.set_update.set(value=1)
self.update_label.set(_("Update search off"))
self.update_tooltip.set(_("Updates you have disabled"))
self.update_foreground.set("red")
# Display the label
self.updates_lb.configure(
textvariable=self.update_label,
foreground=self.update_foreground.get()
)
self.updates_lb.grid(column=4, columnspan=3, row=0, padx=10)
Tooltip(self.updates_lb, self.update_tooltip.get(), self.tooltip_state)
elif res == "No Internet Connection!":
self.update_label.set(_("No Server Connection!"))
self.update_foreground.set("red")
# Display the label
self.updates_lb.configure(
textvariable=self.update_label,
foreground=self.update_foreground.get()
)
self.updates_lb.grid(column=4, columnspan=3, row=0, padx=10)
elif res == "No Updates":
self.update_label.set(_("No Updates"))
self.update_tooltip.set(_("Congratulations! Wire-Py is up to date"))
self.update_foreground.set("black")
# Display the label
self.updates_lb.configure(
textvariable=self.update_label,
foreground=self.update_foreground.get()
)
self.updates_lb.grid(column=4, columnspan=3, row=0, padx=10)
Tooltip(self.updates_lb, self.update_tooltip.get(), self.tooltip_state)
else:
# We have an update available
self.set_update.set(value=0)
update_text = f"Update {res} {_('available!')}"
# Hide the label if it's visible
if self.updates_lb.winfo_ismapped():
self.updates_lb.grid_forget()
# Create or update the update button
if not hasattr(self, 'update_btn') or not self.update_btn.winfo_exists():
# Create the update button if it doesn't exist yet
self.update_btn = ttk.Menubutton(self.menu_frame, text=update_text)
self.update_btn.grid(column=4, columnspan=3, row=0, padx=0)
Tooltip(self.update_btn, _("Click to download new version"), self.tooltip_state)
self.download = tk.Menu(self, relief="flat")
self.update_btn.configure(menu=self.download, style="Toolbutton")
self.download.add_command(
label=_("Download"),
command=lambda: GiteaUpdate.download(
f"{AppConfig.DOWNLOAD_URL}/{res}.zip",
res,
AppConfig.IMAGE_PATHS["icon_info"],
AppConfig.IMAGE_PATHS["icon_vpn"],
AppConfig.IMAGE_PATHS["icon_error"],
AppConfig.IMAGE_PATHS["icon_msg"]
)
)
else:
# Update the existing update button
self.update_btn.configure(text=update_text)
# Make sure it's visible
self.update_btn.grid(column=4, columnspan=3, row=0, padx=0)
# Update the download command
if hasattr(self, 'download'):
self.download.entryconfigure(
0, # First entry in the menu
command=lambda: GiteaUpdate.download(
f"{AppConfig.DOWNLOAD_URL}/{res}.zip",
res,
AppConfig.IMAGE_PATHS["icon_info"],
AppConfig.IMAGE_PATHS["icon_vpn"],
AppConfig.IMAGE_PATHS["icon_error"],
AppConfig.IMAGE_PATHS["icon_msg"]
)
)
def update_setting(self, update_res) -> None:
"""write off or on in file
Args:
@ -532,15 +432,12 @@ class FrameWidgets(ttk.Frame):
# If tooltips are disabled, the menu option should be to enable them
self.tooltip_label.set(_("Enable Tooltips"))
def tooltips_toggle(self):
"""Toggles tooltips on/off and updates the menu label"""
# Toggle the boolean state
new_bool_state = not self.tooltip_state.get()
# Save the converted value in the configuration
ConfigManager.set("tooltips", str(new_bool_state))
print(f"Tooltips are now: {new_bool_state} in ConfigManager")
# Update the tooltip_state variable for immediate effect
self.tooltip_state.set(new_bool_state)
@ -551,7 +448,6 @@ class FrameWidgets(ttk.Frame):
# This assumes it's the third item (index 2) in your menu
self.settings.entryconfigure(1, label=self.tooltip_label.get())
def update_theme_label(self) -> str:
"""Update the theme label based on current theme"""
current_theme = ConfigManager.get("theme")