I'm trying to work out how to handle a 'stop' button for a PyAudio (PortAudio library) recording I'm doing from within my application.
At the moment the recording simply times out after a specific number of loops (equivalent to 30s) , but I want it to be able to use a stop button instead. However, whilst recording the GUI is locked, because it's in a loop appending audio stream data to an array.
How is it best to handle this interaction? Should I be exploring threading/forking?
I'm trying to work out how to handle a 'stop' button for a PyAudio (PortAudio library) recording I'm doing from within my application.
At the moment the recording simply times out after a specific number of loops (equivalent to 30s) , but I want it to be able to use a stop button instead. However, whilst recording the GUI is locked, because it's in a loop appending audio stream data to an array.
How is it best to handle this interaction? Should I be exploring threading/forking?
Yes. In order to keep the UI responsive you don't want to do anything in an event handler that blocks, or in other words, anything that prevents the event handler from returning immediately to the MainLoop. If it is blocked then there can be no more events delivered during that time. If you have to do something that takes a relatively long time to accomplish then you either want to do it in another thread, or find a way to slice it up into multiple small pieces. See http://wiki.wxpython.org/index.cgi/LongRunningTasks for more info.
ยทยทยท
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Yes. In order to keep the UI responsive you don't want to do anything in an event handler that blocks, or in other words, anything that prevents the event handler from returning immediately to the MainLoop. If it is blocked then there can be no more events delivered during that time. If you have to do something that takes a relatively long time to accomplish then you either want to do it in another thread, or find a way to slice it up into multiple small pieces. See http://wiki.wxpython.org/index.cgi/LongRunningTasks for more info.
Brilliant! I ended up using wx.Yield() and checking the status of a need_abort variable in the loop. The app is responsive and works well.