实现wxpython的html2.WebViewHandler和html2.WebViewFSHandler的问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了实现wxpython的html2.WebViewHandler和html2.WebViewFSHandler的问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2599字,纯文字阅读大概需要4分钟。
内容图文
![实现wxpython的html2.WebViewHandler和html2.WebViewFSHandler的问题](/upload/InfoBanner/zyjiaocheng/819/2ff91ab6f74442e89a730d3ede9faa8c.jpg)
我正在开发一个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")
这些代码说明了如何:
>添加MemoryFSHandler并将HTML字符串加载到内存流中,而不是将html代码放在文件中并调用该文件
>此示例也基于html小部件,而不是webview小部件
以下是我的代码(试错)
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)
#self.tester.RegisterHandler(wx.html2.WebViewHandler())
wx.FileSystem.AddHandler(wx.MemoryFSHandler())
#self.tester.SetPage("""
wx.MemoryFSHandler().AddFile("about.js","""
document.write("IT is working")
""")
self.tester.LoadURL("memory:about.htm")
我曾尝试在网上搜索一些例子,但不幸的是
题
如何为webview小部件创建处理程序.此处理程序应在内存流/文件中加载任何html字符串(例如使用URI方案“memory:…..”),以便webview可以加载html内存文件
解决方法:
你能发布完整的代码吗?现在你正在尝试加载
self.tester.LoadURL("memory:about.htm")
但是你注册的唯一内存文件是about.js.如果你想引用about.htm,你必须先注册它:
wx.FileSystem.AddHandler(wx.MemoryFSHandler())
wx.MemoryFSHandler().AddFile("about.js", 'document.write("IT is working")')
wx.MemoryFSHandler().AddFile("about.htm",
"""<html>
<script src="memory:about.js"></script>
<body><h2>It lives!</h2></body>
</html>""")
self.tester.LoadURL("memory:about.htm")
内容总结
以上是互联网集市为您收集整理的实现wxpython的html2.WebViewHandler和html2.WebViewFSHandler的问题全部内容,希望文章能够帮你解决实现wxpython的html2.WebViewHandler和html2.WebViewFSHandler的问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。