<!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 use mozilla thunderbird as my mail/newsreader. when i post code
using the format "text only". the line endings in my code is all
messed up when i see my own posting. so i post with the format "Rich
Text (HTML) only". now i can see my posts as i sent them, but greg
says it's all messed up in his reader. i'm now sending this with the
format "Plain and Rich (HTML) Text".<br>
<br>
---<br>
<br>
<br>
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": <br>
ctypedef struct PyThreadState <br>
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>
<br>
if not callback:<br>
callback = default_callback <br>
<br>
self.callback = callback <br>
mpgedit_play_set_status_callback(self.ctx, _callback_wrapper,
<void*>callback) <br>
more = True<br>
_thread = NULL<br>
while(more): <br>
_thread = PyEval_SaveThread()<br>
more = mpgedit_play_frame(self.ctx)<br>
if _thread:<br>
PyEval_RestoreThread(_thread)<br>
_thread = NULL <br>
<br>
cdef int _callback_wrapper(void *callback, long sec, long msec) except
*: <br>
global _thread<br>
PyEval_RestoreThread(_thread)<br>
_thread = NULL<br>
return (<object>callback)(sec, msec)<br>
<br>
<br>
</body>
</html>