animation for updater and update notify works

This commit is contained in:
2025-08-10 22:48:26 +02:00
parent 1b4d4ad815
commit 65271a50d7
4 changed files with 69 additions and 58 deletions

View File

@@ -78,7 +78,7 @@ class MainFrame(ttk.Frame):
ThemeManager.change_theme(self, new_theme, new_theme) ThemeManager.change_theme(self, new_theme, new_theme)
self.header.header_label.config(fg="#ffffff") self.header.header_label.config(fg="#ffffff")
self.tunnel_details.color_label() self.tunnel_details.color_label()
self.menu_bar.update_theme_label() self.menu_bar.update_theme()
self.menu_bar.settings.entryconfigure( self.menu_bar.settings.entryconfigure(
2, label=self.menu_bar.theme_label.get()) 2, label=self.menu_bar.theme_label.get())

View File

@@ -11,6 +11,7 @@ from logger import app_logger
from shared_libs.common_tools import ConfigManager, Tooltip from shared_libs.common_tools import ConfigManager, Tooltip
from shared_libs.gitea import GiteaUpdate from shared_libs.gitea import GiteaUpdate
from shared_libs.animated_icon import AnimatedIcon, PIL_AVAILABLE
from shared_libs.message import MessageDialog from shared_libs.message import MessageDialog
from shared_libs.wp_app_config import AppConfig, Msg 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 = ttk.Menubutton(self, text=Msg.STR["options"])
self.options_btn.grid(column=0, row=0) 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.set_update = tk.IntVar()
self.settings = tk.Menu(self, relief="flat") self.settings = tk.Menu(self, relief="flat")
@@ -35,16 +37,26 @@ class MenuBar(ttk.Frame):
command=lambda: self.update_setting(self.set_update.get()), command=lambda: self.update_setting(self.set_update.get()),
variable=self.set_update, variable=self.set_update,
) )
self.update_label = tk.StringVar() self.update_label = tk.StringVar()
self.updates_lb = ttk.Label(self, textvariable=self.update_label) self.update_label_widget = ttk.Label(self, textvariable=self.update_label)
self.updates_lb.grid(column=2, row=0) self.update_label_widget.grid(column=4, row=0, padx=10)
self.updates_lb.grid_remove()
self.update_tooltip = tk.StringVar() self.animated_icon_frame = ttk.Frame(self)
self.update_foreground = tk.StringVar(value="red") self.animated_icon_frame.grid(column=5, row=0, padx=10)
self.update_label.trace_add("write", self.update_label_display)
self.update_foreground.trace_add("write", self.update_label_display) 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("<Button-1>", lambda e: self.updater())
self.animated_icon.bind("<Button-1>", lambda e: self.updater())
res = GiteaUpdate.api_down( 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) self.update_ui_for_update(res)
@@ -67,7 +79,8 @@ class MenuBar(ttk.Frame):
) )
self.about_btn.grid(column=1, row=0) 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.log_btn = ttk.Button(
self, self,
@@ -78,53 +91,46 @@ class MenuBar(ttk.Frame):
self.log_btn.grid(column=11, row=0, sticky='e') self.log_btn.grid(column=11, row=0, sticky='e')
Tooltip(self.log_btn, "Show Log", state_var=self.tooltip_state) Tooltip(self.log_btn, "Show Log", state_var=self.tooltip_state)
def update_label_display(self, *args): def update_ui_for_update(self, res):
self.updates_lb.configure(foreground=self.update_foreground.get()) self.animated_icon_frame.grid_remove()
if self.update_label.get(): self.animated_icon.hide()
self.updates_lb.grid(column=4, columnspan=3, row=0, padx=10) 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: 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): def updater(self):
tmp_dir = Path("/tmp/lxtools") tmp_dir = Path("/tmp/lxtools")
Path.mkdir(tmp_dir, exist_ok=True) Path.mkdir(tmp_dir, exist_ok=True)
os.chdir(tmp_dir) 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: if result.returncode != 0:
MessageDialog("error", result.stderr) 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 @staticmethod
def about() -> None: def about() -> None:
MessageDialog( MessageDialog(
@@ -147,11 +153,8 @@ class MenuBar(ttk.Frame):
else: else:
ConfigManager.set("updates", "on") ConfigManager.set("updates", "on")
try: try:
res = GiteaUpdate.api_down(AppConfig.UPDATE_URL, AppConfig.VERSION, "on") res = GiteaUpdate.api_down(
if hasattr(self, "update_btn"): AppConfig.UPDATE_URL, AppConfig.VERSION, "on")
self.update_btn.grid_forget()
if hasattr(self, "updates_lb"):
self.updates_lb.grid_forget()
self.update_ui_for_update(res) self.update_ui_for_update(res)
except Exception as e: except Exception as e:
app_logger.log(f"Error checking for updates: {e}") app_logger.log(f"Error checking for updates: {e}")
@@ -177,3 +180,11 @@ class MenuBar(ttk.Frame):
else: else:
self.theme_label.set(Msg.STR["light"]) 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)

View File

@@ -37,7 +37,6 @@ class Wirepy(tk.Tk):
self.y_height = AppConfig.UI_CONFIG["window_size"][1] self.y_height = AppConfig.UI_CONFIG["window_size"][1]
# Set the window size # 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.geometry(f"{self.x_width}x{self.y_height}")
self.resizable( self.resizable(
AppConfig.UI_CONFIG["resizable_window"][0], AppConfig.UI_CONFIG["resizable_window"][0],

View File

@@ -236,4 +236,5 @@ class Msg:
"no_server_conn_tt": _("Could not connect to update server"), "no_server_conn_tt": _("Could not connect to update server"),
"up_to_date": _("Congratulations! Wire-Py is up to date"), "up_to_date": _("Congratulations! Wire-Py is up to date"),
"install_new_version": _("Click to install new version"), "install_new_version": _("Click to install new version"),
"no_pillow": "Pillow library is not installed.\nInstall it for a better icon experience.",
} }