Skip to content

Dropdowns for Vehicle Components - #272

Merged
amilcarlucas merged 9 commits into
ArduPilot:masterfrom
franfrancisco9:dropdown_components
Mar 24, 2025
Merged

amilcarlucas merged 9 commits into
ArduPilot:masterfrom
franfrancisco9:dropdown_components

Conversation

@franfrancisco9

Copy link
Copy Markdown
Contributor

This pull request allows the user to save a vehicle component to a template and select it directly from a pre-defined set of common vehicle components.

For each vehicle component, a dropdown arrow is present as well as a button to allow to save the current filled component.

The current vehicle_components_template.json is empty but could be filled with common components.

@amilcarlucas

Copy link
Copy Markdown
Collaborator

Thanks Francisco. I have rebased it and corrected the LF and the commit message.

@amilcarlucas

Copy link
Copy Markdown
Collaborator

This pull request introduces several new features and improvements related to component templates in the ardupilot_methodic_configurator project. The most significant changes include the addition of methods to load and save component templates, the integration of template controls in the frontend, and the creation of a new JSON file for storing templates.

Backend Changes:

  • Added load_component_templates and save_component_templates methods to handle loading and saving component templates in backend_filesystem_vehicle_components.py.

Frontend Changes:

  • Imported VehicleComponents and added template controls initialization in frontend_tkinter_component_editor_base.py. [1] [2]
  • Integrated template controls in the __add_widget method to add template dropdown and save buttons for components.
  • Added methods to handle template dropdown, save templates, and apply templates in frontend_tkinter_component_editor_base.py.

Configuration Changes:

  • Created a new JSON file vehicle_components_template.json to store component templates.

@amilcarlucas amilcarlucas self-assigned this Mar 15, 2025
@amilcarlucas amilcarlucas added the enhancement New feature or request label Mar 15, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds support for vehicle component templates by allowing users to save configurations as templates and select them from a dropdown.

  • Introduces new functions in the backend to load and save component templates.
  • Enhances the frontend component editor with dropdown buttons and associated controls to apply and save templates.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
ardupilot_methodic_configurator/backend_filesystem_vehicle_components.py Added functions to load and save component templates from a dedicated JSON file.
ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py Added UI elements and logic (dropdown buttons, template controls, and menu events) for managing component templates.
Comments suppressed due to low confidence (2)

ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py:128

  • [nitpick] Consider renaming the key 'manager' to a more descriptive name, such as 'vehicle_components_manager', to improve clarity about its purpose.
self.template_controls = {"buttons": {}, "current_menu": None, "manager": VehicleComponents()}

ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py:274

  • [nitpick] The check for 'hasattr(self, "current_dropdown_menu")' is inconsistent with storing the dropdown menu in 'self.template_controls["current_menu"]'; consider using a consistent attribute name for clarity.
if hasattr(self, "current_dropdown_menu") and self.template_controls["current_menu"]:

@amilcarlucas

amilcarlucas commented Mar 15, 2025 •

Copy link
Copy Markdown
Collaborator

I fixed the pylint and mypy issues, but intoduced a regression when applying templates, sorry. I will have to take a look at it later. Have no more time today.

@amilcarlucas

Copy link
Copy Markdown
Collaborator

Refractored the code and added pytests

@amilcarlucas
amilcarlucas requested a review from Copilot March 17, 2025 12:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds support for saving and selecting vehicle component templates via dropdown menus and updates the GUI and backend logic to support this new functionality. Key changes include:

  • Introducing a new ComponentTemplateManager class with methods to add template controls and manage template file IO.
  • Adding tests for the ComponentTemplateManager and updating component editor functionality to integrate template selection.
  • Updating the backend filesystem module to support loading and saving of vehicle component templates.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_frontend_tkinter_component_template_manager.py New tests for the component template manager functionality
ardupilot_methodic_configurator/frontend_tkinter_component_template_manager.py Implementation of template controls and dropdown functions
tests/test_frontend_tkinter_component_editor_base.py Updates to tests for widget setup and template controls integration
ardupilot_methodic_configurator/backend_filesystem_vehicle_components.py Enhancements to load and save vehicle component templates
ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py Integration of template manager and updates to widget population logic
ardupilot_methodic_configurator/frontend_tkinter_component_editor.py Override of template name derivation and various editor enhancements
Comments suppressed due to low confidence (1)

ardupilot_methodic_configurator/frontend_tkinter_component_editor.py:786

  • There appear to be duplicate implementations of the 'derive_initial_template_name' method in this class. Consider consolidating the logic to prevent potential inconsistencies.
def derive_initial_template_name(self, component_data: dict[str, Any]) -> str:

menu.post(x, y)

self.current_menu = menu

Copilot AI Mar 17, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The 'close_menu' function uses 'close_handler_id' which is assigned after the function definition. Consider adding a comment or restructuring the code to make the closure of 'close_handler_id' clearer.

Suggested change
# Bind the close_menu function to the Button-1 event and store the handler ID
close_handler_id = self.root.bind("<Button-1>", close_menu, add="+")

Copilot uses AI. Check for mistakes.

new_template = {"name": template_name, "data": component_data}

for i, template in enumerate(templates[component_name]):

Copilot AI Mar 17, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] When a template with the same name exists, the function returns immediately if the user does not confirm an overwrite. Consider providing feedback to the user in the non-confirmed case or revisiting the control flow to ensure clear communication.

Copilot uses AI. Check for mistakes.
@amilcarlucas
amilcarlucas requested a review from Copilot March 17, 2025 21:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds dropdown functionality for vehicle component templates and improves template management by integrating new backend and frontend code while extending test coverage for these features.

  • Introduces and refines ComponentTemplateManager for handling template saving, loading and UI controls.
  • Enhances VehicleComponents template I/O methods in the backend.
  • Expands test coverage for component template and editor behaviors.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_frontend_tkinter_component_template_manager.py New tests covering template manager functionality.
ardupilot_methodic_configurator/backend_filesystem_vehicle_components.py Updates to load and save component templates with proper merging logic.
ardupilot_methodic_configurator/frontend_tkinter_component_template_manager.py New ComponentTemplateManager implementation for the GUI.
tests/test_frontend_tkinter_component_editor_base.py Additional tests for widget and template control functions.
ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py Integration of template_manager into the editor base; minor refactoring.
ardupilot_methodic_configurator/frontend_tkinter_component_editor.py Updated derive_initial_template_name and component editor enhancements.
Comments suppressed due to low confidence (2)

ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py:125

  • The call to __display_component_editor_usage_instructions is executed immediately instead of being scheduled. Use a lambda or pass the function reference without calling it; for example: self.root.after(10, lambda: self.__display_component_editor_usage_instructions(self.root)).
self.root.after(10, self.__display_component_editor_usage_instructions(self.root))  # type: ignore[arg-type]

ardupilot_methodic_configurator/frontend_tkinter_component_template_manager.py:214

  • The close_menu function references close_handler_id from an outer scope that’s declared after its definition. Consider declaring close_handler_id (e.g., by initializing it to None before defining close_menu) to ensure proper closure capture.
def close_menu(_: tk.Event) -> None:

@amilcarlucas
amilcarlucas requested a review from Copilot March 20, 2025 16:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a feature that enables users to save a vehicle component configuration as a template and select from a list of pre-defined system and user templates via dropdown controls. The key changes include:

  • Adding new methods in backend_filesystem_vehicle_components.py to load, merge, and save system and user templates.
  • Implementing a new ComponentTemplateManager class in the Tkinter frontend to handle template dropdowns and saving actions.
  • Extending test coverage and updating architectural documentation to reflect these template management capabilities.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ardupilot_methodic_configurator/backend_filesystem_vehicle_components.py Introduced methods to load system/user templates and manage template saving logic.
tests/test_frontend_tkinter_component_template_manager.py Added extensive tests to verify saving, updating, and applying component templates.
ardupilot_methodic_configurator/frontend_tkinter_component_template_manager.py Developed UI functions for rendering dropdown buttons and saving templates.
tests/test_frontend_tkinter_component_editor_base.py Added tests for widget creation and integration of the new template controls.
ARCHITECTURE.md Updated requirements to document the new template management feature.
ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py & ardupilot_methodic_configurator/frontend_tkinter_component_editor.py Integrated template management into the component editor UI via new callbacks and controls.
Comments suppressed due to low confidence (3)

ardupilot_methodic_configurator/backend_filesystem_vehicle_components.py:92

  • [nitpick] Consider renaming the 'user_modified' flag to a more descriptive name such as 'is_user_modified' for improved clarity.
user_template["user_modified"] = True

ardupilot_methodic_configurator/frontend_tkinter_component_template_manager.py:135

  • Ensure that template entries always include a valid 'name' to avoid unexpected sorting orders when defaulting to an empty string.
component_templates = sorted(component_templates, key=lambda x: x.get("name", "").lower())

ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py:199

  • Double-check that using 'key in self.data.get("Components", {})' reliably identifies components for template controls; consider adding explicit component type validation to ensure proper behavior.
if is_toplevel and key in self.data.get("Components", {}):

@amilcarlucas
amilcarlucas force-pushed the dropdown_components branch 2 times, most recently from 25e63e3 to 83e1322 Compare March 21, 2025 17:19
amilcarlucas and others added 2 commits March 24, 2025 00:54
…ture

Adds a command line switch that allows saving component templates to the
system file to distribute them via git to other users.
@amilcarlucas
amilcarlucas requested a review from Copilot March 23, 2025 23:59

@amilcarlucas amilcarlucas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look good, I'll merge this now.
Please do add some more templates later

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds a new feature that lets users save vehicle component configurations as templates and easily select them via dropdown controls. Key changes include:

  • New methods in the backend for loading, merging, and saving system and user component templates.
  • A new ComponentTemplateManager class (and associated UI controls) for managing template selection and saving.
  • Updates to tests, CLI argument parsing, and architecture documentation to support the new template functionality.

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ardupilot_methodic_configurator/backend_filesystem_vehicle_components.py Added methods for loading and saving component templates with support for system and user templates.
ardupilot_methodic_configurator/frontend_tkinter_component_template_manager.py Introduced a new template manager class to display dropdowns and save buttons for component templates.
tests/test_frontend_tkinter_component_template_manager.py Extended test coverage for new template functionalities.
tests/test_frontend_tkinter_component_editor_base.py Added tests for retrieving component data from GUI and integrating template controls.
ARCHITECTURE.md Updated to reflect the new template-based component management feature.
Various files (backend_filesystem.py, frontend_tkinter_component_editor.py, update_vehicle_templates.py, etc.) Updated constructor arguments and CLI parsers to include the new “save_component_to_system_templates” flag.
Files not reviewed (1)
  • tests/test_backend_filesystem.py: Language not supported
Comments suppressed due to low confidence (2)

ardupilot_methodic_configurator/frontend_tkinter_component_editor.py:786

  • [nitpick] The derive_initial_template_name method in ComponentEditorWindow returns a default template name based on manufacturer and model, which differs from the base implementation returning an empty string. Consider consolidating the logic for template name derivation to ensure consistent behavior across editors.
def derive_initial_template_name(self, component_data: dict[str, Any]) -> str:

ardupilot_methodic_configurator/backend_filesystem.py:797

  • [nitpick] The help message for '--save-component-to-system-templates' could explicitly mention that its default value is False for better clarity.
parser.add_argument("--save-component-to-system-templates", action="store_true", ...

@amilcarlucas
amilcarlucas merged commit 7dd9578 into ArduPilot:master Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants