fix fstrings and syntax error

This commit is contained in:
2025-08-10 12:25:10 +02:00
parent 30c2c3b901
commit d124c24533
11 changed files with 17 additions and 160 deletions

View File

@@ -96,7 +96,7 @@ class CustomFileDialog(tk.Toplevel):
self.view_manager._update_view_mode_buttons()
def initial_load() -> None:
def initial_load() -> None:
"""Performs the initial loading and UI setup."""
self.update_idletasks()
self.last_width = self.widget_manager.file_list_frame.winfo_width()
@@ -113,7 +113,7 @@ class CustomFileDialog(tk.Toplevel):
if self.dialog_mode == "save":
self.bind("<Delete>", self.file_op_manager.delete_selected_item)
def load_settings(self) -> None:
def load_settings(self) -> None:
"""Loads settings from the configuration file."""
self.settings = CfdConfigManager.load()
size_preset = self.settings.get("window_size_preset", "1050x850")
@@ -134,7 +134,7 @@ class CustomFileDialog(tk.Toplevel):
w, h = map(int, preset.split('x'))
return max(650, w - 400), max(450, h - 400)
def reload_config_and_rebuild_ui(self) -> None:
def reload_config_and_rebuild_ui(self) -> None:
"""Reloads the configuration and rebuilds the entire UI."""
self.load_settings()
@@ -169,11 +169,11 @@ class CustomFileDialog(tk.Toplevel):
else:
self.navigation_manager.navigate_to(self.current_dir)
def open_settings_dialog(self) -> None:
def open_settings_dialog(self) -> None:
"""Opens the settings dialog."""
SettingsDialog(self, dialog_mode=self.dialog_mode)
def update_animation_settings(self) -> None:
def update_animation_settings(self) -> None:
"""Updates the search animation icon based on current settings."""
use_pillow = self.settings.get('use_pillow_animation', False)
anim_type = self.settings.get('animation_type', 'double')
@@ -244,7 +244,7 @@ class CustomFileDialog(tk.Toplevel):
if self.resize_job:
self.after_cancel(self.resize_job)
def repopulate_icons() -> None:
def repopulate_icons() -> None:
"""Repopulates the file list icons."""
self.update_idletasks()
self.view_manager.populate_files()
@@ -377,7 +377,7 @@ class CustomFileDialog(tk.Toplevel):
total, used, free = shutil.disk_usage(self.current_dir)
free_str = self._format_size(free)
self.widget_manager.storage_label.config(
text=f"{LocaleStrings.CFD["free_space"]}: {free_str}")
text=f"{LocaleStrings.CFD['free_space']}: {free_str}")
self.widget_manager.storage_bar['value'] = (used / total) * 100
status_text = ""
@@ -386,19 +386,19 @@ class CustomFileDialog(tk.Toplevel):
content_count = self.view_manager._get_folder_content_count(
selected_path)
if content_count is not None:
status_text = f"'{os.path.basename(selected_path)}' ({content_count} {LocaleStrings.CFD["entries"]})"
status_text = f"'{os.path.basename(selected_path)}' ({content_count} {LocaleStrings.CFD['entries']})"
else:
status_text = f"'{os.path.basename(selected_path)}'"
else:
size = os.path.getsize(selected_path)
size_str = self._format_size(size)
status_text = f"'{os.path.basename(selected_path)}' {LocaleStrings.VIEW["size"]}: {size_str}"
status_text = f"'{os.path.basename(selected_path)}' {LocaleStrings.VIEW['size']}: {size_str}"
self.widget_manager.search_status_label.config(text=status_text)
except FileNotFoundError:
self.widget_manager.search_status_label.config(
text=LocaleStrings.CFD["directory_not_found"])
self.widget_manager.storage_label.config(
text=f"{LocaleStrings.CFD["free_space"]}: {LocaleStrings.CFD["unknown"]}")
text=f"{LocaleStrings.CFD['free_space']}: {LocaleStrings.CFD['unknown']}")
self.widget_manager.storage_bar['value'] = 0
def on_open(self) -> None:
@@ -520,9 +520,9 @@ class CustomFileDialog(tk.Toplevel):
break
for block_device in data.get('blockdevices', []):
if block_device.get('mountpoint') and
block_device.get('type') not in ['loop', 'rom'] and
block_device.get('mountpoint') != '/':
if (block_device.get('mountpoint') and
block_device.get('type') not in ['loop', 'rom'] and
block_device.get('mountpoint') != '/'):
if block_device.get('name').startswith(root_disk_name) and not block_device.get('rm', False):
pass
@@ -537,9 +537,9 @@ class CustomFileDialog(tk.Toplevel):
if 'children' in block_device:
for child_device in block_device['children']:
if child_device.get('mountpoint') and
child_device.get('type') not in ['loop', 'rom'] and
child_device.get('mountpoint') != '/':
if (child_device.get('mountpoint') and
child_device.get('type') not in ['loop', 'rom'] and
child_device.get('mountpoint') != '/'):
if block_device.get('name') == root_disk_name and not child_device.get('rm', False):
pass
@@ -586,146 +586,3 @@ class CustomFileDialog(tk.Toplevel):
"""
if hasattr(self, 'tooltip_window') and self.tooltip_window.winfo_exists():
self.tooltip_window.destroy()
"'{os.path.basename(selected_path)}' ({content_count} {LocaleStrings.CFD["entries"]})"
else:
status_text = f"'{os.path.basename(selected_path)}'"
else:
size = os.path.getsize(selected_path)
size_str = self._format_size(size)
status_text = f"'{os.path.basename(selected_path)}' {LocaleStrings.VIEW["size"]}: {size_str}"
self.widget_manager.search_status_label.config(text=status_text)
except FileNotFoundError:
self.widget_manager.search_status_label.config(
text=LocaleStrings.CFD["directory_not_found"])
self.widget_manager.storage_label.config(
text=f"{LocaleStrings.CFD["free_space"]}: {LocaleStrings.CFD["unknown"]}")
self.widget_manager.storage_bar['value'] = 0
def on_open(self):
if self.selected_file and os.path.isfile(self.selected_file):
self.destroy()
def on_save(self):
file_name = self.widget_manager.filename_entry.get()
if file_name:
self.selected_file = os.path.join(self.current_dir, file_name)
self.destroy()
def on_cancel(self):
self.selected_file = None
self.destroy()
def get_selected_file(self):
return self.selected_file
def update_action_buttons_state(self):
is_writable = os.access(self.current_dir, os.W_OK)
state = tk.NORMAL if is_writable and self.dialog_mode != "open" else tk.DISABLED
self.widget_manager.new_folder_button.config(state=state)
self.widget_manager.new_file_button.config(state=state)
def _matches_filetype(self, filename):
if self.current_filter_pattern == "*.*":
return True
patterns = self.current_filter_pattern.lower().split()
fn_lower = filename.lower()
for p in patterns:
if p.startswith('*.'):
if fn_lower.endswith(p[1:]):
return True
elif p.startswith('.'):
if fn_lower.endswith(p):
return True
else:
if fn_lower == p:
return True
return False
def _format_size(self, size_bytes):
if size_bytes is None:
return ""
if size_bytes < 1024:
return f"{size_bytes} B"
if size_bytes < 1024**2:
return f"{size_bytes/1024:.1f} KB"
if size_bytes < 1024**3:
return f"{size_bytes/1024**2:.1f} MB"
return f"{size_bytes/1024**3:.1f} GB"
def shorten_text(self, text, max_len):
return text if len(text) <= max_len else text[:max_len-3] + "..."
def _get_mounted_devices(self):
devices = []
root_disk_name = None
try:
result = subprocess.run(['lsblk', '-J', '-o', 'NAME,MOUNTPOINT,FSTYPE,SIZE,RO,RM,TYPE,LABEL,PKNAME'],
capture_output=True, text=True, check=True)
data = json.loads(result.stdout)
for block_device in data.get('blockdevices', []):
if 'children' in block_device:
for child_device in block_device['children']:
if child_device.get('mountpoint') == '/':
root_disk_name = block_device.get('name')
break
if root_disk_name:
break
for block_device in data.get('blockdevices', []):
if block_device.get('mountpoint') and \
block_device.get('type') not in ['loop', 'rom'] and \
block_device.get('mountpoint') != '/':
if block_device.get('name').startswith(root_disk_name) and not block_device.get('rm', False):
pass
else:
name = block_device.get('name')
mountpoint = block_device.get('mountpoint')
label = block_device.get('label')
removable = block_device.get('rm', False)
display_name = label if label else name
devices.append((display_name, mountpoint, removable))
if 'children' in block_device:
for child_device in block_device['children']:
if child_device.get('mountpoint') and \
child_device.get('type') not in ['loop', 'rom'] and \
child_device.get('mountpoint') != '/':
if block_device.get('name') == root_disk_name and not child_device.get('rm', False):
pass
else:
name = child_device.get('name')
mountpoint = child_device.get('mountpoint')
label = child_device.get('label')
removable = child_device.get('rm', False)
display_name = label if label else name
devices.append(
(display_name, mountpoint, removable))
except Exception as e:
print(f"Error getting mounted devices: {e}")
return devices
def _show_tooltip(self, event):
if hasattr(self, 'tooltip_window') and self.tooltip_window.winfo_exists():
return
tooltip_text = LocaleStrings.UI["start_search"] if not self.widget_manager.search_animation.running else LocaleStrings.UI["cancel_search"]
x = self.widget_manager.search_animation.winfo_rootx() + 25
y = self.widget_manager.search_animation.winfo_rooty() + 25
self.tooltip_window = tk.Toplevel(self)
self.tooltip_window.wm_overrideredirect(True)
self.tooltip_window.wm_geometry(f"+{x}+{y}")
label = tk.Label(self.tooltip_window, text=tooltip_text, relief="solid", borderwidth=1)
label.pack()
def _hide_tooltip(self, event):
if hasattr(self, 'tooltip_window') and self.tooltip_window.winfo_exists():
self.tooltip_window.destroy()

View File

@@ -34,7 +34,7 @@ class GlotzMol(tk.Tk):
initial_dir=os.path.expanduser("~"),
filetypes=[("All Files", "*.*"),
("Wireguard config Files", "*.conf")
], dialog_mode="save")
])
# This is the crucial part: wait for the dialog to be closed
self.wait_window(dialog)