Asset-Frameworker/ProjectNotes/GUI_REFACTOR_PLAN.md
2025-04-29 18:26:13 +02:00

7.5 KiB

Asset Processor GUI Refactor Plan

This document outlines the plan to refactor the Asset Processor GUI based on user requirements.

Goals

  1. Improve File Visibility: Display all files found within an asset in the preview list, including those that don't match the preset, are moved to 'Extra', or have errors, along with their status.
  2. Integrate Preset Editor: Move the preset editing functionality from the separate dialog into a collapsible panel within the main window.

Goal 1: Improve File Visibility in Preview List

Problem: The current preview (PredictionHandler calling AssetProcessor.predict_output_structure) only shows files that successfully match a map type rule and get a predicted output name. It doesn't show files that are ignored, moved to 'Extra', or encounter errors during classification.

Solution: Leverage the more comprehensive classification logic already present in AssetProcessor._inventory_and_classify_files for the GUI preview.

Plan Steps:

  1. Modify asset_processor.py:
    • Create a new method in AssetProcessor, perhaps named get_detailed_file_predictions().
    • This new method will perform the core steps of _setup_workspace(), _extract_input(), and _inventory_and_classify_files().
    • It will then iterate through all categories in self.classified_files ('maps', 'models', 'extra', 'ignored').
    • For each file, it will determine a 'status' (e.g., "Mapped", "Model", "Extra", "Ignored", "Error") and attempt to predict the output name (similar to predict_output_structure for maps, maybe just the original name for others).
    • It will return a more detailed list of dictionaries, each containing: {'original_path': str, 'predicted_name': str | None, 'status': str, 'details': str | None}.
    • Crucially, this method will not perform the actual processing (_process_maps, _merge_maps, etc.) or file moving, only the classification and prediction. It should also include cleanup (_cleanup_workspace).
  2. Modify gui/prediction_handler.py:
    • Update PredictionHandler.run_prediction to call the new AssetProcessor.get_detailed_file_predictions() method instead of predict_output_structure().
    • Adapt the code that processes the results to handle the new dictionary format (including the 'status' and 'details' fields).
    • Emit this enhanced list via the prediction_results_ready signal.
  3. Modify gui/main_window.py:
    • In setup_ui, add a new column to self.preview_table for "Status". Adjust column count and header labels.
    • In on_prediction_results_ready, populate the new "Status" column using the data received from PredictionHandler.
    • Consider adding tooltips to the status column to show the 'details' (e.g., the reason for being ignored or moved to extra).
    • Optionally, use background colors or icons in the status column for better visual distinction.

Goal 2: Integrate Preset Editor into Main Window

Problem: Preset editing requires opening a separate modal dialog, interrupting the main workflow.

Solution: Embed the preset editing controls directly into the main window within a collapsible panel.

Plan Steps:

  1. Modify gui/main_window.py - UI Changes:
    • Remove the "Manage Presets" button (self.manage_presets_button).
    • Add a collapsible panel (potentially using a QFrame with show/hide logic triggered by a button, or a QDockWidget if more appropriate) to the left side of the main layout.
    • Inside this panel:
      • Add the QListWidget for displaying presets (self.preset_list).
      • Add the "New" and "Delete" buttons below the list. (The "Load" button becomes implicit - selecting a preset in the list loads it into the editor).
      • Recreate the QTabWidget (self.preset_editor_tabs) with the "General & Naming" and "Mapping & Rules" tabs.
      • Recreate all the widgets currently inside the PresetEditorDialog tabs (QLineEdit, QTextEdit, QSpinBox, QListWidget+controls, QTableWidget+controls) within the corresponding tabs in the main window's panel. Give them appropriate instance names (e.g., self.editor_preset_name, self.editor_supplier_name, etc.).
      • Add "Save" and "Save As..." buttons within the collapsible panel, likely at the bottom.
  2. Modify gui/main_window.py - Logic Integration:
    • Adapt the populate_presets method to populate the new self.preset_list in the panel.
    • Connect self.preset_list.currentItemChanged to a new method load_selected_preset_for_editing. This method will handle checking for unsaved changes in the editor panel and then load the selected preset's data into the editor widgets (similar to PresetEditorDialog.load_preset).
    • Implement save_preset, save_preset_as, new_preset, delete_preset methods directly within MainWindow, adapting the logic from PresetEditorDialog. These will interact with the editor widgets in the panel.
    • Implement check_unsaved_changes logic for the editor panel, prompting the user if they try to load/create/delete a preset or close the application with unsaved edits in the panel.
    • Connect the editor widgets' change signals (textChanged, valueChanged, itemChanged, etc.) to a mark_editor_unsaved method in MainWindow.
    • Ensure the main preset selection QComboBox (self.preset_combo) is repopulated when presets are saved/deleted via the editor panel.
  3. Cleanup:
    • Delete the gui/preset_editor_dialog.py file.
    • Remove imports and references to PresetEditorDialog from gui/main_window.py.

Visual Plan

Current Layout:

graph TD
    subgraph "Current Main Window Layout"
        A[Preset Combo + Manage Button] --> B(Drag & Drop Area);
        B --> C{File Preview Table};
        C --> D[Progress Bar];
        D --> E[Options + Start/Cancel Buttons];
    end

    subgraph "Current Preset Editor (Separate Dialog)"
        F[Preset List + Load/New/Delete] --> G{Tab Widget};
        subgraph "Tab Widget"
            G1[General & Naming Tab]
            G2[Mapping & Rules Tab]
        end
        G --> H[Save / Save As / Close Buttons];
    end

    A -- Manage Button Click --> F;

    style F fill:#f9f,stroke:#333,stroke-width:2px
    style G fill:#f9f,stroke:#333,stroke-width:2px
    style H fill:#f9f,stroke:#333,stroke-width:2px

Proposed Layout:

graph TD
    subgraph "Proposed Main Window Layout"
        direction LR
        subgraph "Collapsible Preset Editor Panel (Left)"
            P_List[Preset List] --> P_Buttons[New / Delete Buttons]
            P_Buttons --> P_Tabs{Tab Widget}
            subgraph "Editor Tabs"
                P_Tab1[General & Naming]
                P_Tab2[Mapping & Rules]
            end
            P_Tabs --> P_Save[Save / Save As Buttons]
        end

        subgraph "Main Area (Right)"
            M_Preset[Preset Combo (for processing)] --> M_DragDrop(Drag & Drop Area)
            M_DragDrop --> M_Preview{File Preview Table (with Status Column)}
            M_Preview --> M_Progress[Progress Bar]
            M_Progress --> M_Controls[Options + Start/Cancel Buttons]
        end

        P_List -- Selection Loads --> P_Tabs;
        P_Save -- Updates --> P_List;
        P_List -- Updates --> M_Preset;

        style M_Preview fill:#ccf,stroke:#333,stroke-width:2px
        style P_List fill:#cfc,stroke:#333,stroke-width:2px
        style P_Tabs fill:#cfc,stroke:#333,stroke-width:2px
        style P_Save fill:#cfc,stroke:#333,stroke-width:2px
    end