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

Screen scaling factor (Screen Scaling on Windows / Retina Display on Mac) #62

Open
damies13 opened this issue Feb 26, 2022 · 1 comment

Comments

@damies13
Copy link

Well this is frustrating,

I was trying to set up some basic tests for issues #60 and #61 before I start making changes and I encountered the "retina display issue" when trying to use Click Image.

Did a little research, and found that the upstream pyautogui is the cause, there is a known issue for this #589 where a workaround is provided so they closed the issue, so it looks like if we want IHL to behave as users would expect then we need to handle it by implementing the workaround.

I also found this issue impacts Windows machines when screen scaling is enabled, while on Mac's the Retina display means the co-ordinates are always double (200%) what they need to be, with windows the scaling factor can vary between 100% and 500% times with typical values being 125%, 150%, 175%, 200%

Fortunately the workaround provided pixelRatio = pyautogui.screenshot().size[0]/pyautogui.size().width does give us the ratio, so it's a simple matter of dividing the x and y values from pyautogui by the pixelRatio and returning the new co-ordinates.

Also fortunately the workaround doesn't need any additional python modules so it's a minimal impact.

I will submit a fix for this issue soon.

damies13 added a commit to damies13/robotframework-imagehorizonlibrary that referenced this issue Feb 26, 2022
This update will now detect the screen scaling ratio and adjust accordingly. I tested it using "tests/atest/calculator.robot" on a mac with a Retina display running OSX 12.0.1 I don't have a windows machine to test on, but based on comments in [pyautogui issue #589](asweigart/pyautogui#589) this should work for the various windows scaling ratios.
This replaces the self.has_retina which wasn't working as it was returning false on my machine even though it does indeed have a retina display.
__get_pixel_ratio should only get called the first time _locate is called, that was my experience in testing, though perhaps it should be called every time as windows users could potentially change their display scaling during the test. Also I don't know of an OS that supports it now but I guess it's possible in the future an OS may have a scaling factor less than 100% and this change won't support that either.
Issue eficode#62
@damies13
Copy link
Author

My PR was tested on a mac with a Retina display running OSX 12.0.1, using tests/atest/calculator.robot from this project. I did need higher res images for the elements, I've attached these below if anyone wants them, I also needed a 100ms sleep after the click before the copy ( Sleep 0.1 from builtin library).

inputs_macos or_button_macos close_button_macos
inputs_macos or_button_macos close_button_macos

noubar added a commit to noubar/Robotframework-ImageLibrary that referenced this issue Oct 17, 2024
commit 6cc09dd
Author: Dave Amies <damies13@gmail.com>
Date:   Sat Feb 26 14:09:19 2022 +1000

    My tweaks to atest to make it run locally

commit 2dd9d9d
Author: Dave Amies <damies13@gmail.com>
Date:   Sat Feb 26 14:07:38 2022 +1000

    Will now detect the screen scaling ratio and adjust

    This update will now detect the screen scaling ratio and adjust accordingly. I tested it using "tests/atest/calculator.robot" on a mac with a Retina display running OSX 12.0.1 I don't have a windows machine to test on, but based on comments in [pyautogui issue #589](asweigart/pyautogui#589) this should work for the various windows scaling ratios.
    This replaces the self.has_retina which wasn't working as it was returning false on my machine even though it does indeed have a retina display.
    __get_pixel_ratio should only get called the first time _locate is called, that was my experience in testing, though perhaps it should be called every time as windows users could potentially change their display scaling during the test. Also I don't know of an OS that supports it now but I guess it's possible in the future an OS may have a scaling factor less than 100% and this change won't support that either.
    Issue eficode#62
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

No branches or pull requests

1 participant