<p>你需要的是wx.html2.WebViewFSHandler。我自己还没有尝试过,所以我基于wxWidgets WebView示例,但是在创建wx.MemoryShandler公司要向WebView注册内存处理程序:</p>
<pre><code>self.tester.RegisterHandler(wx.html2.WebViewFSHandler("memory"))
</code></pre>
<p>在这之后,你的self.tester.LoadURL("内存:about.htm)调用应该有效。在</p>
<p>在wx.html2.WebViewFSHandler只存在于Phoenix中,因此,如果您不使用Phoenix,那么您最好的选择可能是使用WebView的SetPage方法:</p>
^{pr2}$
<p><strong>编辑:</strong></p>
<p>我为Phoenix添加了一个完整的工作示例,以演示如何使其工作。在</p>
<pre><code>import wx
import wx.html2
class About(wx.Frame):
def __init__(self):
wx.Panel.__init__(self,None,-1,title="This is a working example",size=(700,700))
class Test(wx.Frame):
"""Contact author: contribute a word or send a occurences of bugs"""
def __init__(self,title,pos,size):
wx.Frame.__init__(self,None,-1,title,pos,size)
self.tester=wx.html2.WebView.New(self)
memoryfs = wx.MemoryFSHandler()
wx.FileSystem.AddHandler(memoryfs)
wx.MemoryFSHandler.AddFileWithMimeType("about.js", u'document.write("IT is working")', 'text/plain')
wx.MemoryFSHandler.AddFileWithMimeType("about.htm",
u"""<html>
<script src="memory:about.js"></script>
<body><h2>It lives!</h2></body>
</html>""", 'text/html')
self.tester.RegisterHandler(wx.html2.WebViewFSHandler("memory"))
self.tester.LoadURL("memory:about.htm")
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = Test("Hello", (20, 20), (800, 600))
frame.Show()
app.MainLoop()
</code></pre>