Skip to content

Use the refractored code#524

Merged
amilcarlucas merged 1 commit into
masterfrom
use_component_data_model
Jun 12, 2025
Merged

Use the refractored code#524
amilcarlucas merged 1 commit into
masterfrom
use_component_data_model

Conversation

@amilcarlucas
Copy link
Copy Markdown
Collaborator

@amilcarlucas amilcarlucas commented Jun 1, 2025

This pull request introduces significant refactoring and enhancements to the ComponentEditorWindowBase class in the ardupilot_methodic_configurator module, focusing on improving code modularity, readability, and functionality. Key changes include adopting a data model for managing vehicle components, restructuring the UI setup process, and enhancing the handling of component data. Additionally, a new utility function for displaying warning messages has been added.

Refactoring and Data Model Integration:

  • Introduced ComponentDataModel to encapsulate logic for managing vehicle components, replacing direct manipulation of raw JSON data ([[1]](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL70-R126), [[2]](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL168-R257)).
  • Replaced nested dictionaries with type aliases (ComponentPath, ComponentValue, etc.) for improved readability and type safety ([[1]](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL22-R33), [[2]](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL368-R399)).

UI Enhancements:

  • Modularized UI setup by splitting it into methods like _setup_window, _create_intro_frame, _create_scroll_frame, and _create_save_frame for better maintainability ([[1]](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL70-R126), [[2]](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabR136-R177)).
  • Added a scrollable frame and dynamic UI elements to support better user interaction and scalability ([ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.pyR136-R177](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabR136-R177)).

Improved Component Data Handling:

  • Refactored methods for extracting, validating, and saving component data to leverage the new data model, ensuring consistency and reducing redundant code ([[1]](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL266-R368), [[2]](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL398-R427)).
  • Enhanced the set_component_value_and_update_ui method to update both the data model and UI elements seamlessly ([ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.pyL168-R257](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL168-R257)).

Utility Additions:

  • Added a show_warning_message function in frontend_tkinter_show.py to display warning dialogs, complementing existing error dialogs ([ardupilot_methodic_configurator/frontend_tkinter_show.pyR31-R40](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-2d5cb4788c5ffbd42523cde39b0448b88935e67ddf3d6699ef0d355c157b4270R31-R40)).

Code Cleanup:

  • Removed unused or redundant methods, such as update_json_data and derive_initial_template_name, as their functionality is now handled by the data model ([ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.pyL266-R368](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL266-R368)).
  • Simplified widget addition logic by consolidating _add_widget, _add_non_leaf_widget, and _add_leaf_widget methods ([[1]](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL200-R274), [[2]](https://github.com/ArduPilot/MethodicConfigurator/pull/524/files#diff-7f3397e9355b08ace5f25e2a3f881656ea2b7b934ae6de417f3cac9e9e320dabL229-R320)).

Copilot AI review requested due to automatic review settings June 1, 2025 00:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 introduces several refinements and updates across tests, configuration files, UI modules, and the data model to support the refractored code. Key changes include:

  • Updating test expectations and component value assignments in test_data_model_vehicle_components.py.
  • Refining versioning and protocol definitions in vehicle_components.json and data_model_vehicle_components.py.
  • Restructuring UI setup and enhancing type annotations in the frontend_tkinter_component_editor_base.py module.
  • Adding new VS Code configuration settings and debug launch configurations.

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_data_model_vehicle_components.py Updated test data to include the new ESC option under Battery Monitor and adjusted value assignments.
ardupilot_methodic_configurator/vehicle_templates/ArduCopter/diatone_taycan_mxc/4.6.x-params/vehicle_components.json Revised firmware version format for consistency.
ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py Reorganized UI initialization and enhanced type annotations, with a potential spelling correction in a constant name.
ardupilot_methodic_configurator/data_model_vehicle_components.py Updated protocol definitions and helper functions, with potential duplicate constant redefinitions and tuple construction issues.
.vscode/settings.json & launch.json Minor configuration updates for improved debugging and formatting.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
6615 4776 72% 60% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
ardupilot_methodic_configurator/frontend_tkinter_component_editor.py 88% 🟢
ardupilot_methodic_configurator/frontend_tkinter_component_editor_base.py 52% 🟢
ardupilot_methodic_configurator/frontend_tkinter_show.py 90% 🟢
TOTAL 77% 🟢

updated for commit: 4e525e3 by action🐍

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2025

Test Results

    2 files  ±  0      2 suites  ±0   1m 33s ⏱️ +5s
1 157 tests + 58  1 154 ✅ + 56  3 💤 +2  0 ❌ ±0 
2 314 runs  +116  2 308 ✅ +112  6 💤 +4  0 ❌ ±0 

Results for commit 4e525e3. ± Comparison against base commit 2decb54.

This pull request removes 19 and adds 77 tests. Note that renamed tests count towards both.
tests.test_frontend_tkinter_component_editor_base ‑ test_add_argparse_arguments
tests.test_frontend_tkinter_component_editor_base ‑ test_add_entry_or_combobox
tests.test_frontend_tkinter_component_editor_base ‑ test_add_template_controls
tests.test_frontend_tkinter_component_editor_base ‑ test_add_widget_dict
tests.test_frontend_tkinter_component_editor_base ‑ test_add_widget_leaf
tests.test_frontend_tkinter_component_editor_base ‑ test_derive_initial_template_name
tests.test_frontend_tkinter_component_editor_base ‑ test_get_component_data_from_gui
tests.test_frontend_tkinter_component_editor_base ‑ test_main_function
tests.test_frontend_tkinter_component_editor_base ‑ test_on_closing_cancel
tests.test_frontend_tkinter_component_editor_base ‑ test_on_closing_no_save
…
tests.test_frontend_tkinter_component_editor.TestArgumentParser ‑ test_argument_parser
tests.test_frontend_tkinter_component_editor.TestArgumentParser ‑ test_argument_parser_with_skip_component_editor
tests.test_frontend_tkinter_component_editor.TestComponentEditorWindow ‑ test_add_entry_or_combobox_battery_chemistry
tests.test_frontend_tkinter_component_editor.TestComponentEditorWindow ‑ test_add_entry_or_combobox_fc_connection_type
tests.test_frontend_tkinter_component_editor.TestComponentEditorWindow ‑ test_add_entry_or_combobox_optional_field
tests.test_frontend_tkinter_component_editor.TestComponentEditorWindow ‑ test_add_entry_or_combobox_with_combobox_values
tests.test_frontend_tkinter_component_editor.TestComponentEditorWindow ‑ test_get_validate_function
tests.test_frontend_tkinter_component_editor.TestComponentEditorWindow ‑ test_init
tests.test_frontend_tkinter_component_editor.TestComponentEditorWindow ‑ test_set_fc_manufacturer_invalid
tests.test_frontend_tkinter_component_editor.TestComponentEditorWindow ‑ test_set_fc_manufacturer_valid
…

♻️ This comment has been updated with latest results.

@amilcarlucas amilcarlucas force-pushed the use_component_data_model branch 7 times, most recently from 424eec5 to a21eacb Compare June 12, 2025 16:15
Also adds many pytests
Updates the architecture documentation
@amilcarlucas amilcarlucas force-pushed the use_component_data_model branch from af2f848 to 4e525e3 Compare June 12, 2025 21:37
@amilcarlucas amilcarlucas merged commit 63d960a into master Jun 12, 2025
23 of 24 checks passed
@amilcarlucas amilcarlucas deleted the use_component_data_model branch June 12, 2025 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants