回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在开发一个GUI程序,有些部分是用wxpython编写的,有些部分是用css、html和javascript编写的</p>
<p>下面的代码是取自<a href="http://wxpython.org/Phoenix/docs/html/MemoryFSHandler.html#memoryfshandler" rel="nofollow">http://wxpython.org/Phoenix/docs/html/MemoryFSHandler.html#memoryfshandler</a>的示例</p>
<pre><code>def OnAbout(self, event):
bcur = wx.BeginBusyCursor()
wx.FileSystem.AddHandler(wx.MemoryFSHandler) #there is a bug here in this example wx.MemoryFSHandler should read wx.MemoryFSHandler()
wx.MemoryFSHandler.AddFile("logo.pcx", wx.Bitmap("logo.pcx", wx.BITMAP_TYPE_PCX))
wx.MemoryFSHandler.AddFile("about.htm",
"<html><body>About: "
"<img src=\"memory:logo.pcx\"></body></html>")
dlg = wx.Dialog(self, -1, _("About"))
topsizer = wx.BoxSizer(wx.VERTICAL)
html = wx.html.HtmlWindow(dlg, size=wx.Size(380, 160), style=wx.HW_SCROLLBAR_NEVER)
html.SetBorders(0)
html.LoadPage("memory:about.htm")
html.SetSize(html.GetInternalRepresentation().GetWidth(),
html.GetInternalRepresentation().GetHeight())
topsizer.Add(html, 1, wx.ALL, 10)
topsizer.Add(wx.StaticLine(dlg, -1), 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
topsizer.Add(wx.Button(dlg, wx.ID_OK, "Ok"),
0, wx.ALL | wx.ALIGN_RIGHT, 15)
dlg.SetAutoLayout(True)
dlg.SetSizer(topsizer)
topsizer.Fit(dlg)
dlg.Centre()
dlg.ShowModal()
wx.MemoryFSHandler.RemoveFile("logo.pcx")
wx.MemoryFSHandler.RemoveFile("about.htm")
</code></pre>
<p>这些代码显示了如何:</p>
<ul>
<li>添加memoryShandler并将HTML字符串加载到内存流中,而不是将HTML代码放入文件并调用该文件</li>
<li>此外,本示例基于<strong>html小部件</strong>和<strong>而非webview小部件</strong></li>
</ul>
<p><strong>以下是我的代码(试错)</strong></p>
^{pr2}$
<p>我试着在网上搜索一些例子,但很不幸</p>
<p><strong>问题</strong></p>
<p>如何为<strong>webview小部件创建处理程序</strong>。这个处理程序应该加载内存流/文件中的任何html字符串(例如使用URI方案)记忆:。。。。。)以便<strong>webview</strong>可以加载html内存文件</p>