我對其中的一些部件都寫在wxPython和CSS,HTML一些地方和javascript問題與實施的wxPython的html2.WebViewHandler和html2.WebViewFSHandler
下面的代碼的GUI程序的工作是從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代碼的S IN文件並調用該文件
- 另外這個例子是基於HTML控件和不是web視圖控件
下面是我的代碼(試錯)
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方案「內存:.....」),以便webview可以加載html內存文件
希望我能很快把賞金這個問題...我一直在嘗試了幾天就這個問題 – repzero