From 29480a00961ba414d7fe2e5e75d1ecc0089c2519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A9sir=C3=A9=20Werner=20Menrath?= Date: Wed, 6 Aug 2025 11:38:15 +0200 Subject: [PATCH] refactor(ui): Encapsulate bottom bar setup in its own method To improve readability and reduce the size of the main setup_widgets method, the logic for creating and laying out all widgets in the bottom bar has been extracted into a new _setup_bottom_bar method. --- cfd_ui_setup.py | 120 +++++++++++++++++++++++++----------------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/cfd_ui_setup.py b/cfd_ui_setup.py index aef3826..a55c5c7 100644 --- a/cfd_ui_setup.py +++ b/cfd_ui_setup.py @@ -115,6 +115,62 @@ class WidgetManager: self.settings = settings self.setup_widgets() + def _setup_bottom_bar(self): + """Sets up the bottom bar including containers and widgets based on dialog mode.""" + self.action_status_frame = ttk.Frame(self.content_frame, style="AccentBottom.TFrame") + self.action_status_frame.grid(row=1, column=0, sticky="ew", pady=(5, 10), padx=10) + + self.left_container = ttk.Frame(self.action_status_frame, style="AccentBottom.TFrame") + self.center_container = ttk.Frame(self.action_status_frame, style="AccentBottom.TFrame") + self.right_container = ttk.Frame(self.action_status_frame, style="AccentBottom.TFrame") + + self.action_status_frame.grid_columnconfigure(1, weight=1) + self.left_container.grid(row=0, column=0, sticky='w') + self.center_container.grid(row=0, column=1, sticky='ew') + self.right_container.grid(row=0, column=2, sticky='e') + + # --- Define Widgets --- + self.status_bar = ttk.Label(self.center_container, text="", anchor="w", style="AccentBottom.TLabel") + self.search_entry = ttk.Entry(self.center_container) + self.search_status_label = ttk.Label(self.center_container, text="", style="AccentBottom.TLabel") + self.settings_button = ttk.Button(self.action_status_frame, image=self.dialog.icon_manager.get_icon('settings-2_small'), + command=self.dialog.open_settings_dialog, style="Bottom.TButton.Borderless.Round") + self.trash_button = ttk.Button(self.action_status_frame, image=self.dialog.icon_manager.get_icon('trash_small2'), + command=self.dialog.delete_selected_item, style="Bottom.TButton.Borderless.Round") + Tooltip(self.trash_button, "Ausgewähltes Element löschen/verschieben") + + button_box_pos = self.settings.get("button_box_pos", "left") + + if self.dialog.dialog_mode == "save": + self.filename_entry = ttk.Entry(self.center_container) + self.save_button = ttk.Button(self.action_status_frame, text="Speichern", command=self.dialog.on_save) + self.cancel_button = ttk.Button(self.action_status_frame, text="Abbrechen", command=self.dialog.on_cancel) + self.filter_combobox = ttk.Combobox(self.center_container, values=[ft[0] for ft in self.dialog.filetypes], state="readonly") + self.filter_combobox.bind("<>", self.dialog.on_filter_change) + self.filter_combobox.set(self.dialog.filetypes[0][0]) + + self.filename_entry.pack(side="top", fill="x", expand=True) + + if button_box_pos == 'left': + self._layout_save_buttons_left() + else: + self._layout_save_buttons_right() + else: # Open mode + self.open_button = ttk.Button(self.action_status_frame, text="Öffnen", command=self.dialog.on_open) + self.cancel_button = ttk.Button(self.action_status_frame, text="Abbrechen", command=self.dialog.on_cancel) + self.filter_combobox = ttk.Combobox(self.center_container, values=[ft[0] for ft in self.dialog.filetypes], state="readonly") + self.filter_combobox.bind("<>", self.dialog.on_filter_change) + self.filter_combobox.set(self.dialog.filetypes[0][0]) + + self.status_bar.pack(side="top", fill="x") + self.search_entry.pack(side="top", fill="x") + self.search_entry.pack_forget() + + if button_box_pos == 'left': + self._layout_open_buttons_left() + else: + self._layout_open_buttons_right() + def _layout_save_buttons_left(self): self.save_button.pack(in_=self.left_container, side="left", padx=(0, 5)) self.cancel_button.pack(in_=self.left_container, side="left") @@ -423,69 +479,17 @@ class WidgetManager: storage_frame, orient="horizontal", length=100, mode="determinate") self.storage_bar.pack(fill="x", pady=(2, 5), padx=15) - content_frame = ttk.Frame(paned_window, padding=( + self.content_frame = ttk.Frame(paned_window, padding=( 0, 0, 0, 0), style="AccentBottom.TFrame") - paned_window.add(content_frame, weight=1) - content_frame.grid_rowconfigure(0, weight=1) - content_frame.grid_columnconfigure(0, weight=1) + paned_window.add(self.content_frame, weight=1) + self.content_frame.grid_rowconfigure(0, weight=1) + self.content_frame.grid_columnconfigure(0, weight=1) self.file_list_frame = ttk.Frame( # Use Content.TFrame for consistent bg color - content_frame, style="Content.TFrame") + self.content_frame, style="Content.TFrame") self.file_list_frame.grid(row=0, column=0, sticky="nsew") self.dialog.bind("", self.dialog.on_window_resize) # --- Bottom Bar --- - self.action_status_frame = ttk.Frame(content_frame, style="AccentBottom.TFrame") - self.action_status_frame.grid(row=1, column=0, sticky="ew", pady=(5, 10), padx=10) - - self.left_container = ttk.Frame(self.action_status_frame, style="AccentBottom.TFrame") - self.center_container = ttk.Frame(self.action_status_frame, style="AccentBottom.TFrame") - self.right_container = ttk.Frame(self.action_status_frame, style="AccentBottom.TFrame") - - self.action_status_frame.grid_columnconfigure(1, weight=1) - self.left_container.grid(row=0, column=0, sticky='w') - self.center_container.grid(row=0, column=1, sticky='ew') - self.right_container.grid(row=0, column=2, sticky='e') - - # --- Define Widgets --- - self.status_bar = ttk.Label(self.center_container, text="", anchor="w", style="AccentBottom.TLabel") - self.search_entry = ttk.Entry(self.center_container) - self.search_status_label = ttk.Label(self.center_container, text="", style="AccentBottom.TLabel") - self.settings_button = ttk.Button(self.action_status_frame, image=self.dialog.icon_manager.get_icon('settings-2_small'), - command=self.dialog.open_settings_dialog, style="Bottom.TButton.Borderless.Round") - self.trash_button = ttk.Button(self.action_status_frame, image=self.dialog.icon_manager.get_icon('trash_small2'), - command=self.dialog.delete_selected_item, style="Bottom.TButton.Borderless.Round") - Tooltip(self.trash_button, "Ausgewähltes Element löschen/verschieben") - - button_box_pos = self.settings.get("button_box_pos", "left") - - if self.dialog.dialog_mode == "save": - self.filename_entry = ttk.Entry(self.center_container) - self.save_button = ttk.Button(self.action_status_frame, text="Speichern", command=self.dialog.on_save) - self.cancel_button = ttk.Button(self.action_status_frame, text="Abbrechen", command=self.dialog.on_cancel) - self.filter_combobox = ttk.Combobox(self.center_container, values=[ft[0] for ft in self.dialog.filetypes], state="readonly") - self.filter_combobox.bind("<>", self.dialog.on_filter_change) - self.filter_combobox.set(self.dialog.filetypes[0][0]) - - self.filename_entry.pack(side="top", fill="x", expand=True) - - if button_box_pos == 'left': - self._layout_save_buttons_left() - else: - self._layout_save_buttons_right() - else: # Open mode - self.open_button = ttk.Button(self.action_status_frame, text="Öffnen", command=self.dialog.on_open) - self.cancel_button = ttk.Button(self.action_status_frame, text="Abbrechen", command=self.dialog.on_cancel) - self.filter_combobox = ttk.Combobox(self.center_container, values=[ft[0] for ft in self.dialog.filetypes], state="readonly") - self.filter_combobox.bind("<>", self.dialog.on_filter_change) - self.filter_combobox.set(self.dialog.filetypes[0][0]) - - self.status_bar.pack(side="top", fill="x") - self.search_entry.pack(side="top", fill="x") - self.search_entry.pack_forget() - - if button_box_pos == 'left': - self._layout_open_buttons_left() - else: - self._layout_open_buttons_right() + self._setup_bottom_bar()