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

How to turn scaling off? Screen grab always has scaling with factor 2 applied #257

Open
orange-puff opened this issue Apr 30, 2023 · 7 comments · May be fixed by #258
Open

How to turn scaling off? Screen grab always has scaling with factor 2 applied #257

orange-puff opened this issue Apr 30, 2023 · 7 comments · May be fixed by #258

Comments

@orange-puff
Copy link

General information:

  • OS name: macOS Big Sur

  • OS version: 11.1

  • OS architecture: 64 bits

  • Resolutions:

    • Monitor 1: 2560x1600
  • Python version: 3.10.7

  • MSS version: 9.0.1

Description

When I run the following code:

import pyautogui
import mss

w, h = pyautogui.size()
with mss.mss() as sct:
    monitor = {"top": 0, "left": 0, "width": w, "height": h}
    mss_image = sct.grab(monitor)
    print(f'({w}, {h}) ({mss_image.width}, {mss_image.height})')

it results in
(1440, 900) (2880, 1800)

This interferes with my ability to then use pyautogui to find certain pixels with a given color and click them. Is there a way to turn scaling off in mss, or is this perhaps a macOS issue?

@BoboTiG
Copy link
Owner

BoboTiG commented Apr 30, 2023

It's funny, I was thinking about that exact behavior.
I think I will make the auto-scaling an optional feature rather than the default behavior. It will also fix several issues I saw here, and there, like:

I will try something and rely on the CI (and maybe you) for the testing, since I don't own a Mac machine yet.

@BoboTiG BoboTiG linked a pull request Apr 30, 2023 that will close this issue
4 tasks
@orange-puff
Copy link
Author

orange-puff commented May 1, 2023

I would be happy to test this.
Also, sorry for the off topic question. Is there a link to any documentation of why mss is so fast compared to pillow or pyautogui? It's performing much better on my computer than either of them.

@orange-puff
Copy link
Author

orange-puff commented May 5, 2023

I was hoping to test this locally, but the docs look outdated, https://python-mss.readthedocs.io/developers.html python -m pip install -r tests-requirements.txt but this file doesn't seem to exist.

Is there an updated guide for getting things running locally? I am also getting

    from . import __version__
ImportError: attempted relative import with no known parent package

when attempting to run main.py. I've researched this error extensively in other contexts and I cannot find a working solution for it

@BoboTiG
Copy link
Owner

BoboTiG commented May 5, 2023

Thanks for pointing the documentation issue, it's broken since my last commit, and I'll fix it.

To run main:

cd src
python -m mss

You should remove any older MSS installation first:

python -m pip uninstall -y mss

And here is the correct installation command:

python -m pip install -e '.[test]'

@orange-puff
Copy link
Author

So I did this, then added

import pyautogui
if __name__ == "__main__":  # pragma: nocover
    w, h = pyautogui.size()
    print(w,h)
    with mss() as sct:
        monitor = {"top": 0, "left": 0, "width": w, "height": h}
        mss_image = sct.grab(monitor)
        print(f'({w}, {h}) ({mss_image.width}, {mss_image.height})')

to src/mss/__main__.py
and I get

1440 900
zsh: segmentation fault  python3 -m mss

@orange-puff
Copy link
Author

The line that is throwing the exception is; https://github.com/BoboTiG/python-mss/blob/main/src/mss/darwin.py#L181
If I rerun I also get
zsh: bus error python3 -m mss
zsh: illegal hardware instruction python3 -m mss

Without knowing what the underlying dll looks like, it's not easy to go deeper. But I will try to look at the arg and how the PR might have contributed

@BoboTiG
Copy link
Owner

BoboTiG commented May 6, 2023

Actually the PR isn't working. I quickly tried something, but without a Mac machine it's complex.
I will receive a Mac machine by the next week, and will be able to work on it then.

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

Successfully merging a pull request may close this issue.

2 participants