- Update button styles in Backup Content and Advanced Settings to match the main application navigation. - Implement a progress bar indicator for the active tab. - Realign buttons in Advanced Settings to the left. - Add a dynamic informational label for the "Manual Excludes" section.
409 lines
18 KiB
Python
409 lines
18 KiB
Python
import tkinter as tk
|
|
from tkinter import ttk
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from pbp_app_config import AppConfig, Msg
|
|
from shared_libs.animated_icon import AnimatedIcon
|
|
from pyimage_ui.shared_logic import enforce_backup_type_exclusivity
|
|
|
|
|
|
class AdvancedSettingsFrame(tk.Toplevel):
|
|
def __init__(self, master, config_manager, app_instance, **kwargs):
|
|
super().__init__(master, **kwargs)
|
|
|
|
self.title(Msg.STR["advanced_settings_title"])
|
|
self.config_manager = config_manager
|
|
self.app_instance = app_instance
|
|
self.current_view_index = 0
|
|
|
|
# --- Warning Label ---
|
|
self.info_label = ttk.Label(
|
|
self, text=Msg.STR["advanced_settings_warning"], wraplength=780, justify="left")
|
|
self.info_label.pack(pady=10, fill=tk.X, padx=10)
|
|
|
|
# --- Navigation ---
|
|
nav_frame = ttk.Frame(self)
|
|
nav_frame.pack(fill=tk.X, padx=10, pady=5)
|
|
|
|
top_nav_frame = ttk.Frame(nav_frame)
|
|
top_nav_frame.pack(side=tk.LEFT)
|
|
|
|
self.nav_buttons_defs = [
|
|
(Msg.STR["system_excludes"], lambda: self._switch_view(0)),
|
|
(Msg.STR["manual_excludes"], lambda: self._switch_view(1)),
|
|
]
|
|
|
|
self.nav_buttons = []
|
|
self.nav_progress_bars = []
|
|
|
|
for i, (text, command) in enumerate(self.nav_buttons_defs):
|
|
button_frame = ttk.Frame(top_nav_frame)
|
|
button_frame.pack(side=tk.LEFT, padx=5)
|
|
button = ttk.Button(button_frame, text=text,
|
|
command=command, style="TButton.Borderless.Round")
|
|
button.pack(side=tk.TOP)
|
|
self.nav_buttons.append(button)
|
|
progress_bar = ttk.Progressbar(
|
|
button_frame, orient="horizontal", length=50, mode="determinate", style="Small.Horizontal.TProgressbar")
|
|
progress_bar.pack_forget()
|
|
self.nav_progress_bars.append(progress_bar)
|
|
|
|
if i < len(self.nav_buttons_defs) - 1:
|
|
ttk.Separator(top_nav_frame, orient=tk.VERTICAL).pack(
|
|
side=tk.LEFT, fill=tk.Y, padx=2)
|
|
|
|
# --- Container for the two views ---
|
|
view_container = ttk.Frame(self)
|
|
view_container.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
|
|
|
|
# --- Treeview for system folder exclusion ---
|
|
self.tree_frame = ttk.LabelFrame(
|
|
view_container, text=Msg.STR["exclude_system_folders"], padding=10)
|
|
|
|
columns = ("included", "name", "path")
|
|
self.tree = ttk.Treeview(
|
|
self.tree_frame, columns=columns, show="headings")
|
|
self.tree.heading("included", text=Msg.STR["in_backup"])
|
|
self.tree.heading("name", text=Msg.STR["name"])
|
|
self.tree.heading("path", text=Msg.STR["path"])
|
|
self.tree.column("path", anchor="center")
|
|
self.tree.column("name", anchor="center")
|
|
self.tree.column("included", width=100, anchor="center")
|
|
self.tree.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
|
|
self.tree.tag_configure("backup_dest_exclude", foreground="gray")
|
|
|
|
self.tree.bind("<Button-1>", self._toggle_include_status)
|
|
|
|
# --- Manual Excludes Frame ---
|
|
self.manual_excludes_frame = ttk.LabelFrame(
|
|
view_container, text=Msg.STR["manual_excludes"], padding=10)
|
|
|
|
self.manual_excludes_listbox = tk.Listbox(
|
|
self.manual_excludes_frame, selectmode=tk.MULTIPLE)
|
|
self.manual_excludes_listbox.pack(
|
|
fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
|
|
delete_button = ttk.Button(
|
|
self.manual_excludes_frame, text=Msg.STR["delete"], command=self._delete_manual_exclude)
|
|
delete_button.pack(pady=5)
|
|
|
|
# --- Animation Settings ---
|
|
animation_frame = ttk.LabelFrame(
|
|
self, text=Msg.STR["animation_settings_title"], padding=10)
|
|
animation_frame.pack(fill=tk.X, padx=10, pady=5)
|
|
|
|
animation_types = ["counter_arc", "double_arc", "line", "blink"]
|
|
|
|
ttk.Label(animation_frame, text=Msg.STR["backup_animation_label"]).grid(
|
|
row=0, column=0, sticky="w", pady=2)
|
|
self.backup_anim_var = tk.StringVar()
|
|
self.backup_anim_combo = ttk.Combobox(
|
|
animation_frame, textvariable=self.backup_anim_var, values=animation_types, state="readonly")
|
|
self.backup_anim_combo.grid(row=0, column=1, sticky="ew", padx=5)
|
|
|
|
ttk.Label(animation_frame, text=Msg.STR["calc_animation_label"]).grid(
|
|
row=1, column=0, sticky="w", pady=2)
|
|
self.calc_anim_var = tk.StringVar()
|
|
self.calc_anim_combo = ttk.Combobox(
|
|
animation_frame, textvariable=self.calc_anim_var, values=animation_types, state="readonly")
|
|
self.calc_anim_combo.grid(row=1, column=1, sticky="ew", padx=5)
|
|
|
|
reset_button = ttk.Button(
|
|
animation_frame, text=Msg.STR["default_settings"], command=self._reset_animation_settings)
|
|
reset_button.grid(row=0, column=2, rowspan=2, padx=10)
|
|
|
|
animation_frame.columnconfigure(1, weight=1)
|
|
|
|
# --- Backup Default Settings ---
|
|
defaults_frame = ttk.LabelFrame(
|
|
self, text="Backup Defaults", padding=10)
|
|
defaults_frame.pack(fill=tk.X, padx=10, pady=5)
|
|
|
|
self.force_full_var = tk.BooleanVar()
|
|
self.force_incremental_var = tk.BooleanVar()
|
|
self.force_compression_var = tk.BooleanVar()
|
|
self.force_encryption_var = tk.BooleanVar()
|
|
|
|
ttk.Checkbutton(defaults_frame, text=Msg.STR["force_full_backup"], variable=self.force_full_var, command=lambda: enforce_backup_type_exclusivity(
|
|
self.force_full_var, self.force_incremental_var, self.force_full_var.get())).pack(anchor=tk.W)
|
|
ttk.Checkbutton(defaults_frame, text=Msg.STR["force_incremental_backup"], variable=self.force_incremental_var, command=lambda: enforce_backup_type_exclusivity(
|
|
self.force_incremental_var, self.force_full_var, self.force_incremental_var.get())).pack(anchor=tk.W)
|
|
ttk.Checkbutton(defaults_frame, text=Msg.STR["force_compression"],
|
|
variable=self.force_compression_var).pack(anchor=tk.W)
|
|
ttk.Checkbutton(defaults_frame, text=Msg.STR["force_encryption"],
|
|
variable=self.force_encryption_var).pack(anchor=tk.W)
|
|
|
|
ttk.Separator(defaults_frame, orient=tk.HORIZONTAL).pack(
|
|
fill=tk.X, pady=5)
|
|
|
|
encryption_note = ttk.Label(
|
|
defaults_frame, text=Msg.STR["encryption_note_system_backup"], wraplength=750, justify="left")
|
|
encryption_note.pack(anchor=tk.W, pady=5)
|
|
|
|
# --- Action Buttons ---
|
|
button_frame = ttk.Frame(self)
|
|
button_frame.pack(pady=10)
|
|
|
|
ttk.Button(button_frame, text=Msg.STR["apply"], command=self._apply_changes).pack(
|
|
side=tk.LEFT, padx=5)
|
|
ttk.Button(button_frame, text=Msg.STR["cancel"], command=self.destroy).pack(
|
|
side=tk.LEFT, padx=5)
|
|
|
|
self._load_system_folders()
|
|
self._load_animation_settings()
|
|
self._load_backup_defaults()
|
|
self._load_manual_excludes()
|
|
|
|
self._switch_view(self.current_view_index)
|
|
|
|
def _switch_view(self, index):
|
|
self.current_view_index = index
|
|
self.update_nav_buttons(index)
|
|
|
|
if index == 0:
|
|
self.manual_excludes_frame.pack_forget()
|
|
self.tree_frame.pack(fill=tk.BOTH, expand=True)
|
|
self.info_label.config(
|
|
text=Msg.STR["advanced_settings_warning"])
|
|
else:
|
|
self.tree_frame.pack_forget()
|
|
self.manual_excludes_frame.pack(fill=tk.BOTH, expand=True)
|
|
self.info_label.config(text=Msg.STR["manual_excludes_info"])
|
|
|
|
def update_nav_buttons(self, active_index):
|
|
for i, button in enumerate(self.nav_buttons):
|
|
if i == active_index:
|
|
button.configure(style="Toolbutton")
|
|
self.nav_progress_bars[i].pack(side=tk.BOTTOM, fill=tk.X)
|
|
self.nav_progress_bars[i]['value'] = 100
|
|
else:
|
|
button.configure(style="Gray.Toolbutton")
|
|
self.nav_progress_bars[i].pack_forget()
|
|
|
|
def _load_manual_excludes(self):
|
|
self.manual_excludes_listbox.delete(0, tk.END)
|
|
if AppConfig.MANUAL_EXCLUDE_LIST_PATH.exists():
|
|
with open(AppConfig.MANUAL_EXCLUDE_LIST_PATH, 'r') as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
if line:
|
|
self.manual_excludes_listbox.insert(tk.END, line)
|
|
|
|
def _delete_manual_exclude(self):
|
|
selected_indices = self.manual_excludes_listbox.curselection()
|
|
for i in reversed(selected_indices):
|
|
self.manual_excludes_listbox.delete(i)
|
|
|
|
def _reset_animation_settings(self):
|
|
self.config_manager.remove_setting("backup_animation_type")
|
|
self.config_manager.remove_setting("calculation_animation_type")
|
|
self._load_animation_settings()
|
|
|
|
def _reset_backup_defaults(self):
|
|
self.config_manager.remove_setting("force_full_backup")
|
|
self.config_manager.remove_setting("force_incremental_backup")
|
|
self.config_manager.remove_setting("force_compression")
|
|
self.config_manager.remove_setting("force_encryption")
|
|
self._load_backup_defaults()
|
|
if self.app_instance:
|
|
self.app_instance.update_backup_options_from_config()
|
|
|
|
def _load_backup_defaults(self):
|
|
self.force_full_var.set(
|
|
self.config_manager.get_setting("force_full_backup", False))
|
|
self.force_incremental_var.set(
|
|
self.config_manager.get_setting("force_incremental_backup", False))
|
|
self.force_compression_var.set(
|
|
self.config_manager.get_setting("force_compression", False))
|
|
self.force_encryption_var.set(
|
|
self.config_manager.get_setting("force_encryption", False))
|
|
|
|
def _load_animation_settings(self):
|
|
backup_anim = self.config_manager.get_setting(
|
|
"backup_animation_type", "counter_arc")
|
|
calc_anim = self.config_manager.get_setting(
|
|
"calculation_animation_type", "double_arc")
|
|
self.backup_anim_var.set(backup_anim)
|
|
self.calc_anim_var.set(calc_anim)
|
|
|
|
def _load_system_folders(self):
|
|
for i in self.tree.get_children():
|
|
self.tree.delete(i)
|
|
|
|
always_exclude = [
|
|
"/home", "/root", "/bin", "/etc", "/lib", "/lib64", "/sys", "/sbin", "/usr",
|
|
"/tmp", "/dev", "/run", "/mnt", "/proc", "/media", "/cdrom", "/var",
|
|
"/sbin.usr-is-merged", "/bin.usr-is-merged", "/lib.usr-is-merged", "/boot"
|
|
]
|
|
always_exclude.extend(AppConfig.STANDARD_EXCLUDE_CONTENT.splitlines())
|
|
_, user_patterns = self._load_exclude_patterns()
|
|
items_to_display = {}
|
|
|
|
root_dir = Path("/")
|
|
for item in root_dir.iterdir():
|
|
if item.is_dir():
|
|
item_path_str = str(item.absolute())
|
|
if item_path_str in always_exclude or f"{item_path_str}/*" in always_exclude:
|
|
continue
|
|
is_user_excluded = f"{item_path_str}/*" in user_patterns
|
|
included_text = Msg.STR["no"] if is_user_excluded else Msg.STR["yes"]
|
|
items_to_display[item_path_str] = (
|
|
included_text, item.name, item_path_str)
|
|
|
|
if self.app_instance and self.app_instance.destination_path:
|
|
backup_root_path = Path(
|
|
f"/{self.app_instance.destination_path.strip('/').split('/')[0]}")
|
|
backup_root_path_str = str(backup_root_path.absolute())
|
|
items_to_display[backup_root_path_str] = (
|
|
Msg.STR["no"], backup_root_path.name, backup_root_path_str)
|
|
|
|
restore_src_path = self.config_manager.get_setting(
|
|
"restore_source_path")
|
|
if restore_src_path and Path(restore_src_path).is_dir():
|
|
restore_root_path = Path(
|
|
f"/{str(Path(restore_src_path)).strip('/').split('/')[0]}")
|
|
restore_root_path_str = str(restore_root_path.absolute())
|
|
items_to_display[restore_root_path_str] = (
|
|
Msg.STR["no"], restore_root_path.name, restore_root_path_str)
|
|
|
|
for item_path_str in sorted(items_to_display.keys()):
|
|
item_values = items_to_display[item_path_str]
|
|
tag = "yes" if item_values[0] == Msg.STR["yes"] else "no"
|
|
|
|
# Special tag for the backup destination, which is always excluded and read-only
|
|
is_backup_dest = (self.app_instance and self.app_instance.destination_path and
|
|
item_path_str == str(Path(f"/{self.app_instance.destination_path.strip('/').split('/')[0]}").absolute()))
|
|
is_restore_src = (restore_src_path and
|
|
item_path_str == str(Path(f"/{str(Path(restore_src_path)).strip('/').split('/')[0]}").absolute()))
|
|
|
|
if is_backup_dest or is_restore_src:
|
|
tags = ("backup_dest_exclude", tag)
|
|
else:
|
|
tags = (tag,)
|
|
self.tree.insert("", "end", values=item_values, tags=tags)
|
|
|
|
def _toggle_include_status(self, event):
|
|
item_id = self.tree.identify_row(event.y)
|
|
if not item_id:
|
|
return
|
|
if "backup_dest_exclude" in self.tree.item(item_id, "tags"):
|
|
return
|
|
current_values = self.tree.item(item_id, 'values')
|
|
new_status = Msg.STR["yes"] if current_values[0] == Msg.STR["no"] else Msg.STR["no"]
|
|
|
|
new_tag = "yes" if new_status == Msg.STR["yes"] else "no"
|
|
|
|
self.tree.item(item_id, values=(
|
|
new_status, current_values[1], current_values[2]), tags=(new_tag,))
|
|
|
|
def _apply_changes(self):
|
|
self.config_manager.set_setting(
|
|
"backup_animation_type", self.backup_anim_var.get())
|
|
self.config_manager.set_setting(
|
|
"calculation_animation_type", self.calc_anim_var.get())
|
|
self.config_manager.set_setting(
|
|
"force_full_backup", self.force_full_var.get())
|
|
self.config_manager.set_setting(
|
|
"force_incremental_backup", self.force_incremental_var.get())
|
|
self.config_manager.set_setting(
|
|
"force_compression", self.force_compression_var.get())
|
|
self.config_manager.set_setting(
|
|
"force_encryption", self.force_encryption_var.get())
|
|
|
|
if self.app_instance:
|
|
self.app_instance.update_backup_options_from_config()
|
|
# Destroy the old icon
|
|
self.app_instance.animated_icon.destroy()
|
|
|
|
# Create a new one
|
|
bg_color = self.app_instance.style.lookup('TFrame', 'background')
|
|
backup_animation_type = self.backup_anim_var.get()
|
|
|
|
initial_animation_type = "blink"
|
|
if backup_animation_type == "line":
|
|
initial_animation_type = "line"
|
|
|
|
self.app_instance.animated_icon = AnimatedIcon(
|
|
self.app_instance.action_frame, width=20, height=20, use_pillow=True, bg=bg_color, animation_type=initial_animation_type)
|
|
|
|
# Pack it in the correct order
|
|
self.app_instance.animated_icon.pack(
|
|
side=tk.LEFT, padx=5, before=self.app_instance.task_progress)
|
|
|
|
# Set the correct state
|
|
self.app_instance.animated_icon.stop("DISABLE")
|
|
self.app_instance.animated_icon.animation_type = backup_animation_type
|
|
|
|
tree_paths = set()
|
|
for item_id in self.tree.get_children():
|
|
values = self.tree.item(item_id, 'values')
|
|
tree_paths.add(values[2])
|
|
|
|
new_excludes = []
|
|
for item_id in self.tree.get_children():
|
|
values = self.tree.item(item_id, 'values')
|
|
if values[0] == Msg.STR["no"]:
|
|
path = values[2]
|
|
if os.path.isdir(path):
|
|
new_excludes.append(f"{path}/*")
|
|
else:
|
|
new_excludes.append(path)
|
|
|
|
existing_patterns = []
|
|
if AppConfig.USER_EXCLUDE_LIST_PATH.exists():
|
|
with open(AppConfig.USER_EXCLUDE_LIST_PATH, 'r') as f:
|
|
existing_patterns = [
|
|
line.strip() for line in f if line.strip() and not line.startswith('#')]
|
|
|
|
preserved_patterns = []
|
|
for pattern in existing_patterns:
|
|
clean_pattern = pattern.replace('/*', '')
|
|
if clean_pattern not in tree_paths:
|
|
preserved_patterns.append(pattern)
|
|
|
|
final_excludes = list(set(preserved_patterns + new_excludes))
|
|
|
|
if self.app_instance and self.app_instance.destination_path:
|
|
backup_root_to_exclude = f"/{self.app_instance.destination_path.strip('/').split('/')[0]}/*"
|
|
if backup_root_to_exclude not in final_excludes:
|
|
final_excludes.append(backup_root_to_exclude)
|
|
|
|
with open(AppConfig.USER_EXCLUDE_LIST_PATH, 'w') as f:
|
|
for path in final_excludes:
|
|
f.write(f"{path}\n")
|
|
|
|
# Save manual excludes
|
|
with open(AppConfig.MANUAL_EXCLUDE_LIST_PATH, 'w') as f:
|
|
for item in self.manual_excludes_listbox.get(0, tk.END):
|
|
f.write(f"{item}\n")
|
|
|
|
self.destroy()
|
|
|
|
if self.app_instance:
|
|
current_source = self.app_instance.left_canvas_data.get('folder')
|
|
if current_source:
|
|
self.app_instance.actions.on_sidebar_button_click(
|
|
current_source)
|
|
|
|
def _load_exclude_patterns(self):
|
|
generated_patterns = []
|
|
if AppConfig.GENERATED_EXCLUDE_LIST_PATH.exists():
|
|
with open(AppConfig.GENERATED_EXCLUDE_LIST_PATH, 'r') as f:
|
|
generated_patterns = [
|
|
line.strip() for line in f if line.strip() and not line.startswith('#')]
|
|
|
|
user_patterns = []
|
|
if AppConfig.USER_EXCLUDE_LIST_PATH.exists():
|
|
with open(AppConfig.USER_EXCLUDE_LIST_PATH, 'r') as f:
|
|
user_patterns.extend(
|
|
[line.strip() for line in f if line.strip() and not line.startswith('#')])
|
|
|
|
if AppConfig.MANUAL_EXCLUDE_LIST_PATH.exists():
|
|
with open(AppConfig.MANUAL_EXCLUDE_LIST_PATH, 'r') as f:
|
|
user_patterns.extend(
|
|
[line.strip() for line in f if line.strip() and not line.startswith('#')])
|
|
|
|
return generated_patterns, user_patterns
|