8.7 KiB
8.7 KiB
Plan for New Definitions Editor UI
1. Overview
This document outlines the plan to create a new, dedicated UI for managing "Asset Type Definitions", "File Type Definitions", and "Supplier Settings". This editor will provide a more structured and user-friendly way to manage these core application configurations, which are currently stored in separate JSON files.
2. General Design Principles
- Dedicated Dialog: The editor will be a new
QDialog(e.g.,DefinitionsEditorDialog). - Access Point: Launched from the
MainWindowmenu bar (e.g., under a "Definitions" menu or "Edit" -> "Edit Definitions..."). - Tabbed Interface: The dialog will use a
QTabWidgetto separate the management of different definition types. - List/Details View: Each tab will generally follow a two-pane layout:
- Left Pane: A
QListWidgetdisplaying the primary keys or names of the definitions (e.g., asset type names, file type IDs, supplier names). Includes "Add" and "Remove" buttons for managing these primary entries. - Right Pane: A details area (e.g.,
QGroupBoxwith aQFormLayout) that shows the specific settings for the item selected in the left-pane list.
- Left Pane: A
- Data Persistence: The dialog will load from and save to the respective JSON configuration files:
- Asset Types:
config/asset_type_definitions.json - File Types:
config/file_type_definitions.json - Supplier Settings:
config/suppliers.json(This file will be refactored from a simple list to a dictionary of supplier objects).
- Asset Types:
- User Experience: Standard "Save" and "Cancel" buttons, with a check for unsaved changes.
3. Tab-Specific Plans
3.1. Asset Type Definitions Tab
- Manages:
config/asset_type_definitions.json - UI Sketch:
graph LR subgraph AssetTypeTab [Asset Type Definitions Tab] direction LR AssetList[QListWidget (Asset Type Keys e.g., "Surface")] --> AssetDetailsGroup{Details for Selected Asset Type}; end subgraph AssetDetailsGroup direction TB Desc[Description: QTextEdit] Color[Color: QPushButton ("Choose Color...") + Color Swatch Display] Examples[Examples: QListWidget + Add/Remove Example Buttons] end AssetActions["Add Asset Type (Prompt for Name)\nRemove Selected Asset Type"] --> AssetList - Details:
- Left Pane:
QListWidgetfor asset type names. "Add Asset Type" (prompts for new key) and "Remove Selected Asset Type" buttons. - Right Pane (Details):
description:QTextEdit.color:QPushButtonopeningQColorDialog, with an adjacentQLabelto display the color swatch.examples:QListWidgetwith "Add Example" (QInputDialog.getText) and "Remove Selected Example" buttons.
- Left Pane:
3.2. File Type Definitions Tab
- Manages:
config/file_type_definitions.json - UI Sketch:
graph LR subgraph FileTypeTab [File Type Definitions Tab] direction LR FileList[QListWidget (File Type Keys e.g., "MAP_COL")] --> FileDetailsGroup{Details for Selected File Type}; end subgraph FileDetailsGroup direction TB DescF[Description: QTextEdit] ColorF[Color: QPushButton ("Choose Color...") + Color Swatch Display] ExamplesF[Examples: QListWidget + Add/Remove Example Buttons] StdType[Standard Type: QLineEdit] BitDepth[Bit Depth Rule: QComboBox ("respect", "force_8bit", "force_16bit")] IsGrayscale[Is Grayscale: QCheckBox] Keybind[Keybind: QLineEdit (1 char)] end FileActions["Add File Type (Prompt for ID)\nRemove Selected File Type"] --> FileList - Details:
- Left Pane:
QListWidgetfor file type IDs. "Add File Type" (prompts for new key) and "Remove Selected File Type" buttons. - Right Pane (Details):
description:QTextEdit.color:QPushButtonopeningQColorDialog, with an adjacentQLabelfor color swatch.examples:QListWidgetwith "Add Example" and "Remove Selected Example" buttons.standard_type:QLineEdit.bit_depth_rule:QComboBox(options: "respect", "force_8bit", "force_16bit").is_grayscale:QCheckBox.keybind:QLineEdit(validation for single character recommended).
- Left Pane:
3.3. Supplier Settings Tab
- Manages:
config/suppliers.json(This file will be refactored to a dictionary structure, e.g.,{"SupplierName": {"normal_map_type": "OpenGL", ...}}). - UI Sketch:
graph LR subgraph SupplierTab [Supplier Settings Tab] direction LR SupplierList[QListWidget (Supplier Names)] --> SupplierDetailsGroup{Details for Selected Supplier}; end subgraph SupplierDetailsGroup direction TB NormalMapType[Normal Map Type: QComboBox ("OpenGL", "DirectX")] %% Future supplier-specific settings can be added here end SupplierActions["Add Supplier (Prompt for Name)\nRemove Selected Supplier"] --> SupplierList - Details:
- Left Pane:
QListWidgetfor supplier names. "Add Supplier" (prompts for new name) and "Remove Selected Supplier" buttons. - Right Pane (Details):
normal_map_type:QComboBox(options: "OpenGL", "DirectX"). Default for new suppliers: "OpenGL".- (Space for future supplier-specific settings).
- Left Pane:
- Data Handling Note for
config/suppliers.json:- The editor will load from and save to
config/suppliers.jsonusing the new dictionary format (supplier name as key, object of settings as value). - Initial implementation might require
config/suppliers.jsonto be manually updated to this new format if it currently exists as a simple list. Alternatively, the editor could attempt an automatic conversion on first load if the old list format is detected, or prompt the user. For the first pass, assuming the editor works with the new format is simpler.
- The editor will load from and save to
4. Implementation Steps (High-Level)
- (Potentially Manual First Step) Refactor
config/suppliers.json: Ifconfig/suppliers.jsonexists as a list, manually convert it to the new dictionary structure (e.g.,{"SupplierName": {"normal_map_type": "OpenGL"}}) before starting UI development for this tab, or plan for the editor to handle this conversion. - Create
DefinitionsEditorDialogClass: Inherit fromQDialog. - Implement UI Structure: Main
QTabWidget, and for each tab, the two-pane layout withQListWidget,QGroupBoxfor details, and relevant input widgets (QLineEdit,QTextEdit,QComboBox,QCheckBox,QPushButton). - Implement Loading Logic:
- For each tab, read data from its corresponding JSON file.
- Populate the left-pane
QListWidgetwith the primary keys/names. - Store the full data structure internally (e.g., in dictionaries within the dialog instance).
- Implement Display Logic:
- When an item is selected in a
QListWidget, populate the right-pane detail fields with the data for that item.
- When an item is selected in a
- Implement Editing Logic:
- Ensure that changes made in the detail fields (text edits, combobox selections, checkbox states, color choices, list example modifications) update the corresponding internal data structure for the currently selected item.
- Implement Add/Remove Functionality:
- For each definition type (Asset Type, File Type, Supplier), implement the "Add" and "Remove" buttons.
- "Add": Prompt for a unique key/name, create a new default entry in the internal data, and add it to the
QListWidget. - "Remove": Remove the selected item from the
QListWidgetand the internal data.
- "Add": Prompt for a unique key/name, create a new default entry in the internal data, and add it to the
- For "examples" lists within Asset and File types, implement their "Add Example" and "Remove Selected Example" buttons.
- For each definition type (Asset Type, File Type, Supplier), implement the "Add" and "Remove" buttons.
- Implement Saving Logic:
- When the main "Save" button is clicked:
- Write the (potentially modified) Asset Type definitions data structure to
config/asset_type_definitions.json. - Write File Type definitions to
config/file_type_definitions.json. - Write Supplier settings (in the new dictionary format) to
config/suppliers.json.
- Write the (potentially modified) Asset Type definitions data structure to
- Consider creating new dedicated save functions in
configuration.pyfor each of these files if they don't already exist or if existing ones are not suitable.
- When the main "Save" button is clicked:
- Implement Unsaved Changes Check & Cancel Logic.
- Integrate Dialog Launch: Add a menu action in
MainWindow.pyto open theDefinitionsEditorDialog.
This plan provides a comprehensive approach to creating a dedicated editor for these crucial application definitions.