Psychopy does not quit at end of script when using sounds - python

I've encountered an odd bug using psychopy recently, where my script does not kill psychopy when it is terminating.
This only happens when I add a sound to my routine and when I make psychopy generate a sound or play a sound from a file. In other words, just loading sound from psychopy does not result in my script being unable to quit. Only when I make a call to a sound as in s=sound.Sound(value="C", secs=0.15), and even if that sound ins't actually played in my routine by s.play()
I've tried googling to see if other people reported this issue but it seems I'm kinda lonely. I've tested it on two Macs specs below:
MacBook Pro runs:
OSX Yosemite
enthought python 2.7
latest psychopy (recently installed with easy_install)
pyglet 1.2
pyo 0.7.5
Intel Iris graphics card/built in
iMac runs:
everything similar to above
NVIDIA separate graphics card (don't remember model right now)
Here is some example code I am running. Does this quit fine for you?
Does anyone have suggestions regarding what might be going on?
Let me know if more info is needed about my system etc.
#Display a text together with a sound synced
#to the onset of the visual display
#---------------------------------------------
from psychopy import core, visual,sound
win = visual.Window([800,800], color='gray', allowGUI=False, winType='pyglet', monitor='testMonitor',units='pix')
stim = visual.TextStim(win, text="Hi!")
s=sound.Sound(value="C", secs=0.15)
startText=visual.TextStim(win, text="starting")
startText.draw()
win.flip()
core.wait(1)
for i in xrange(2):
for frameN in range(70):
stim.draw()
if frameN == 0:
win.flip()
s.play()
else:
win.flip()
win.flip()
core.wait(.2)
Thanks :)

Related

How can i fix my problem with pyautogui.click?

Need to mention that im new with Python and i decided to create a bot for multiplayer game, to autobuy items on auctionhouse, using opencv and pyautogui, so far everything was going pretty well, the cursor was heading to the right point on the screen (reload auction), but
pyautogui.click(clicks=1) isnt working in game window.
IDE (PyCharm) is running with admin rights, googled alot about the topic, but nothing works so far. Will be pleased if anyone could help me, this is my first big project i really want to work with, so hopefully you guys can help me :D
additional info: game uses Battle Eye anticheat, engine Java (probably... Game is called Stalcraft, you can find it on steam, looks like its something Minecraft-based, but im not sure about it)
OS: Win 10 x64
Python:3.11
What i tried:
pyautogui library (tried pyautogui.MoveTo(x,y) and the method with pyautogui.locateCenterOnScreen("whatever.png",confidence=0.85 Need to mention that first method works only in IDE, the second one based on img recognition also works with browser. Tried this in other apps, but no results. It's just hovering cursor on the right place, but no clicks at all)
pydirectinput library
Here's what i got so far
import cv2
import random
import pyautogui
from time import sleep
import imutils
import numpy as np
import pydirectinput
pyautogui.FAILSAFE=True
rng=random.uniform(0.87, 1.3)
sleep(5)
pyautogui.size()
print(pyautogui.size())
pyautogui.position()
print(pyautogui.position())
pyautogui.moveTo(x=1344, y=342, duration=rng)
pyautogui.click(1344, 342, clicks=5)```
This might be very silly. But I had no luck with .click. In my sample I used .moveTo as you did, but then .mouseDown() and .mouseUp() to simulate a click. Also sometimes it required a delay between the two. I wonder if that combo would help instead?
pyautogui.mouseDown()
sleep(1)
pyautogui.mouseUp()

The graphic in my project using turtle library doesn't appear on my screen

import turtle
fondo = turtle.Screen()
fondo.setup(width=500, height=500, startx=750, starty=300)
fondo.bgcolor("blue")
There's no TypeError or NameError in my project, so it's rare that this is happening. I'm using Pycharm for this project. Thank you
it work fine for me I run the script on my phone and it executed with no error. Could you check if you have installed a python compiler, cuz pycharm is just an ide.
You need compiler to run high level programming languages eg python, c++, java but you can run assembly on any device, c programming languages can run on windows also.
It probably does appear, but very quickly closes again. You didn't transfer control to the event handler so the program started and then immediately quit. Add a mainloop() at the end to transfer control:
import turtle
fondo = turtle.Screen()
fondo.setup(width=500, height=500, startx=750, starty=300)
fondo.bgcolor("blue")
# the rest of your code goes here
fondo.mainloop()
This is true for standard Python/turtle, under PyCharm, things might work differently.

Sending keyboard input to windows lock screen

As it sounds I wanted to create my own kinda smart assistant that can actually unlock my pc (Cortana can't and I could not find any good solution for this).
for now, I have tried multiple ways including messing with winlogon.exe and MSGINA.dll. After about 3 hours of search, I haven't found anything that could actually unlock my pc, and I saw some programs that said that they have succeeded in unlocking their pc while messing around with this files but in reality, it just prevents the locking mechanism and it is not my intention.
right now I have seen some videos about using pyautogui and keyboard to control keyboard and mouse movement and I wrote a small script that can "unfold" the windows lock screen cover (where the time and date is displayed) but nothing more than that (it is not working at all)
import keyboard
import time
for i in range(10):
print 10 - i
time.sleep(1)
keyboard.send('enter')
time.sleep(2)
keyboard.write("password1")
keyboard.send("enter")
also tried keyboard.press_and_release and it doesn't do anything.
how can I send any keyboard input to the lock screen?
and if it is not possible, do you have any other suggestions?
EDIT: I am Working on windows 10 build 1803 and python 2.7

pygame sound with Python 3.5 on Windows

im currently having trouble with the python 3rd party library pygame.
Other posts on stackoverflow didn't help me so i opened a new post.
I want to load a *.mp3 file into the program and play it. My code so far (copied from other posts):
import pygame,time,sys
pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
print ("Mixer settings", pygame.mixer.get_init())
print ("Mixer channels", pygame.mixer.get_num_channels())
pygame.mixer.music.set_volume(1.0)
pygame.mixer.music.load("test.mp3")
pygame.mixer.music.play()
clock = pygame.time.Clock()
while pygame.mixer.music.get_busy():
clock.tick(30)
Here is a link to a screenshot from the Windows Sound panel: http://i.imgur.com/fUvJXof.png
I see that there is some output, but i cant hear anything on my headphones.
I hope some has an idea what the problem is.
Thanks
Check your hardware/audio drivers. It doesn't sound like (pardon the pun!) an issue with python or pygame. Does your audio work outside python? Also, if you've got other programs open, they can sometimes take control of your audio drivers and not allow other programs (in this case python) to output.

Graphics Window Crashing in IDLE

A real newbie question here.
I'm using IDLE 2.7.2 on OSX 10.7.2 and reading Zelle's Python:Programming. I haven't programmed since the 80's, so after going through the command line stuff, I'm excited to dive into Objects. I grab his graphics.py file and copy it into documents (this seems like the default location for IDLE) and start up IDLE.
He then suggests a few commands into the shell:
from graphics import *
win = GraphWin() #which opens a graphics window with no problem
He then goes on to have you draw some lines and shapes in the window. Those graphics show up just fine in the window.
Here's my problem. If I try to mouse over the graphics window, I get the Mac pinwheel. Moving the window doesn't help. So the window seems like it's crashing (though IDLE is doing fine), but strangely, if I keep entering commands into IDLE, the shapes keep drawing normally in the window.
Am I doing something wrong? Is this normal? Thanks,
Henry
Idle runs the python commands you enter in another process, so it's reasonable to expect this "lock up" behavior to be different between the program controlled window and Idle.
What's probably going on, though is that everything is fine, but you have not yet started the event loop in the program you're typing in. The operating system notices that the program is not emptying out its event queue when you mouse over it (which creates lots of events) and it's helpfully informing you (by way of the pinwheel) that the program seems to be busy.
You will likely reach a point later in the tutorial where you do start the event loop, and the pinwheel will magically go away.

Categories

Resources