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

Fix bottom display when pattern is near the edge #737

Merged

Conversation

jonathanperret
Copy link
Contributor

@jonathanperret jonathanperret commented Dec 4, 2024

Problem

Fixes #733.

Proposed solution

Capture d’écran 2024-12-04 à 23 41 24

The bug was caused by an edge case where the midline value was apparently wrong but unfortunately I could not really make sense of what that value was supposed to represent. Instead I changed the code to use the index of the first patterning needle, along with the machine width, to compute the displayed (orange/green) needle numbers.

Along the way I simplified the logic to transmit the current status to the UI. Some values were transported as extra arguments alongside the Status object; moving them into the Status class made the code more regular. I also removed a couple of parameters that were entirely unused.

I also fixed what appeared to be a logic error that caused Pass 1 to be shown in row headers in single-bed mode (where each row always has a single pass), and never be shown on ribber modes (where multiple passes are required per pattern row) — interestingly this appears to be a regression of a once-fixed issue: #548. Now single-bed knitting shows no pass number, and multi-pass modes show Pass x/n.

For code review, a note on the changes in knitprogress.py: most of the lines that are modified have no change in logic, but the configured style checker (flake8), which apparently had never been run on that file, required splitting a number of lines before I could commit the file. Sorry for the churn.

How to test

Here's a test release built from the code in this PR: https://github.com/jonathanperret/ayab-desktop/releases/tag/1.0.0-knitprogress-1

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new attributes in the status management system: machine_width, knit_start_needle, and passes_per_row.
  • Improvements

    • Streamlined the Control, KnitProgress, and SignalSender classes for better status management and code readability.
    • Simplified signal emission in the SignalReceiver class to enhance clarity.
  • Bug Fixes

    • Removed unnecessary parameters in various methods to ensure smoother operation and reduce complexity.

Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

The pull request introduces changes across several classes related to knitting operations. The Control class has removed the midline attribute and updated the logic for determining the knitting start needle. The Status class now includes new attributes for machine width, knitting start needle, and passes per row, while removing the mirror attribute. The KnitProgress, SignalReceiver, and SignalSender classes have been updated to simplify method signatures and improve code readability, particularly by eliminating the midline parameter from several methods.

Changes

File Path Change Summary
src/main/python/main/ayab/engine/control.py Removed midline attribute; updated start method to directly assign self.status.knit_start_needle; modified reset_status method to include new status attributes.
src/main/python/main/ayab/engine/engine.py Renamed local variable data to status_copy in __handle_status method for clarity.
src/main/python/main/ayab/engine/status.py Added attributes: machine_width, knit_start_needle, passes_per_row; removed mirror attribute. Updated copy method to include new attributes.
src/main/python/main/ayab/knitprogress.py Updated method signatures to remove midline parameter; simplified logic in update_progress, load_columns_from_status, and other methods.
src/main/python/main/ayab/signal_receiver.py Changed knit_progress_updater signal to accept only Status object.
src/main/python/main/ayab/signal_sender.py Removed ColorSymbolType import; simplified method signatures for emit_progress_bar_updater and emit_knit_progress_updater.

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 522d1a6 and 3baa653.

📒 Files selected for processing (6)
  • src/main/python/main/ayab/engine/control.py (1 hunks)
  • src/main/python/main/ayab/engine/engine.py (1 hunks)
  • src/main/python/main/ayab/engine/status.py (3 hunks)
  • src/main/python/main/ayab/knitprogress.py (7 hunks)
  • src/main/python/main/ayab/signal_receiver.py (1 hunks)
  • src/main/python/main/ayab/signal_sender.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/main/python/main/ayab/engine/engine.py
  • src/main/python/main/ayab/signal_receiver.py
  • src/main/python/main/ayab/engine/control.py
  • src/main/python/main/ayab/signal_sender.py
  • src/main/python/main/ayab/engine/status.py
  • src/main/python/main/ayab/knitprogress.py

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

@jonathanperret jonathanperret force-pushed the fix-progress-display branch 2 times, most recently from ff6b346 to 4501d1b Compare December 4, 2024 21:23
@jonathanperret jonathanperret marked this pull request as ready for review December 4, 2024 22:42
@jonathanperret jonathanperret requested a review from dl1com December 4, 2024 22:43
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: 1

🧹 Outside diff range and nitpick comments (3)
src/main/python/main/ayab/engine/control.py (1)

153-161: Architectural improvement: Better separation of concerns

The consolidation of display-related values (machine_width, knit_start_needle, passes_per_row) into the Status class represents a significant improvement in code organization. This change:

  1. Reduces coupling between display logic and control logic
  2. Makes the code more maintainable by centralizing display-related state
  3. Simplifies the logic by removing the indirect midline calculation

The new architecture will make it easier to handle future display-related changes.

src/main/python/main/ayab/knitprogress.py (2)

58-65: Consider making the display geometry configurable

The table widget has a fixed geometry (700x220) which might not be optimal for different screen sizes and resolutions. Consider making these dimensions configurable through preferences or responsive to the parent widget's size.


210-216: Use f-strings consistently for string formatting

For better readability and consistency, consider using f-strings instead of string concatenation.

-            info_text = (
-                info_text
-                + " "
-                + tr_("KnitProgress", "Color")
-                + " "
-                + status.color_symbol
-            )
+            info_text = f'{info_text} {tr_("KnitProgress", "Color")} {status.color_symbol}'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4501d1b and 120cf6c.

📒 Files selected for processing (6)
  • src/main/python/main/ayab/engine/control.py (1 hunks)
  • src/main/python/main/ayab/engine/engine.py (1 hunks)
  • src/main/python/main/ayab/engine/status.py (3 hunks)
  • src/main/python/main/ayab/knitprogress.py (7 hunks)
  • src/main/python/main/ayab/signal_receiver.py (1 hunks)
  • src/main/python/main/ayab/signal_sender.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/main/python/main/ayab/engine/engine.py
  • src/main/python/main/ayab/signal_receiver.py
  • src/main/python/main/ayab/signal_sender.py
  • src/main/python/main/ayab/engine/status.py
🔇 Additional comments (6)
src/main/python/main/ayab/engine/control.py (3)

153-154: LGTM: Machine width properly stored in status

This change appropriately moves the machine width into the Status class, supporting the consolidation of display-related values.


161-161: LGTM: Pass count properly stored in status

This change appropriately stores the passes per row in the Status class, supporting the improved display of pass numbers in multi-pass modes.


155-160: Core fix: Improved needle position calculation

The new logic correctly handles needle position calculations by:

  1. Using pattern.knit_start_needle for modes with flanking needles
  2. Using start_needle directly for single-bed mode, which doesn't emit extra needles

This change directly fixes the blank display issue when edges are wider than the image.

Let's verify the impact of this change on the display calculations:

✅ Verification successful

Needle position calculation changes verified as correct

The codebase analysis confirms that the changes to knit_start_needle calculation are consistent with the overall needle position handling:

  1. In pattern.py, knit_start_needle is properly managed as part of the pattern's core properties and is used for alignment calculations
  2. In knitprogress.py, the display logic correctly uses knit_start_needle for needle position visualization
  3. The special case for single-bed mode (using start_needle directly) aligns with the comment about not emitting extra needles

The changes maintain consistency with both the display system and the knitting engine's needle position calculations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of knit_start_needle and related display calculations

# Check for any other references to midline or related display calculations
rg -A 3 "knit_start_needle|start_needle|display.*needle" --type python

# Check for any potential edge cases in tests
rg -A 5 "test.*display.*edge|test.*needle.*position" --type python

Length of output: 203


Script:

#!/bin/bash
# Let's try without file type filtering since python extension wasn't recognized
# Check for any other references to knit_start_needle and start_needle
rg -A 3 "knit_start_needle|start_needle"

# Look for test files that might verify edge cases
fd "test.*\.py$" --exec rg -A 5 "test.*display.*edge|test.*needle.*position" {}

Length of output: 20470

src/main/python/main/ayab/knitprogress.py (3)

96-98: LGTM: Status comparison properly includes new attributes

The addition of knit_start_needle, machine_width, and passes_per_row to the status comparison ensures the display updates correctly when these critical values change.


203-206: LGTM: Pass display logic correctly handles single-bed mode

The pass information is now only displayed when passes_per_row > 1, which correctly implements the requirement to omit pass numbers in single-bed mode.


136-150: Verify the needle number calculation logic

The new logic for calculating needle positions uses knit_start_needle and machine_width instead of midline. This should fix the blank display issue when patterns are near the edge.

Let's verify this fixes the reported issue:

✅ Verification successful

Based on the search results, I can now generate the final response. The code shows consistent needle position calculation logic across the codebase:

Needle position calculation is correctly implemented

The new logic for calculating needle positions is consistent throughout the codebase:

  • knit_start_needle represents the absolute needle position
  • needle_number_from_r1 = needle - machine_width // 2 correctly calculates the relative position from the machine center (R1)
  • This calculation is used consistently in both the progress display and header labeling
  • The logic properly handles both positive (green) and negative (orange) needle numbers

The implementation aligns with the machine's physical characteristics where:

  • The machine center is at machine_width // 2
  • Left side needles (negative numbers) are displayed in orange
  • Right side needles (positive numbers) are displayed in green
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of needle position calculations
# to ensure consistent logic across the codebase
rg -l "machine_width|knit_start_needle" | \
  xargs ast-grep --pattern 'needle = $x + $y' -j

Length of output: 246


Script:

#!/bin/bash
# Let's search for needle position calculations with ripgrep
rg -A 5 -B 5 "knit_start_needle" 

# Also search for machine_width usage
rg -A 5 -B 5 "machine_width"

Length of output: 29552

src/main/python/main/ayab/knitprogress.py Show resolved Hide resolved
@dl1com
Copy link
Contributor

dl1com commented Dec 9, 2024

As this fixes not only #733 but also tweaks some more things, I'd love to get some feedback of testing.

@jonathanperret
Copy link
Contributor Author

As this fixes not only #733 but also tweaks some more things, I'd love to get some feedback of testing.

Agreed, more feedback is always welcome. @Adrienne200 did you get a chance to try this one out maybe?

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 (1)
src/main/python/main/ayab/knitprogress.py (1)

232-242: Consider using integer division operator

While the current implementation using floor() is correct, you could simplify it by using Python's integer division operator // for the HSL calculations:

-                floor(background_color.hslHue() * 0.85),
-                floor(background_color.hslSaturation() * 0.85),
+                background_color.hslHue() * 85 // 100,
+                background_color.hslSaturation() * 85 // 100,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 120cf6c and 522d1a6.

📒 Files selected for processing (6)
  • src/main/python/main/ayab/engine/control.py (1 hunks)
  • src/main/python/main/ayab/engine/engine.py (1 hunks)
  • src/main/python/main/ayab/engine/status.py (3 hunks)
  • src/main/python/main/ayab/knitprogress.py (7 hunks)
  • src/main/python/main/ayab/signal_receiver.py (1 hunks)
  • src/main/python/main/ayab/signal_sender.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/main/python/main/ayab/engine/engine.py
  • src/main/python/main/ayab/signal_receiver.py
  • src/main/python/main/ayab/signal_sender.py
  • src/main/python/main/ayab/engine/control.py
  • src/main/python/main/ayab/engine/status.py
🧰 Additional context used
📓 Learnings (1)
src/main/python/main/ayab/knitprogress.py (1)
Learnt from: jonathanperret
PR: AllYarnsAreBeautiful/ayab-desktop#737
File: src/main/python/main/ayab/knitprogress.py:267-270
Timestamp: 2024-12-04T23:30:20.505Z
Learning: In the `onStitchSelect` method in `src/main/python/main/ayab/knitprogress.py`, avoid suggesting replacing magic numbers with named constants unless it fundamentally improves the logic, as the user prefers to leave them as is.
🔇 Additional comments (5)
src/main/python/main/ayab/knitprogress.py (5)

58-65: LGTM: Header configuration improvements

The header configuration changes improve the UI layout and interaction behavior by:

  • Setting fixed resize mode for headers
  • Disabling section clicks
  • Using preferences for section size

96-98: LGTM: Enhanced state tracking for edge display fixes

Added tracking of knit_start_needle, machine_width, and passes_per_row to properly detect UI state changes, which is essential for fixing the edge display issues mentioned in PR #733.


136-150: LGTM: Improved needle position calculation

The new implementation correctly calculates needle positions using knit_start_needle and machine_width instead of midline, which fixes the edge display issues. The code is now more maintainable and logically clearer.


203-206: LGTM: Fixed pass number display logic

The pass number is now correctly displayed only when passes_per_row > 1, addressing the PR objective of fixing pass number display in single-bed and ribber modes.


267-270: LGTM: Color comparison logic

The color comparison logic is working as intended.

Values of `row_multiplier` and `midline` were passed along
with `status` to UI update events, move them into `status`.

Pass `knit_start_needle` and `machine_width` properties
instead of `midline` in the hope of making needle number
computations clearer.
@dl1com dl1com force-pushed the fix-progress-display branch from 522d1a6 to 3baa653 Compare December 13, 2024 07:50
@jonathanperret
Copy link
Contributor Author

Reported working on Discord by @Adrienne200 .

@dl1com dl1com merged commit 5b80726 into AllYarnsAreBeautiful:main Dec 13, 2024
3 checks passed
@jonathanperret jonathanperret deleted the fix-progress-display branch December 13, 2024 08:35
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.

[BUG] Lower display is blank with edges wider than image
2 participants