Will now detect the screen scaling ratio and adjust#63
Will now detect the screen scaling ratio and adjust#63damies13 wants to merge 1 commit intoeficode:masterfrom
Conversation
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
| y = y / 2 | ||
| if self.pixel_ratio == 0.0: | ||
| self.__get_pixel_ratio() | ||
| if self.pixel_ratio>1: |
There was a problem hiding this comment.
If this were changed to if not isclose(self.pixel_ratio, 1.0, abs_tol=1e-3):, would this allow it to work for large (>1) or small (<1) scaling ratios?
Also, from math import isclose would be needed above.
There was a problem hiding this comment.
If this were changed to if not isclose(self.pixel_ratio, 1.0, abs_tol=1e-3):, would this allow it to work for large (>1) or small (<1) scaling ratios?
Actually I could simply do:
if self.pixel_ratio>0 and self.pixel_ratio != 1.0:
To cover the same case, then there would be no need to import isclose.
I have no idea how we could test it though? Windows only allows scaling from 100% to 500% so would never have a scaling ratio below 1 and MacOS only had 100% for non retina displays and 200% for retina displays no other scaling ratios, I'm not aware of any linux distro that supports scaling below 100% either.
I could actually just use too
if self.pixel_ratio>0:
as any number divided by 1 will give the same number, but it seems a waste of processing power to do divide by 1 twice, but it might make the code easier to read?
let me know the preferred option and i'll update the PR.
Dave.
|
Hi, I found this RFW library quite useful! Thanks for this! :) About this PR. I am really struggling not only with Retina display, but with several different external displays which uses different pixel densities. I see this is a two year old pull request, but it would help me a lot if your PR would be merged. Since no further comment arrived within this 2 years, I would suggest to use your solution, Dave, and go with the
Thanks and regard, |
|
Hi Zoltan, I'm not sure if this library is being maintained? not a single PR I submitted has been used nor any other updates from anyone else. which is sad as I like this Library too, I just don't have the time to maintain it myself, I have 3 other projects to maintain, other wise I'd fork it and update it. But if someone starts maintaining this library I'd be happy to help fix bugs when I have time. Dave. |
My proposed fix for Issue #62
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 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.