HtmlWindow не отображает изображения правильно - PullRequest
1 голос
/ 02 мая 2020

Итак, у меня следующая проблема: HtmlWindow неправильно отображает изображения из файлов HTML. Вместо реального изображения появляется красный пиксел X.

Это мой код:

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)

Пример Html:

https://pastebin.com/GJJsyDY3

1 Ответ

2 голосов
/ 02 мая 2020

См .: Вывод изображений в html с использованием python Я не могу сказать, действительно ли то, что сказано в этом обсуждении, все еще действует, но у меня нет оснований сомневаться в этом.
С тех пор wx.html2, который поддерживает javascript и css, был добавлен.

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()

или избегайте поддержки OpenGL и просто используйте wx.Frame как обычно

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()

enter image description here

для целей тестирования d.html содержит ваш связанный html код:

<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&amp;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&amp;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>
...