commit 37

This commit is contained in:
2025-08-02 10:54:37 +02:00
parent af7dcc31e4
commit b350e562fa
5 changed files with 47 additions and 683 deletions

View File

@@ -41,7 +41,7 @@ class CustomFileDialog(tk.Toplevel):
super().__init__(parent)
self.parent = parent
self.title("Datei auswählen")
self.geometry("900x650")
self.geometry("1100x850")
self.minsize(650, 400)
self.transient(parent)
self.grab_set()
@@ -49,7 +49,7 @@ class CustomFileDialog(tk.Toplevel):
self.selected_file = None
self.current_dir = os.path.abspath(
initial_dir) if initial_dir else os.path.expanduser("~")
self.filetypes = filetypes if filetypes else [("Alle Dateien", "*.*")]
self.filetypes = filetypes if filetypes else [("Alle Dateien", "*.* ")]
self.current_filter_pattern = self.filetypes[0][1]
self.history = []
self.history_pos = -1
@@ -64,7 +64,6 @@ class CustomFileDialog(tk.Toplevel):
self.original_path_text = "" # Store original path text
self.icon_manager = IconManager()
self.icons = self.icon_manager.icons
self.create_styles()
self.create_widgets()
self.navigate_to(self.current_dir)
@@ -72,22 +71,22 @@ class CustomFileDialog(tk.Toplevel):
def get_file_icon(self, filename, size='large'):
ext = os.path.splitext(filename)[1].lower()
if ext == '.svg':
return self.icons[f'warning_{size}']
return self.icon_manager.get_icon(f'warning_{size}')
if ext == '.py':
return self.icons[f'python_{size}']
return self.icon_manager.get_icon(f'python_{size}')
if ext == '.pdf':
return self.icons[f'pdf_{size}']
return self.icon_manager.get_icon(f'pdf_{size}')
if ext in ['.tar', '.zip', '.rar', '.7z', '.gz']:
return self.icons[f'archive_{size}']
return self.icon_manager.get_icon(f'archive_{size}')
if ext in ['.mp3', '.wav', '.ogg', '.flac']:
return self.icons[f'audio_{size}']
return self.icon_manager.get_icon(f'audio_{size}')
if ext in ['.mp4', '.mkv', '.avi', '.mov']:
return self.icons[f'video_{size}'] if size == 'large' else self.icons['video_small_file']
return self.icon_manager.get_icon(f'video_{size}') if size == 'large' else self.icon_manager.get_icon('video_small_file')
if ext in ['.jpg', '.jpeg', '.png', '.gif', '.bmp']:
return self.icons[f'picture_{size}']
return self.icon_manager.get_icon(f'picture_{size}')
if ext == '.iso':
return self.icons[f'iso_{size}']
return self.icons[f'file_{size}']
return self.icon_manager.get_icon(f'iso_{size}')
return self.icon_manager.get_icon(f'file_{size}')
def create_styles(self):
style = ttk.Style(self)
@@ -188,16 +187,16 @@ class CustomFileDialog(tk.Toplevel):
nav_buttons_container.grid(row=0, column=0, sticky="w")
self.back_button = ttk.Button(
nav_buttons_container, image=self.icons['back'], command=self.go_back, state=tk.DISABLED, style="Header.TButton.Borderless.Round")
nav_buttons_container, image=self.icon_manager.get_icon('back'), command=self.go_back, state=tk.DISABLED, style="Header.TButton.Borderless.Round")
self.back_button.pack(side="left", padx=10)
Tooltip(self.back_button, "Zurück")
self.forward_button = ttk.Button(
nav_buttons_container, image=self.icons['forward'], command=self.go_forward, state=tk.DISABLED, style="Header.TButton.Borderless.Round")
nav_buttons_container, image=self.icon_manager.get_icon('forward'), command=self.go_forward, state=tk.DISABLED, style="Header.TButton.Borderless.Round")
self.forward_button.pack(side="left")
Tooltip(self.forward_button, "Vorwärts")
self.home_button = ttk.Button(nav_buttons_container, image=self.icons['home'], command=lambda: self.navigate_to(
self.home_button = ttk.Button(nav_buttons_container, image=self.icon_manager.get_icon('home'), command=lambda: self.navigate_to(
os.path.expanduser("~")), style="Header.TButton.Borderless.Round")
self.home_button.pack(side="left", padx=10)
Tooltip(self.home_button, "Home")
@@ -217,7 +216,7 @@ class CustomFileDialog(tk.Toplevel):
right_top_bar_frame, style='Accent.TFrame')
search_container.pack(side="left", padx=(0, 10))
self.search_button = ttk.Button(search_container, image=self.icons['search_small'],
self.search_button = ttk.Button(search_container, image=self.icon_manager.get_icon('search_small'),
command=self.toggle_search_mode, style="Header.TButton.Borderless.Round")
self.search_button.pack(side="left")
Tooltip(self.search_button, "Suchen")
@@ -228,7 +227,7 @@ class CustomFileDialog(tk.Toplevel):
# Recursive search toggle button
self.recursive_search = tk.BooleanVar(value=True)
self.recursive_button = ttk.Button(self.search_options_frame, image=self.icons['recursive_small'],
self.recursive_button = ttk.Button(self.search_options_frame, image=self.icon_manager.get_icon('recursive_small'),
command=self.toggle_recursive_search,
style="Header.TButton.Active.Round")
self.recursive_button.pack(side="left", padx=2)
@@ -238,18 +237,18 @@ class CustomFileDialog(tk.Toplevel):
padding=(5, 0), style='Accent.TFrame')
view_switch.pack(side="left")
self.icon_view_button = ttk.Button(view_switch, image=self.icons['icon_view'],
self.icon_view_button = ttk.Button(view_switch, image=self.icon_manager.get_icon('icon_view'),
command=self.set_icon_view, style="Header.TButton.Active.Round")
self.icon_view_button.pack(side="left", padx=(50, 10))
Tooltip(self.icon_view_button, "Kachelansicht")
self.list_view_button = ttk.Button(view_switch, image=self.icons['list_view'],
self.list_view_button = ttk.Button(view_switch, image=self.icon_manager.get_icon('list_view'),
command=self.set_list_view, style="Header.TButton.Borderless.Round")
self.list_view_button.pack(side="left")
Tooltip(self.list_view_button, "Listenansicht")
self.hidden_files_button = ttk.Button(
right_top_bar_frame, image=self.icons['hide'], command=self.toggle_hidden_files, style="Header.TButton.Borderless.Round")
right_top_bar_frame, image=self.icon_manager.get_icon('hide'), command=self.toggle_hidden_files, style="Header.TButton.Borderless.Round")
self.hidden_files_button.pack(side="left", padx=10)
Tooltip(self.hidden_files_button, "Versteckte Dateien anzeigen")
@@ -278,16 +277,16 @@ class CustomFileDialog(tk.Toplevel):
row=0, column=0, sticky="nsew")
sidebar_buttons_config = [
{'name': 'Computer',
'icon': self.icons['computer_small'], 'path': '/'},
{'name': 'Downloads', 'icon': self.icons['downloads_small'], 'path': get_xdg_user_dir(
'icon': self.icon_manager.get_icon('computer_small'), 'path': '/'},
{'name': 'Downloads', 'icon': self.icon_manager.get_icon('downloads_small'), 'path': get_xdg_user_dir(
"XDG_DOWNLOAD_DIR", "Downloads")},
{'name': 'Dokumente', 'icon': self.icons['documents_small'], 'path': get_xdg_user_dir(
{'name': 'Dokumente', 'icon': self.icon_manager.get_icon('documents_small'), 'path': get_xdg_user_dir(
"XDG_DOCUMENTS_DIR", "Documents")},
{'name': 'Bilder', 'icon': self.icons['pictures_small'], 'path': get_xdg_user_dir(
{'name': 'Bilder', 'icon': self.icon_manager.get_icon('pictures_small'), 'path': get_xdg_user_dir(
"XDG_PICTURES_DIR", "Pictures")},
{'name': 'Musik', 'icon': self.icons['music_small'], 'path': get_xdg_user_dir(
{'name': 'Musik', 'icon': self.icon_manager.get_icon('music_small'), 'path': get_xdg_user_dir(
"XDG_MUSIC_DIR", "Music")},
{'name': 'Videos', 'icon': self.icons['video_small'], 'path': get_xdg_user_dir(
{'name': 'Videos', 'icon': self.icon_manager.get_icon('video_small'), 'path': get_xdg_user_dir(
"XDG_VIDEO_DIR", "Videos")},
]
for config in sidebar_buttons_config:
@@ -364,7 +363,8 @@ class CustomFileDialog(tk.Toplevel):
# Populate devices
for device_name, mount_point, removable in self._get_mounted_devices():
icon = self.icons['usb_small'] if removable else self.icons['device_small']
icon = self.icon_manager.get_icon(
'usb_small') if removable else self.icon_manager.get_icon('device_small')
button_text = f" {device_name}"
if len(device_name) > 15: # Static wrapping for long names
button_text = f" {device_name[:15]}\n{device_name[15:]}"
@@ -408,7 +408,7 @@ class CustomFileDialog(tk.Toplevel):
# Storage section at bottom - use pack instead of grid to stay at bottom
storage_frame = ttk.Frame(sidebar_frame, style="Sidebar.TFrame")
storage_frame.grid(row=4, column=0, sticky="sew", padx=10, pady=10)
storage_frame.grid(row=5, column=0, sticky="sew", padx=10, pady=10)
self.storage_label = ttk.Label(
storage_frame, text="Freier Speicher:", background=self.freespace_background)
self.storage_label.pack(fill="x", padx=10)
@@ -437,18 +437,20 @@ class CustomFileDialog(tk.Toplevel):
self.status_bar = ttk.Label(
bottom_controls_frame, text="", anchor="w", style="AccentBottom.TLabel")
self.status_bar.grid(row=0, column=1, columnspan=2,
self.status_bar.grid(row=0, column=1, columnspan=3,
sticky="ew", padx=10, pady=10)
ttk.Button(bottom_controls_frame, text="Öffnen",
command=self.on_open).grid(row=0, column=0, padx=10)
command=self.on_open).grid(row=0, column=0, padx=(10, 0))
ttk.Button(bottom_controls_frame, text="Speichern",
command=self.on_save).grid(row=1, column=0, padx=(10, 0))
ttk.Button(bottom_controls_frame, text="Abbrechen",
command=self.on_cancel).grid(row=1, column=0, padx=10)
command=self.on_cancel).grid(row=1, column=1, columnspan=3, padx=(10, 0))
self.filter_combobox = ttk.Combobox(
bottom_controls_frame, values=[ft[0] for ft in self.filetypes], state="readonly")
self.filter_combobox.grid(
row=1, column=1, sticky="w", padx=10, pady=(5, 10))
row=1, column=2, sticky="w", padx=(0, 10), pady=(5, 10))
self.filter_combobox.bind(
"<<ComboboxSelected>>", self.on_filter_change)
self.filter_combobox.set(self.filetypes[0][0])
@@ -456,10 +458,12 @@ class CustomFileDialog(tk.Toplevel):
def toggle_hidden_files(self):
self.show_hidden_files.set(not self.show_hidden_files.get())
if self.show_hidden_files.get():
self.hidden_files_button.config(image=self.icons['unhide'])
self.hidden_files_button.config(
image=self.icon_manager.get_icon('unhide'))
Tooltip(self.hidden_files_button, "Versteckte Dateien ausblenden")
else:
self.hidden_files_button.config(image=self.icons['hide'])
self.hidden_files_button.config(
image=self.icon_manager.get_icon('hide'))
Tooltip(self.hidden_files_button, "Versteckte Dateien anzeigen")
self.populate_files()
@@ -835,7 +839,7 @@ class CustomFileDialog(tk.Toplevel):
container_frame, width=item_width, height=item_height, style="Item.TFrame")
item_frame.grid(row=row, column=col, padx=5, ipadx=25, pady=5)
item_frame.grid_propagate(False)
icon = self.icons['folder_large'] if is_dir else self.get_file_icon(
icon = self.icon_manager.get_icon('folder_large') if is_dir else self.get_file_icon(
name, 'large')
icon_label = ttk.Label(item_frame, image=icon, style="Icon.TLabel")
icon_label.pack(pady=(10, 5))
@@ -912,7 +916,8 @@ class CustomFileDialog(tk.Toplevel):
modified_time = datetime.fromtimestamp(
stat.st_mtime).strftime('%d.%m.%Y %H:%M')
if is_dir:
icon, file_type, size = self.icons['folder_small'], "Ordner", ""
icon, file_type, size = self.icon_manager.get_icon(
'folder_small'), "Ordner", ""
else:
icon, file_type, size = self.get_file_icon(
name, 'small'), "Datei", self._format_size(stat.st_size)
@@ -1051,6 +1056,9 @@ class CustomFileDialog(tk.Toplevel):
return
self.destroy()
def on_save(self):
pass
def on_cancel(self):
self.selected_file = None
self.destroy()