[PyQt] discard button presses while some function is running

Samuele Carcagno sam.carcagno at gmail.com
Thu Mar 17 00:49:38 GMT 2011


> 
>  Logic, time() stop the process.
>  
>  Place your sound in a thread, like this:
>  
>  from threading import Timer
>  
>      def doTrial(self):
>          self.trialRunning = True
>          print('Trial running') #this is where the sounds are presented
>          self.t = Timer(3, self.unblock)
>          self.t.start()
>  
>      def unblock(self):
>          self.trialRunning = False
>  
>      def keyPressEvent(self, event):
>          print self.trialRunning
>          if self.trialRunning:
>              event.accept()
>          elif (event.type() == QtCore.QEvent.KeyPress) and self.trialRunning == False:
>              ...
>  
>  
> 


Thank you very much for the suggestion. I'm not very familiar with using threads, so I'll do
a bit of homework first and then I'll try it out.

Sam 



More information about the PyQt mailing list