Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset start/stop needle sides when loading an image #735

Merged

Conversation

jonathanperret
Copy link
Contributor

@jonathanperret jonathanperret commented Dec 4, 2024

Problem

Fixes #732.

Proposed solution

Reset start/stop needle sides when loading an image.

How to test

Try this test release: https://github.com/jonathanperret/ayab-desktop/releases/tag/1.0.0-startstop-side-reset-1

Summary by CodeRabbit

  • New Features

    • Enhanced the OptionsTab to automatically select needle colors when image dimensions are set.
  • Bug Fixes

    • Improved validation logic for portname and needle color selection to prevent errors.
  • Improvements

    • Added restrictions on the number of colors based on selected modes, ensuring clarity in user options.

Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

The changes in this pull request focus on the OptionsTab class within the options.py file. Key modifications include updates to the set_image_dimensions method to automatically select specific colors for needle settings and enhancements to the validate method to improve validation logic regarding the portname attribute and the constraints on needle colors based on selected modes. These changes aim to refine the functionality and user interface consistency of the OptionsTab.

Changes

File Path Change Summary
src/main/python/main/ayab/engine/options.py - Updated set_image_dimensions to set default needle colors.
- Enhanced validate method for better checks on portname, needle definitions, and color restrictions.

Assessment against linked issues

Objective Addressed Explanation
Ensure settings reset when opening a new image (#732) The changes do not address the reset behavior when loading a new image.

Possibly related PRs

  • Fix "default knit side image" behavior #712: This PR modifies the OptionsTab class in options.py, which is directly related to the changes made in the main PR, as both involve modifications to the same file and class.

Suggested reviewers

  • dl1com

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

sonarqubecloud bot commented Dec 4, 2024

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
src/main/python/main/ayab/engine/options.py (2)

Line range hint 226-235: Consider adding validation for needle positions.

While the method correctly centers the needles, it would be good to validate that the calculated positions don't exceed the machine's physical limits:

 def set_image_dimensions(self, width: int, height: int) -> None:
     left_side = width // 2
+    # Ensure positions don't exceed machine limits
+    if width > self.machine.width:
+        raise ValueError(f"Image width {width} exceeds machine width {self.machine.width}")
     self.ui.start_needle_color.setCurrentIndex(0)  # orange
     self.ui.start_needle_edit.setValue(left_side)
     self.ui.stop_needle_color.setCurrentIndex(1)  # green
     self.ui.stop_needle_edit.setValue(width - left_side)
     self.ui.start_row_edit.setMaximum(height)

Line range hint 237-252: Enhance error messages and comments in validate method.

The validation logic is correct, but the error messages and comments could be more descriptive:

 def validate(self) -> tuple[Literal[False], str] | tuple[Literal[True], None]:
     """Validate configuration options."""
     if self.portname == "":
-        return False, "Please choose a valid port."
+        return False, "No port selected. Please choose a valid port."
-    # else
     if self.start_needle and self.stop_needle:
         if self.start_needle > self.stop_needle:
-            return False, "Invalid needle start and end."
+            return False, f"Start needle ({self.start_needle}) cannot be greater than stop needle ({self.stop_needle})."
-    # else
     if self.mode == Mode.SINGLEBED and self.num_colors >= 3:
         return False, "Singlebed knitting currently supports only 2 colors."
-    # else
     if self.mode == Mode.CIRCULAR_RIBBER and self.num_colors >= 3:
         return False, "Circular knitting supports only 2 colors."
-    # else
     return True, None
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5e781f1 and 3c0cdfb.

📒 Files selected for processing (1)
  • src/main/python/main/ayab/engine/options.py (1 hunks)
🔇 Additional comments (1)
src/main/python/main/ayab/engine/options.py (1)

231-231: LGTM! This change fixes the needle side reset issue.

The changes correctly address issue #732 by explicitly resetting the needle color selections when loading a new image:

  • Start needle color is set to orange (left side)
  • Stop needle color is set to green (right side)

Let's verify the color-to-side mapping assumptions:

Also applies to: 233-233

✅ Verification successful

Based on the search results, I can now provide a definitive response about the color-to-side mapping verification:

The color-to-side mapping is correctly implemented and consistent throughout the codebase.

The evidence confirms that:

  1. The NeedleColor enum defines ORANGE = 0 and GREEN = 1 (src/main/python/main/ayab/engine/options.py:270-271)
  2. This mapping is consistently used in the UI initialization (lines 99-100) and image loading (lines 231-233)
  3. The machine visualization in scene.py also uses orange for left side and green for right side (lines 92-97)
  4. The needle color selection directly affects the needle position calculation through NeedleColor.read() method (lines 281-284)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the color-to-side mapping in the codebase
# Expected: Consistent mapping of orange=left, green=right

# Check for any other needle color definitions or mappings
rg -n "(?i)(orange|green).*(left|right|needle)" --type py

# Check for related test cases
rg -n "test.*needle.*color" --type py

Length of output: 99


Script:

#!/bin/bash
# Let's try a broader search to understand the needle color setup

# Search for NeedleColor enum or class definition
ast-grep --pattern 'class NeedleColor'

# Search for needle color related UI setup
rg -n "needle_color" --type py -A 3 -B 3

# Search for any color constants or enums
rg -n "(?i)(ORANGE|GREEN)" --type py -A 2 -B 2

# Look for start/stop needle related code
rg -n "start_needle|stop_needle" --type py -A 2 -B 2

Length of output: 35265

@dl1com dl1com added this to the 1.0.0 milestone Dec 4, 2024
@dl1com dl1com merged commit 544245b into AllYarnsAreBeautiful:main Dec 4, 2024
3 checks passed
@jonathanperret
Copy link
Contributor Author

Thanks @dl1com, now waiting for @Adrienne200 's feedback before merging.

I see you've merged this already 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

[BUG] Opening a new image does not reset the Left and Right settings
3 participants