From 65271a50d7d2ec611a7c3f81adf665337f0fee33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A9sir=C3=A9=20Werner=20Menrath?= Date: Sun, 10 Aug 2025 22:48:26 +0200 Subject: [PATCH] animation for updater and update notify works --- ui/main_frame.py | 2 +- ui/menu_bar.py | 119 ++++++++++++++++++++++++++--------------------- wirepy.py | 5 +- wp_app_config.py | 1 + 4 files changed, 69 insertions(+), 58 deletions(-) diff --git a/ui/main_frame.py b/ui/main_frame.py index fd23846..ff4033b 100644 --- a/ui/main_frame.py +++ b/ui/main_frame.py @@ -78,7 +78,7 @@ class MainFrame(ttk.Frame): ThemeManager.change_theme(self, new_theme, new_theme) self.header.header_label.config(fg="#ffffff") self.tunnel_details.color_label() - self.menu_bar.update_theme_label() + self.menu_bar.update_theme() self.menu_bar.settings.entryconfigure( 2, label=self.menu_bar.theme_label.get()) diff --git a/ui/menu_bar.py b/ui/menu_bar.py index 94bfd48..6b6ee2c 100644 --- a/ui/menu_bar.py +++ b/ui/menu_bar.py @@ -11,6 +11,7 @@ from logger import app_logger from shared_libs.common_tools import ConfigManager, Tooltip from shared_libs.gitea import GiteaUpdate +from shared_libs.animated_icon import AnimatedIcon, PIL_AVAILABLE from shared_libs.message import MessageDialog from shared_libs.wp_app_config import AppConfig, Msg @@ -25,7 +26,8 @@ class MenuBar(ttk.Frame): self.options_btn = ttk.Menubutton(self, text=Msg.STR["options"]) self.options_btn.grid(column=0, row=0) - Tooltip(self.options_btn, Msg.TTIP["settings"], state_var=self.tooltip_state) + Tooltip(self.options_btn, + Msg.TTIP["settings"], state_var=self.tooltip_state) self.set_update = tk.IntVar() self.settings = tk.Menu(self, relief="flat") @@ -35,16 +37,26 @@ class MenuBar(ttk.Frame): command=lambda: self.update_setting(self.set_update.get()), variable=self.set_update, ) + self.update_label = tk.StringVar() - self.updates_lb = ttk.Label(self, textvariable=self.update_label) - self.updates_lb.grid(column=2, row=0) - self.updates_lb.grid_remove() - self.update_tooltip = tk.StringVar() - self.update_foreground = tk.StringVar(value="red") - self.update_label.trace_add("write", self.update_label_display) - self.update_foreground.trace_add("write", self.update_label_display) + self.update_label_widget = ttk.Label(self, textvariable=self.update_label) + self.update_label_widget.grid(column=4, row=0, padx=10) + + self.animated_icon_frame = ttk.Frame(self) + self.animated_icon_frame.grid(column=5, row=0, padx=10) + + current_theme = ConfigManager.get("theme") + bg_color = "#ffffff" if current_theme == "light" else "#333333" + + self.animated_icon = AnimatedIcon( + self.animated_icon_frame, animation_type="blink", use_pillow=PIL_AVAILABLE, bg=bg_color) + self.animated_icon.pack() + self.animated_icon_frame.bind("", lambda e: self.updater()) + self.animated_icon.bind("", lambda e: self.updater()) + res = GiteaUpdate.api_down( - AppConfig.UPDATE_URL, AppConfig.VERSION, ConfigManager.get("updates") + AppConfig.UPDATE_URL, AppConfig.VERSION, ConfigManager.get( + "updates") ) self.update_ui_for_update(res) @@ -60,14 +72,15 @@ class MenuBar(ttk.Frame): self.settings.add_command( label=self.theme_label.get(), command=self.on_theme_toggle ) - + # About BTN Menu / Label self.about_btn = ttk.Button( self, text=Msg.STR["about"], style="Toolbutton", command=self.about ) self.about_btn.grid(column=1, row=0) - self.columnconfigure(10, weight=1) # Add a column with weight to push button to the right + # Add a column with weight to push button to the right + self.columnconfigure(10, weight=1) self.log_btn = ttk.Button( self, @@ -78,53 +91,46 @@ class MenuBar(ttk.Frame): self.log_btn.grid(column=11, row=0, sticky='e') Tooltip(self.log_btn, "Show Log", state_var=self.tooltip_state) - def update_label_display(self, *args): - self.updates_lb.configure(foreground=self.update_foreground.get()) - if self.update_label.get(): - self.updates_lb.grid(column=4, columnspan=3, row=0, padx=10) + def update_ui_for_update(self, res): + self.animated_icon_frame.grid_remove() + self.animated_icon.hide() + self.update_label.set("") + + tooltip_msg = "" + if res == "False": + self.set_update.set(value=1) + self.update_label.set(Msg.STR["update_search_off"]) + self.update_label_widget.configure(foreground="") + tooltip_msg = Msg.TTIP["updates_disabled"] + elif res == "No Internet Connection!": + self.update_label.set(Msg.STR["no_server_connection"]) + self.update_label_widget.configure(foreground="red") + tooltip_msg = Msg.TTIP["no_server_conn_tt"] + elif res == "No Updates": + self.animated_icon_frame.grid() + self.animated_icon.stop() + tooltip_msg = Msg.TTIP["up_to_date"] else: - self.updates_lb.grid_remove() + self.set_update.set(value=0) + self.animated_icon_frame.grid() + self.animated_icon.start() + tooltip_msg = Msg.TTIP["install_new_version"] + + if not PIL_AVAILABLE: + tooltip_msg += f"\n\n{Msg.TTIP['no_pillow']}" + + Tooltip(self.animated_icon_frame, tooltip_msg, + state_var=self.tooltip_state) def updater(self): tmp_dir = Path("/tmp/lxtools") Path.mkdir(tmp_dir, exist_ok=True) os.chdir(tmp_dir) - result = subprocess.run(["/usr/local/bin/lxtools_installer"], check=False) + result = subprocess.run( + ["/usr/local/bin/lxtools_installer"], check=False) if result.returncode != 0: MessageDialog("error", result.stderr) - def update_ui_for_update(self, res): - if hasattr(self, "update_btn"): - self.update_btn.grid_forget() - delattr(self, "update_btn") - - if res == "False": - self.set_update.set(value=1) - self.update_label.set(Msg.STR["update_search_off"]) - self.update_tooltip.set(Msg.TTIP["updates_disabled"]) - self.update_foreground.set("") - Tooltip(self.updates_lb, self.update_tooltip.get(), state_var=self.tooltip_state) - elif res == "No Internet Connection!": - self.update_label.set(Msg.STR["no_server_connection"]) - self.update_foreground.set("red") - Tooltip(self.updates_lb, Msg.TTIP["no_server_conn_tt"], state_var=self.tooltip_state) - elif res == "No Updates": - self.update_label.set(Msg.STR["no_updates"]) - self.update_tooltip.set(Msg.TTIP["up_to_date"]) - self.update_foreground.set("") - Tooltip(self.updates_lb, self.update_tooltip.get(), state_var=self.tooltip_state) - else: - self.set_update.set(value=0) - self.update_label.set("") - self.update_btn = ttk.Button( - self, - image=self.image_manager.get_icon("settings"), - style="Toolbutton", - command=self.updater, - ) - self.update_btn.grid(column=5, row=0, padx=0) - Tooltip(self.update_btn, Msg.TTIP["install_new_version"], state_var=self.tooltip_state) - @staticmethod def about() -> None: MessageDialog( @@ -147,11 +153,8 @@ class MenuBar(ttk.Frame): else: ConfigManager.set("updates", "on") try: - res = GiteaUpdate.api_down(AppConfig.UPDATE_URL, AppConfig.VERSION, "on") - if hasattr(self, "update_btn"): - self.update_btn.grid_forget() - if hasattr(self, "updates_lb"): - self.updates_lb.grid_forget() + res = GiteaUpdate.api_down( + AppConfig.UPDATE_URL, AppConfig.VERSION, "on") self.update_ui_for_update(res) except Exception as e: app_logger.log(f"Error checking for updates: {e}") @@ -177,3 +180,11 @@ class MenuBar(ttk.Frame): else: self.theme_label.set(Msg.STR["light"]) + def update_theme(self): + self.update_theme_label() + self.after(100, self._update_bg) + + def _update_bg(self): + current_theme = ConfigManager.get("theme") + bg_color = "#ffffff" if current_theme == "light" else "#333333" + self.animated_icon.configure(bg=bg_color) diff --git a/wirepy.py b/wirepy.py index 82bf222..48cd9e2 100755 --- a/wirepy.py +++ b/wirepy.py @@ -37,7 +37,6 @@ class Wirepy(tk.Tk): self.y_height = AppConfig.UI_CONFIG["window_size"][1] # Set the window size - print(f"Setting window size to: {self.x_width}x{self.y_height}") self.geometry(f"{self.x_width}x{self.y_height}") self.resizable( AppConfig.UI_CONFIG["resizable_window"][0], @@ -90,7 +89,7 @@ if __name__ == "__main__": LxTools.sigi(AppConfig.TEMP_DIR) CryptoUtil.decrypt(getpass.getuser()) window = Wirepy() - + """ the hidden files are hidden in Filedialog """ @@ -103,4 +102,4 @@ if __name__ == "__main__": window.mainloop() LxTools.clean_files(AppConfig.TEMP_DIR) - sys.exit(0) \ No newline at end of file + sys.exit(0) diff --git a/wp_app_config.py b/wp_app_config.py index 2ae1f98..d838e21 100755 --- a/wp_app_config.py +++ b/wp_app_config.py @@ -236,4 +236,5 @@ class Msg: "no_server_conn_tt": _("Could not connect to update server"), "up_to_date": _("Congratulations! Wire-Py is up to date"), "install_new_version": _("Click to install new version"), + "no_pillow": "Pillow library is not installed.\nInstall it for a better icon experience.", }