在 Mac 上将 CEFPython 合并到 Kivy 应用程序中——键盘输入不起作用

Incorporating CEFPython into Kivy App on Mac -- keyboard input doesn't work

我正在尝试 运行 位于 OSX 上 here 的简单 Kivy 应用程序。

起初,CEF 在初始化过程中失败。输出是:

igskcicgltgm047:Kivy_Test dslosky$ kivy cefTest4.py 
[INFO   ] [Logger      ] Record log in /Applications/Kivy.app/Contents/Resources/.kivy/logs/kivy_15-07-09_18.txt
[INFO   ] [Kivy        ] v1.9.0
[INFO   ] [Python      ] v2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]
[INFO   ] [Factory     ] 173 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_imageio, img_dds, img_gif, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO   ] [OSC         ] using <multiprocessing> for socket
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] OpenGL version <2.1 NVIDIA-10.2.1 310.41.15f01>
[INFO   ] [GL          ] OpenGL vendor <NVIDIA Corporation>
[INFO   ] [GL          ] OpenGL renderer <NVIDIA GeForce GT 750M OpenGL Engine>
[INFO   ] [GL          ] OpenGL parsed version: 2, 1
[INFO   ] [GL          ] Shading version <1.20>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available
[CEF Python] Initialize() called
[CEF Python] CefExecuteProcess(): exitCode = -1
[CEF Python] CefInitialize()
2015-07-09 12:20:09.283 python[4355:122290] Internals of CFAllocator not known; out-of-memory failures via CFAllocator will not result in termination. http://crbug.com/45650
[CEF Python] App_OnBeforeCommandLineProcessing_BrowserProcess()
[CEF Python] Command line string for the browser process:  --browser-subprocess-path=/Applications/Kivy.app/Contents/Resources/venv/lib/python2.7/site-packages/cefpython3/subprocess --lang=en-US --log-file=debug.log --log-severity=info --enable-release-dcheck --resources-dir-path=/Applications/Kivy.app/Contents/Resources/venv/lib/python2.7/site-packages/cefpython3 --locales-dir-path=/Applications/Kivy.app/Contents/Resources/venv/lib/python2.7/site-packages/cefpython3/locales --remote-debugging-port=51420 --no-sandbox
[0709/122009:WARNING:resource_bundle.cc(269)] locale_file_path.empty()
[0709/122009:FATAL:main_delegate.cc(449)] Check failed: !loaded_locale.empty(). Locale could not be found for en-US
Trace/BPT trap: 5

我发现了一个讨论 here,建议手动设置 local_pak 标志以避免此错误。我对从第 150 行开始的示例代码进行了以下更改:

# Command line switches set programmatically
g_switches = {
    "locale_pak": cefpython.GetModuleDirectory()
    +"/Resources/en.lproj/locale.pak",
    }

#init CEF
cefpython.Initialize(settings, g_switches)

这解决了我的初始化问题! CEF 浏览器出现,但不会响应键盘的任何输入。我也无法使用我的触控板滚动,虽然我可以用它来点击链接。

我给出了这个问题的全部背景,以防我通过更改 locale_pak 标志走错路线。

我正在使用:

Kivy v1.9.0  
Python v2.7.6  
cefpython3 v31.2  

我还应该提到,我能够 运行 与 cefpython3 一起打包的 wxpython.py 示例没有问题。

如有任何帮助,我们将不胜感激!

问题是在 kivy_.py 示例中,键码仅针对 Linux 进行了翻译,请参阅 translate_to_cef_keycode() 函数:

https://code.google.com/p/cefpython/source/browse/cefpython/cef3/linux/binaries_64bit/kivy_.py?r=5cf79c6eec11#355

还需要添加对 Windows/OSX 键码的支持。