-
Notifications
You must be signed in to change notification settings - Fork 34
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 "default knit side image" behavior #712
Fix "default knit side image" behavior #712
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this 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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (7)
- src/main/python/main/ayab/ayab.py (0 hunks)
- src/main/python/main/ayab/engine/options.py (4 hunks)
- src/main/python/main/ayab/engine/pattern.py (1 hunks)
- src/main/python/main/ayab/image.py (0 hunks)
- src/main/python/main/ayab/scene.py (3 hunks)
- src/main/python/main/ayab/signal_receiver.py (2 hunks)
- src/main/python/main/ayab/signal_sender.py (1 hunks)
Files not reviewed due to no reviewable changes (2)
- src/main/python/main/ayab/ayab.py
- src/main/python/main/ayab/image.py
Additional comments not posted (12)
src/main/python/main/ayab/signal_receiver.py (1)
56-56
: Verify the impact of the signal signature change.The change in the
image_reverser
signal signature to accept a boolean parameter is a good improvement. It allows the signal to directly control the image reversal state, potentially simplifying its usage.Please ensure that all connected slots have been updated to handle the boolean parameter correctly. You can use the following script to search for the signal usage:
Verification successful
Signal signature change verified successfully.
The
image_reverser
signal now correctly accepts a boolean parameter, and the connected slotset_image_reversed
handles it appropriately.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all connected slots handle the boolean parameter correctly. # Test: Search for the signal connection. Expect: Matching slot signatures. rg --type python -A 5 $'self.image_reverser.connect'Length of output: 82
Script:
#!/bin/bash # Description: Verify all connected slots handle the boolean parameter correctly. # Test: Search for the signal connection. Expect: Matching slot signatures. rg --type py -A 5 'self.image_reverser.connect'Length of output: 478
Script:
#!/bin/bash # Description: Locate the definition of 'set_image_reversed' to verify it accepts a boolean parameter. # Test: Search for the method definition. Expect: Method signature includes a boolean parameter. rg --type py 'def set_image_reversed'Length of output: 132
src/main/python/main/ayab/signal_sender.py (1)
89-90
: LGTM!The change to the
emit_image_reverser
method signature to include thereversed
parameter is consistent with the method's purpose and the signal it emits. This change allows the caller to specify the desired reversed state when emitting the signal, providing more control.Please verify that all callers of this method have been updated to pass the
reversed
parameter. You can use the following script to search for the method usage:Verification successful
Verification Successful!
All callers of
emit_image_reverser
have been updated to pass thereversed
parameter.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all callers of `emit_image_reverser` pass the `reversed` parameter. # Test: Search for the method usage. Expect: All occurrences pass the `reversed` parameter. rg --type python -A 5 $'emit_image_reverser'Length of output: 74
Script:
#!/bin/bash # Description: Verify all callers of `emit_image_reverser` pass the `reversed` parameter. # Test: Search for the method usage in Python files. Expect: All occurrences pass the `reversed` parameter. rg --type py -A 5 'emit_image_reverser\('Length of output: 1418
src/main/python/main/ayab/scene.py (4)
26-26
: LGTM!The import of the
QTransform
class fromPySide6.QtGui
is appropriate for implementing image transformations using Qt's capabilities.
71-71
: LGTM!The introduction of the
reverse_image
attribute as a boolean flag to track the reversed state of the image is a clear and concise way to manage image mirroring.
77-83
: LGTM!The addition of the
set_image_reversed
method is a clean and effective way to provide external control over thereverse_image
attribute. Calling therefresh
method after updating the attribute ensures that the displayed image is updated accordingly.
106-107
: LGTM!The conditional application of the horizontal flip transformation based on the
reverse_image
attribute is a clean and effective way to handle image mirroring. Utilizing Qt'sQTransform
class for image transformation is a good practice and provides flexibility in image manipulation.src/main/python/main/ayab/engine/pattern.py (1)
34-36
: LGTM! The code segment correctly handles image mirroring based on the configuration.The change introduces a conditional transposition of the input
image
based on theauto_mirror
attribute of theconfig
parameter. Ifconfig.auto_mirror
isTrue
, the image is flipped horizontally usingimage.transpose(Image.FLIP_LEFT_RIGHT)
. The resulting image (flipped or original) is then assigned to the__pattern
attribute.This change centralizes the image mirroring logic within the
Pattern
class initialization and ensures that the__pattern
attribute consistently holds the correctly mirrored image based on the configuration. It aligns with the objective of automatically flipping the image when the "Default Knit Side Image" preference is enabled.src/main/python/main/ayab/engine/options.py (5)
85-85
: LGTM!The addition of the
auto_mirror
attribute with a default value ofFalse
is a clean way to introduce this new feature without affecting existing functionality.
126-134
: LGTM!The
__auto_mirror_changed
method correctly updates theauto_mirror_icon
based on the state of the checkbox and emits theimage_reverser
signal with the current state of theauto_mirror
variable. This is the correct way to handle the change in the checkbox state and communicate it to other parts of the application.
190-190
: LGTM!Emitting the current state of
auto_mirror
instead of relying on the checkbox state directly is a good refactoring that improves the consistency and reliability of the code. This ensures that the state ofauto_mirror
is always in sync with the state of the checkbox.
Line range hint
192-208
: LGTM!The inclusion of the
auto_mirror
attribute in the dictionary representation returned by theas_dict
method is correct. This ensures that the state ofauto_mirror
is included when theOptionsTab
instance is serialized, which is necessary for consistency and completeness.
Line range hint
209-223
: LGTM!Reading the state of the
auto_mirror_checkbox
and updating theauto_mirror
attribute in theread
method is correct. This ensures that the state ofauto_mirror
is always in sync with the state of the checkbox when the configuration options are read from the UI elements.
83822aa
to
d59bdf1
Compare
There was a problem hiding this 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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- src/main/python/main/ayab/ayab.py (0 hunks)
- src/main/python/main/ayab/engine/options.py (4 hunks)
- src/main/python/main/ayab/engine/pattern.py (1 hunks)
- src/main/python/main/ayab/image.py (0 hunks)
- src/main/python/main/ayab/scene.py (3 hunks)
- src/main/python/main/ayab/signal_receiver.py (2 hunks)
- src/main/python/main/ayab/signal_sender.py (1 hunks)
- src/main/python/main/ayab/tests/test_control.py (1 hunks)
Files not reviewed due to no reviewable changes (2)
- src/main/python/main/ayab/ayab.py
- src/main/python/main/ayab/image.py
Files skipped from review as they are similar to previous changes (5)
- src/main/python/main/ayab/engine/options.py
- src/main/python/main/ayab/engine/pattern.py
- src/main/python/main/ayab/scene.py
- src/main/python/main/ayab/signal_receiver.py
- src/main/python/main/ayab/signal_sender.py
Additional context used
Ruff
src/main/python/main/ayab/tests/test_control.py
48-48: Undefined name
self
(F821)
48-48: Undefined name
auto_mirror
(F821)
d59bdf1
to
cd2cafa
Compare
Instead of Scene modifying AyabImage's internal image, it now reverses the image (if requested) only at render time. This makes it easier to avoid getting confused with how many times the image has been reversed.
cd2cafa
to
c2b9c5d
Compare
|
There was a problem hiding this 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 (1)
src/main/python/main/ayab/scene.py (1)
79-83
: LGTM: New method improves image reversal controlThe
set_image_reversed
method centralizes control over the image's reversed state, aligning with the PR objectives. It updates theimage_reversed
flag and refreshes the display, which is a clean approach to handling image transformations.Consider enhancing the method's docstring for clarity:
def set_image_reversed(self, image_reversed: bool) -> None: """ Sets the image reversed flag and refreshes the display. Args: image_reversed (bool): True to display the image reversed, False otherwise. """ self.image_reversed = image_reversed self.refresh()
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (8)
- src/main/python/main/ayab/ayab.py (0 hunks)
- src/main/python/main/ayab/engine/options.py (4 hunks)
- src/main/python/main/ayab/engine/pattern.py (1 hunks)
- src/main/python/main/ayab/image.py (0 hunks)
- src/main/python/main/ayab/scene.py (3 hunks)
- src/main/python/main/ayab/signal_receiver.py (2 hunks)
- src/main/python/main/ayab/signal_sender.py (1 hunks)
- src/main/python/main/ayab/tests/test_control.py (1 hunks)
Files not reviewed due to no reviewable changes (2)
- src/main/python/main/ayab/ayab.py
- src/main/python/main/ayab/image.py
Files skipped from review as they are similar to previous changes (5)
- src/main/python/main/ayab/engine/options.py
- src/main/python/main/ayab/engine/pattern.py
- src/main/python/main/ayab/signal_receiver.py
- src/main/python/main/ayab/signal_sender.py
- src/main/python/main/ayab/tests/test_control.py
Additional comments not posted (3)
src/main/python/main/ayab/scene.py (3)
26-26
: LGTM: Import changes align with new transformation approachThe addition of
QTransform
import and removal of the customTransform
import indicate a shift towards using Qt's built-in transformation capabilities. This change aligns well with the PR objectives of simplifying image handling.
71-71
: LGTM: Initialization changes improve image state managementThe addition of
self.image_reversed = False
introduces a flag to track the image's reversed state, which aligns with the PR objectives. Callingself.refresh()
at the end of initialization ensures that the scene is properly set up with the initial state. These changes contribute to a more robust image handling system.Also applies to: 77-77
Line range hint
1-214
: Summary: Significant improvements in image reversal handlingThe changes in
scene.py
successfully address the PR objectives related to fixing the "Default Knit Side Image" behavior. Key improvements include:
- Introduction of the
image_reversed
flag for tracking the image state.- New
set_image_reversed
method for centralized control of image reversal.- Simplified image transformation using Qt's
QTransform
in therefresh
method.These changes result in a more robust, flexible, and maintainable implementation of image reversal. The new approach should resolve the issues reported in #711, ensuring that images are correctly displayed based on the "Default Knit Side Image" preference.
To ensure the changes are correctly implemented across the codebase, please run the following verification script:
This script will help ensure that the new image reversal approach is consistently applied throughout the codebase and that there are no remnants of the old implementation.
Problem
Fixes #711.
Proposed solution
Instead of
Scene
modifyingAyabImage
's internalimage
, it now reverses the image (if requested) only at render time.Pattern
does likewise when generating the pattern from the image.This makes it easier to avoid getting confused with how many times the image has been reversed.
Summary by CodeRabbit
New Features
auto_mirror
option for automatic image mirroring based on user preference.Bug Fixes
Refactor