<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
i'm still working on this problem where the following code is called
from a wxPython GUI. i have a test program that contains two buttons.
one button calls the play method of the following class and plays an
mp3 file. the second button is brings up a simple message dialog.
the problem is the when the following play method is called and the
music is playing, you are unable to press the button to display the
message dialog. essentially, the GUI app is frozen until the play of
the mp3 file is finished. i thought the PyEval_SaveThread and
PyEval_RestoreThread would work, but not only does it not work, the
app crashes when you press the button the display the message dialog.
as suggested by simon i looked at the dsptools, but i wasn't able to
get anything working with my app. following is my code with the Thread
functions added . i've tested this with the default _callback as well
as a callback from the calling python script. in both cases the app
just hangs after the music is finished playing. i'm also not able to
press the message dialog button while the play is happening. what i
was trying to accomplish is giving back control to python while the c
code is busy, but obviously this is completely wrong.
<br>
<br>
bryan
<br>
<br>
<br>
cdef extern from "Python.h": ctypedef struct PyThreadState
PyThreadState * PyEval_SaveThread()
<br>
void PyEval_RestoreThread(PyThreadState *)
<br>
<br>
cdef PyThreadState *_thread
<br>
<br>
default_callback = eval('lambda *args: 1')
<br>
<br>
cdef class Play: <br>
def play(self, callback=None):
<br>
global _thread
<br>
if not callback:
<br>
callback = default_callback self.callback
= callback
mpgedit_play_set_status_callback(self.ctx, _callback_wrapper,
<void*>callback) more =
True
<br>
_thread = NULL
<br>
<br>
while(more):
<br>
_thread = PyEval_SaveThread()
<br>
more = mpgedit_play_frame(self.ctx)
<br>
<br>
if _thread:
<br>
PyEval_RestoreThread(_thread)
<br>
_thread = NULL <br>
<br>
<br>
cdef int _callback_wrapper(void *callback, long sec, long msec) except
*: global _thread
<br>
PyEval_RestoreThread(_thread)
<br>
_thread = NULL
<br>
return (<object>callback)(sec, msec)
<br>
</body>
</html>