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

AttributeError (event has no attribute state) in Python 3.10.6 #13

Open
kumoshk opened this issue Oct 20, 2022 · 4 comments
Open

AttributeError (event has no attribute state) in Python 3.10.6 #13

kumoshk opened this issue Oct 20, 2022 · 4 comments

Comments

@kumoshk
Copy link

kumoshk commented Oct 20, 2022

I installed Solarwolf with aptitude or apt on Xubuntu 22.04.1 (running the Cinnamon desktop), and I tried the same with the version on Github here, and I got the following error for line 78 in main.py:

AttributeError: 'Event' object has no attribute 'state'

I also figured out how to fix it:

Change

            elif event.type == pygame.ACTIVEEVENT:
                if event.state == 4 and event.gain:
                    #uniconified, lets try to kick the screen
                    pygame.display.update()
                elif event.state == 2:
                    if hasattr(game.handler, 'gotfocus'):
                        if event.gain:
                            game.handler.gotfocus()
                        else:
                            game.handler.lostfocus()
                continue

to

            elif event.type == pygame.ACTIVEEVENT:
                if "state" in event.__dict__:
                    if event.state == 4 and event.gain:
                        #uniconified, lets try to kick the screen
                        pygame.display.update()
                    elif event.state == 2:
                        if hasattr(game.handler, 'gotfocus'):
                            if event.gain:
                                game.handler.gotfocus()
                            else:
                                game.handler.lostfocus()
                continue

Some of the powerups don't look like I think they're supposed to, though. I'm not sure if that's related to this.

@kumoshk kumoshk changed the title AttributeError (event has no attribute state) AttributeError (event has no attribute state) in Python 3.10.6 Oct 20, 2022
@kumoshk
Copy link
Author

kumoshk commented Oct 20, 2022

Anyway, if the attribute doesn't exist, I'm guessing it's not 4 or 2! :)

@illume
Copy link
Member

illume commented Oct 28, 2023

I can't see this problem with the main branch and pygame 2.5.2.
So I guess it's fixed now.

Maybe it's an issue with an older pygame version.

(It's been a long time since the issue is reported. But if it's still a problem I'd like to know more info about your versions).

@illume illume closed this as completed Oct 28, 2023
@kumoshk
Copy link
Author

kumoshk commented Oct 28, 2023

I can't see this problem with the main branch and pygame 2.5.2. So I guess it's fixed now.

Maybe it's an issue with an older pygame version.

(It's been a long time since the issue is reported. But if it's still a problem I'd like to know more info about your versions).

Here's what I'm using:

Xubuntu 22.04.2 LTS (64-bit) (I guess my OS has been updated a bit since I submited it.)
Solarwolf version 1.5+dfsg1-5
python3-pygame version 2.1.2+dfsg-3

These are the versions installed with the package manager.

I haven't tried a newer version as of yet.

Here are my Python versions:
python3 version 3.10.6-1~22.04
python2 version 2.7.18-3 (I'm guessing it's using Python 3.x, but I'm telling you this information anyway.)

@illume illume reopened this Oct 29, 2023
@lcerf
Copy link

lcerf commented Feb 28, 2024

Same problem here, on Trisquel 11, which is based on Ubuntu 22.04 (hence essentially the same versions as kumoshk reported), if SolarWolf runs fullscreen. No problem in a window display. The (in)existence of ~/.solarwolf makes no difference.

Since my TV gives the resolution, I can see that, in full screen (which turns all black), SolarWolf first changes the resolution for 800x600p@60Hz, then goes back to 1920x1080p@60Hz (the resolution I use), then 800x600p@60Hz again and 1920x1080p@60Hz again, back on my desktop and showing me an error box explaining that 'Event' object has no attribute 'state'.

Avoiding the execution of the line testing event.state, for instance with kumoshk's additional test, the screen resolution goes 800x600p@60Hz, then 1920x1080p@60Hz, then 800x600p@60Hz again, SolarWolf's menu appear and the game runs fine, but the 4:3 display is horizontally stretched out to fill the entire 16:9 TV screen.

The same error occurs on my laptop screen, also using the resolution1920x1080@60Hz, with the fullscreen display, unless I avoid the execution of the line testing event.state. If I do avoid its execution, SolarWolf not only runs fine but the display is not stretched out, thanks to black strips (or whatever it is called) on the left and on the right of the screen.

Here is a video of the problem: https://dcc.ufmg.br/~lcerf/2024-02-28-15-48-22.webm (at the end of the OBS record, the video appears black, but the game was actually running).

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

3 participants