Merge pull request #1412 from wxWidgets/add-archivehandler-example

Add an example of viewing html pages from a .zip file
This commit is contained in:
Robin Dunn
2019-10-23 18:07:25 -07:00
committed by GitHub
3 changed files with 18 additions and 8 deletions

BIN
samples/html2/simpleweb.zip Normal file

Binary file not shown.

View File

@@ -20,8 +20,12 @@
<p>
Resources can also be loaded from custom file systems:
<ul>
<li><a href="memory:page1.htm">wx.MemoryFSHandler</a></li>
<li>Custom <a href="custom:page1.html">wx.html2.WebViewHandler</a></li>
<li><a href="memory:page1.html">wx.MemoryFSHandler</a>:
Pages can be loaded from an in-memory filesystem</li>
<li><a href="wxzip://simpleweb.zip;protocol=zip/index.html">wx.ArchiveFSHandler</a>:
Or from a ZIP file</li>
<li><a href="custom://page1.html">wx.html2.WebViewHandler</a>:
A custom handler can also be implemented</li>
</ul>
</p>
<p></p>

View File

@@ -10,7 +10,9 @@ BASE = 'file://{}/'.format(HERE.replace('\\', '/'))
URL = BASE + 'webview_sample.html'
LOGO = os.path.join(HERE, 'logo.png')
#print(wx.version())
# We need to be in the HERE folder for the archive link to work since the sample
# page does not use a full path
os.chdir(HERE)
#--------------------------------------------------------------------------
@@ -58,7 +60,10 @@ class WebViewPanel(wx.Panel):
# Register a handler for the memory: file system
self.wv.RegisterHandler(webview.WebViewFSHandler("memory"))
# And also one for the custom: file system implemented by the
# This handler takes care of links that are in zip files
self.wv.RegisterHandler(webview.WebViewArchiveHandler("wxzip"))
# And this one is for the custom: file system implemented by the
# CustomWebViewHandler class below
self.wv.RegisterHandler(CustomWebViewHandler())
@@ -191,20 +196,21 @@ def SetupMemoryFiles():
# loaded into the webview just like network or local file sources.
# These "files" can be access using a protocol specifier of "memory:"
wx.FileSystem.AddHandler(wx.MemoryFSHandler())
wx.FileSystem.AddHandler(wx.ArchiveFSHandler())
wx.MemoryFSHandler.AddFile(
"page1.htm",
"page1.html",
"<html><head><title>File System Example</title>"
"<link rel='stylesheet' type='text/css' href='memory:test.css'>"
"</head><body><h1>Page 1</h1>"
"<p><img src='memory:logo.png'></p>"
"<p>This file was loaded directly from a virtual in-memory filesystem.</p>"
"<p>Here's another page: <a href='memory:page2.htm'>Page 2</a>.</p></body>")
"<p>Here's another page: <a href='memory:page2.html'>Page 2</a>.</p></body>")
wx.MemoryFSHandler.AddFile(
"page2.htm",
"page2.html",
"<html><head><title>File System Example</title>"
"<link rel='stylesheet' type='text/css' href='memory:test.css'>"
"</head><body><h1>Page 2</h1>"
"<p><a href='memory:page1.htm'>Page 1</a> was better.</p></body>")
"<p><a href='memory:page1.html'>Page 1</a> was better.</p></body>")
wx.MemoryFSHandler.AddFile(
"test.css",
"h1 {color: red;}")