Reputation: 104
So I have the following problem: HtmlWindow doesn't display the images from HTML files correctly. Instead of the actual image, a red pixelated X appears.
This is my code:
class OpenMail(Inbox):
def __init__(self, parent, title):
wx.Frame.__init__(self, None, title='Email')
wx.InitAllImageHandlers()
vbox = wx.BoxSizer(wx.HORIZONTAL)
self.SetSizer(vbox)
self.htmlwin = wx.html.HtmlWindow(self, style=wx.html.HW_SCROLLBAR_AUTO)
vbox.Add(self.htmlwin, 1, wx.EXPAND)
def openEmail2(self,x):
self.htmlwin.LoadPage(x)
Example Html:
Upvotes: 2
Views: 227
Reputation: 22443
See: Output images to html using python
I can't say whether what is said in that discussion is still valid but I have no reason to doubt it.
Since then wx.html2
which supports javascript and css has been added.
import wx
import wx.glcanvas as glcanvas
import wx.html2
class myGLCanvas(glcanvas.GLCanvas):
def __init__(self, parent):
glcanvas.GLCanvas.__init__(self, parent,-1)
sizer = wx.BoxSizer(wx.VERTICAL)
self.browser = wx.html2.WebView.New(self)
sizer.Add(self.browser, 1, wx.EXPAND, 10)
self.SetSizer(sizer)
self.context = glcanvas.GLContext(self)
self.browser.LoadURL("file:///home/rolf/d.html")
def main():
app = wx.App()
frame = wx.Frame(None,-1,'Web',wx.DefaultPosition,size=(800,800))
canvas = myGLCanvas(frame)
frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()
or avoid the OpenGL
support and simply use a wx.Frame
as normal
import wx
import wx.html2
class TestFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
sizer = wx.BoxSizer(wx.VERTICAL)
self.browser = wx.html2.WebView.New(self)
sizer.Add(self.browser, 1, wx.EXPAND, 10)
self.SetSizer(sizer)
self.browser.LoadURL("file:///home/rolf/d.html")
def main():
app = wx.App()
frame = TestFrame(None,-1,'Web',wx.DefaultPosition,size=(800,800))
frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()
for testing purposes d.html
contains your linked html code:
<html><head><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><title>Three tips to get the most out of Gmail</title></head><body style="background-color:#e5e5e5; margin:20px 0;"><br /><div style="margin:2%;"><div style="direction:ltr; text-align:left; font-family:'Open sans','Arial',sans-serif; color:#444; background-color:white; padding:1.5em; border-radius:1em; box-shadow:1px -5px 8px 2px #bbb; max-width:580px; margin:2% auto 0 auto;"><table style="background:white;width:100%"><tr><td><div style="width:90px; height:54px; margin:10px auto;"><img src="https://services.google.com/fh/files/emails/google_logo_flat_90_color.png" alt="Google" width="90" height="34"/></div><div style="width:90%; padding-bottom:10px; padding-left:15px"><p><img alt="" src="https://ssl.gstatic.com/accounts/services/mail/msa/gmail_icon_small.png" style="display:block; float:left; margin-top:4px; margin-right:5px;"/><span style="font-family:'Open sans','Arial',sans-serif; font-weight:bold; font-size:small; line-height:1.4em">Hi Adam</span></p><p><span style="font-family:'Open sans','Arial',sans-serif; font-size:2.08em;">Tips to get the most out of Gmail</span><br/></p></div><p></p><div style="float:left; clear:both; padding:0px 5px 10px 10px;"><img src="https://services.google.com/fh/files/emails/importcontacts.png" alt="Contacts" style="display:block;"width="129"height="129"/></div><div style="float:left; vertical-align:middle; padding:10px; max-width:398px; float:left;"><table style="vertical-align:middle;"><tr><td style="font-family:'Open sans','Arial',sans-serif;"><span style="font-size:20px;">Bring your contacts and mail into Gmail</span><br/><br/><span style="font-size:small; line-height:1.4em">On your computer, you can copy your contacts and emails from your old email account to make the transition to Gmail even better. <a href="https://support.google.com/mail/answer/164640?hl=en&ref_topic=1669014" style="text-decoration:none; color:#15C">Learn how</a>.</span></td></tr></table></div><div style="float:left; clear:both; padding:0px 5px 10px 10px;"><img src="https://ssl.gstatic.com/mail/welcome/localized/en/welcome_search.png" alt="Search" style="display:block;"width="129"height="129"/></div><div style="float:left; vertical-align:middle; padding:10px; max-width:398px; float:left;"><table style="vertical-align:middle;"><tr><td style="font-family:'Open sans','Arial',sans-serif;"><span style="font-size:20px;">Find what you need fast</span><br/><br/><span style="font-size:small; line-height:1.4em">With the power of Google Search right in your inbox, it's easy to sort your email. Find what you're looking for with predictions based on email content, past searches and contacts.</span></td></tr></table></div><div style="float:left; clear:both; padding:0px 5px 10px 10px;"><img src="https://ssl.gstatic.com/accounts/services/mail/msa/welcome_hangouts.png" alt="Search" style="display:block;"width="129"height="129"/></div><div style="float:left; vertical-align:middle; padding:10px; max-width:398px; float:left;"><table style="vertical-align:middle;"><tr><td style="font-family:'Open sans','Arial',sans-serif;"><span style="font-size:20px;">Much more than email</span><br/><br/><span style="font-size:small; line-height:1.4em">You can send text messages and make video calls with <a href="https://www.google.com/intl/en/hangouts/" style="text-decoration:none; color:#15C">Hangouts</a> right from Gmail. To use this feature on mobile, download the Hangouts app for <a href="https://play.google.com/store/apps/details?id=com.google.android.talk&hl=en" style="text-decoration:none; color:#15C">Android</a> and <a href="https://itunes.apple.com/en/app/hangouts/id643496868?mt=8" style="text-decoration:none; color:#15C">Apple</a> devices.</span></td></tr></table></div><br/><br/>
<div style="clear:both; padding-left:13px; height:6.8em;"><table style="width:100%; border-collapse:collapse; border:0"><tr><td style="width:68px"><img alt='Gmail icon' width="49" height="37" src="https://ssl.gstatic.com/accounts/services/mail/msa/gmail_icon_large.png" style="display:block;"/></td><td style="align:left; font-family:'Open sans','Arial',sans-serif; vertical-align:bottom"><span style="font-size:small">Happy emailing,<br/></span><span style="font-size:x-large; line-height:1">The Gmail Team</span></td></tr></table></div>
</td></tr></table></div>
<div style="direction:ltr;color:#777; font-size:0.8em; border-radius:1em; padding:1em; margin:0 auto 4% auto; font-family:'Arial','Helvetica',sans-serif; text-align:center;">© 2014 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043<br/></div></div></body></html>
Upvotes: 2