编辑:谷歌集团帖子
我正在和Brython一起玩。
我试图弄清楚如何从 JavaScript 执行 Brython 代码。
http://www.brython.info/static_doc/en/jsobjects.html <-- 这看起来像相关的文档页面,但似乎缺少从 JavaScript 调用 Brython 函数的示例。
对于我的具体情况,我正在听 MIDI 事件(使用https://github.com/cwilso/WebMIDIAPIShim)
我希望执行 Brython 代码以响应收到的 MIDI 事件。
目前我正在尝试:
function myMIDIMessagehandler( event )
{
if( brythonListener != null )
brythonListener( event );
和 Brython 代码:
<script type="text/python3">
from browser import document as doc, window, html
def foo(event):
print("BRYTHON!" + event);
window.brythonListener = foo
</script>
但是当我在我的 MIDI 键盘上按下一个音符时,我得到:
我不知道如何处理这个错误,而且我完全不确定这种方法是否合理。