meerk40t / meerk40t

Hackable Laser software for K40 / GRBL / Fibre Lasers
MIT License
232 stars 62 forks source link

Node Drag+Drop - Fix crash / invalid any statement #2694

Closed jpirnay closed 4 days ago

jpirnay commented 4 days ago

Summary by Sourcery

Fix crash in the drag and drop functionality for image operations by correcting logic issues in the 'can_drop' method and refactor similar logic across multiple operation nodes for consistency.

Bug Fixes:

Enhancements:

sourcery-ai[bot] commented 4 days ago

Reviewer's Guide by Sourcery

This PR fixes drag and drop functionality across operation nodes, with a focus on image operations. The main changes involve correcting logic in the can_drop methods and adding proper element type definitions for image operations.

Updated class diagram for op_image.py

classDiagram
    class OpImage {
        +bool stopop
        +string label
        +bool overrule_dpi
        +tuple _allowed_elements_dnd
        +tuple _allowed_elements
        +list allowed_attributes
        +bool can_drop(drag_node)
        +void drop(drag_node, modify, flag)
    }
    note for OpImage "Added _allowed_elements_dnd and _allowed_elements attributes"

File-Level Changes

Change Details Files
Added allowed elements definitions for image operations
  • Added _allowed_elements_dnd and _allowed_elements tuples with 'elem image' type
  • Initialized new attributes in the init method
meerk40t/core/node/op_image.py
Fixed image operation drop validation logic
  • Simplified image drop validation to check for as_image attribute
  • Updated reference node validation to check node's as_image attribute
  • Removed unnecessary _allowed_elements_dnd type check
meerk40t/core/node/op_image.py
Fixed ancestor check logic across all operation types
  • Corrected the has_ancestor check to use the element instead of the drag_node
  • Standardized the ancestor check implementation across all operation types
meerk40t/core/node/op_image.py
meerk40t/core/node/op_cut.py
meerk40t/core/node/op_engrave.py
meerk40t/core/node/op_dots.py
meerk40t/core/node/op_raster.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).