我正在开发一个GUI程序,有些部分是用wxpython编写的,有些部分是用css、html和javascript编写的
下面的代码是取自http://wxpython.org/Phoenix/docs/html/MemoryFSHandler.html#memoryfshandler的示例
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")
这些代码显示了如何:
以下是我的代码(试错)
^{pr2}$我试着在网上搜索一些例子,但很不幸
问题
如何为webview小部件创建处理程序。这个处理程序应该加载内存流/文件中的任何html字符串(例如使用URI方案)记忆:。。。。。)以便webview可以加载html内存文件
你需要的是wx.html2.WebViewFSHandler。我自己还没有尝试过,所以我基于wxWidgets WebView示例,但是在创建wx.MemoryShandler公司要向WebView注册内存处理程序:
在这之后,你的self.tester.LoadURL("内存:about.htm)调用应该有效。在
在wx.html2.WebViewFSHandler只存在于Phoenix中,因此,如果您不使用Phoenix,那么您最好的选择可能是使用WebView的SetPage方法:
^{pr2}$编辑:
我为Phoenix添加了一个完整的工作示例,以演示如何使其工作。在
你能发布完整的代码吗?现在你正在尝试加载
但是您注册的唯一内存文件是
^{pr2}$about.js
。如果要引用about.htm
,必须先注册它:相关问题 更多 >
编程相关推荐