sugarlabs / Pippy

Pippy allows the student to examine, execute, and modify simple Python programs. In addition it is possible to write Python statements to play sounds, calculate expressions, or make simple text based interactive games.
GNU General Public License v2.0
11 stars 35 forks source link

Graphic examples fail to quit #87

Closed chimosky closed 1 year ago

chimosky commented 1 year ago

Graphic examples fail to exit full-screen window on esc so there's no way to quit the activity.

Pressing <ctrl>C has no effect, killing the python process or <ctrl>Q does quit the activity.

Noticed this happens mostly with the graphics examples.

This was seen in the logs;

(sugar-activity3:1209): Gtk-CRITICAL **: 09:09:56.307: gtk_notebook_get_tab_label: assertion 'list != NULL' failed

(sugar-activity3:1209): Gtk-CRITICAL **: 09:09:56.308: gtk_notebook_get_tab_label: assertion 'list != NULL' failed

(sugar-activity3:1209): Gtk-CRITICAL **: 09:09:56.310: gtk_notebook_get_tab_label: assertion 'list != NULL' failed
chimosky commented 1 year ago

@sparshg can you reproduce?

sparshg commented 1 year ago

I think this is working as intended, in graphics example with pygame, we have specified ESCAPE key in the event loop to exit the window that pygame spawns.

chimosky commented 1 year ago

I think this is working as intended, in graphics example with pygame, we have specified ESCAPE key in the event loop to exit the window that pygame spawns.

Can you test and reproduce? I know that the escape keys are handled in the pygame events loop.

sparshg commented 1 year ago

I tested with pygame 2.4.0, and the escape key is working fine. Some graphic examples have event loop such that they exit on any key press. I couldn't see any critical errors as in your logs, can you mention the example in which you see the bug?

chimosky commented 1 year ago

Noticed it with all the graphics examples.

quozl commented 1 year ago

Pippy does mix pygame with GTK but does it differently to Sugargame or OLPCgame, somehow. There may be some change in Sugargame that may need adopting in Pippy. A quick look at activity.py shows a class PyGameActivity and the forking of a process to hide the pygame file inside.

chimosky commented 1 year ago

Agreed, if we decide to use sugargame here we might need to tweak it to suit Pippy.

sparshg commented 1 year ago

Seeing the graphics example, they don't use PyGameActivity at all, (you can try removing PyGameActivity and it still works). Pippy just runs the pygame code, and pygame spawns the fullscreen window itself as it normally does if you would run it from terminal. So for that reason, the keys are entirely handled by the pygame event loop and not Pippy. There is no embedding of windows or anything happening here, unlike sugargame. Try removing the pygame.NOFRAME | pygame.FULLSCREEN flags and make the window size smaller, and you should see pygame window spawn normally like how it does if you run it without Pippy.

This means you can run the same code without Pippy, and should see the same result. (If you use pippy.pygame.next_frame() in your code, just include the definitions for next_frame and pause functions from library/pippy/game.py to run it without Pippy)

Now, I wanted to clarify, is the issue that the ESCAPE key is not able to exit the pygame's full-screen window in graphics examples? Because in the description you mentioned <ctrl>c not being able to exit the pygame's window, which should be the intended behaviour. We can change this by including <ctrl>c in pygame's event loop to exit the pygame window.

quozl commented 1 year ago

@sparshg, that's great testing, thanks.

I've just tested with Ubuntu 22.04 (jammy), with pygame 2.12, SDL 2.0.30 and Python 3.10.6, and no issues with any of the example programs in the graphics set. esc worked in each example where it was supposed to work.

chimosky commented 1 year ago

Now, I wanted to clarify, is the issue that the ESCAPE key is not able to exit the pygame's full-screen window in graphics examples? Because in the description you mentioned c not being able to exit the pygame's window, which should be the intended behaviour. We can change this by including c in pygame's event loop to exit the pygame window.

Yes the issue is that ESC isn't able to exit the pygame full-screen window in graphics examples. I mentioned the other key combinations as there's no other way to leave the full-screen window and exit the activity.

I've edited my opening comment.

I'm testing with live build.

quozl commented 1 year ago

I'm testing with live build.

Which one?

chimosky commented 1 year ago

Currently running 0.120.

quozl commented 1 year ago

Sorry, not familiar with that any more. The version of Pygame and Python may be significant.

sparshg commented 1 year ago

Can you try running the example without pygame.NOFRAME flag we just introduced? Also which pygame and python version is it?

chimosky commented 1 year ago

Can you try running the example without pygame.NOFRAME flag we just introduced?

Doesn't make any difference.

Also which pygame and python version is it?

pygame 2.3.0 and python3, tested on an F38 vm I have and it works fine.

I'll close this.