spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.34k stars 1.62k forks source link

Keyboard events in pygame program run from spyder sent to terminal not program #4077

Open pvince99 opened 7 years ago

pvince99 commented 7 years ago

Description of your problem

I was using spyder ( version 2.3.4 ) to write and run a pygame/opengl program that handles both mouse and keyboard interactions. When run from Spyder the program's window successfully captures mouse actions, keyboard events however are not captured and disappear (don't appear in the console window). I am forced to use IDLE, manifestly unsatisfactory as an IDE, which does its thing successfully.

What steps will reproduce the problem?

  1. run the program as follows a) from spyder; b) from IDLE

What is the expected output? What do you see instead? Expected output from spyder: LEFT 276 KEYUP ...etc... got MOUSEBUTTONDOWN

Actual output: got MOUSEBUTTONDOWN ...etc... quitting

Please provide any additional information below

import pygame, sys
from pygame.locals import *

pygame.init()
display = pygame.display.set_mode((500,500))

while True:
     pygame.display.update()
     events = pygame.event.get()
     for event in events:
         if event.type == QUIT:
             print('quitting')
             pygame.quit()
             sys.exit()
         else:
             if event.type == KEYDOWN:
                 if event.key == K_ESCAPE:
                     print ("ESCAPE")
                     pygame.quit()
                     sys.exit()
                 if event.key == K_LEFT:
                     print ("LEFT")
                 if event.key == K_RIGHT:
                     print ("RIGHT")
                 else:
                    print (event.key)
             if event.type == KEYUP:
                 print('KEYUP')
             if event.type == pygame.MOUSEBUTTONDOWN:
                 print('got MOUSEBUTTONDOWN')

Versions and main components

Dependencies

pgame.version: 1.9.2a0

Please go to the menu entry Help > Optional Dependencies (or Help > Dependencies), press the button Copy to clipboard and paste the contents below:

ccordoba12 commented 7 years ago

Have you tried to change the run settings of your file (with F6) and run it in an external interpreter?

pvince99 commented 7 years ago

Thanks for the reply and suggestion. But when I tried it, I got this on the console:

2017-01-31 08:48:28.241 python[4791:331122] modalSession has been exited prematurely - check for a reentrant call to endModalSession: Does this make sense? What can I do here?

On Tue, Jan 31, 2017 at 4:00 AM, Carlos Cordoba notifications@github.com wrote:

Have you tried to change the run settings of your file (with F6) and run it in an external interpreter?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/spyder-ide/spyder/issues/4077#issuecomment-276309364, or mute the thread https://github.com/notifications/unsubscribe-auth/AGqpE-jQ-LRWvLKg-MnFvYDeoGTMPg2Uks5rXvgqgaJpZM4LxjkH .

ccordoba12 commented 7 years ago

I forgot we haven't implemented that functionality for macOS, sorry. We'll try to work on this for Spyder 3.2, to be released during the summer.

pvince99 commented 6 years ago

It appears that this is still not implemented on MacOS (High Sierra). I'm running Spyder 3.2.8. Am I mistaken?

On Tue, Jan 31, 2017 at 1:39 PM, Carlos Cordoba notifications@github.com wrote:

I forgot we haven't implemented that functionality for macOS, sorry. We'll try to work on this for Spyder 3.2, to be released during the summer.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/spyder-ide/spyder/issues/4077#issuecomment-276451677, or mute the thread https://github.com/notifications/unsubscribe-auth/AGqpE9jqJtRo_ncAIWsORJLiVvCKS02mks5rX3_GgaJpZM4LxjkH .

ccordoba12 commented 6 years ago

No, we haven't, sorry.

goanpeca commented 4 years ago

It appears that this is still not implemented on MacOS (High Sierra).

It is now implemented

pvince99 commented 4 years ago

No, it's not - running Spyder 4.0.1. Same problem as first raised.

ccordoba12 commented 4 years ago

@pvince99, we don't know how to fix this, sorry.

gorkemer commented 2 years ago

running it in an external interpreter (for psychopy package) allowed me to interact with the events. Thank you @ccordoba12 !