pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
777 stars 123 forks source link

Incorrect window size when import pywinauto #2752

Closed LondonClass closed 4 months ago

LondonClass commented 4 months ago

Environment:

You can get some of this info from the text that pops up in the console when you run a pygame program.

Set the scaling and layout settings of Windows to 150% pywinauto version:0.6.8

Current behavior:

After importing pywinauto, the scaling of the pygame window is no longer affected by Windows settings. The actual window size is approximately 533*400.

Expected behavior:

The scaling of the pygame window is affected by Windows settings. Window size is 800*600.

Test code


import pygame
import sys
import pywinauto #When not importing pywinauto, errors will not occur

pygame.init()
WIN = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Pygame Example")

def main():
    run = True
    while run:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False

        WIN.fill((255, 255, 255))
        pygame.draw.rect(WIN, (0, 0, 255), (50, 50, 50, 50))
        pygame.display.update()

    pygame.quit()
    sys.exit()
if __name__ == "__main__":
    main()
Starbuck5 commented 4 months ago

How is this a bug in pygame-ce?

I checked the source code of pywinauto, they're setting the whole process as DPI aware in one of their modules. Therefore any graphics controlled by the process would have this exact thing happen.

LondonClass commented 4 months ago

How is this a bug in pygame-ce?

I checked the source code of pywinauto, they're setting the whole process as DPI aware in one of their modules. Therefore any graphics controlled by the process would have this exact thing happen.

So it's like this.

Starbuck5 commented 4 months ago

Yep, I'm pretty sure!

You would achieve the same affect if instead of importing pywinauto, you declared dpi awareness yourself like in this example code: https://github.com/pygame-community/pygame-ce/blob/9111d6cc65926b85ab10f95db4d3573dbcf6eb4d/examples/prevent_display_stretching.py#L51

LondonClass commented 4 months ago

Yep, I'm pretty sure!

You would achieve the same affect if instead of importing pywinauto, you declared dpi awareness yourself like in this example code:

https://github.com/pygame-community/pygame-ce/blob/9111d6cc65926b85ab10f95db4d3573dbcf6eb4d/examples/prevent_display_stretching.py#L51

Thank you, I know how to solve it now.