![]() |
[WxPython] Script execution - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [WxPython] Script execution (/thread-15706.html) |
Script execution - ioprst - Jan-28-2019 Why can't the script run completely (the script works in a normal browser)? Marked the comment "no". And the SVG is not displayed on the page. I need through Python to determine the size of the svg-element "text". import wx import wx.html2 html_string = """ <!DOCTYPE htm> <html> <head> <title>Hello World!</title> </head> <body> <svg viewBox="0 0 192 192" xmlns="http://www.w3.org/2000/svg" id="svg" height="100%" width="100%"> <rect transform="translate(64,128)" width="27" height="64" stroke-width=".5" fill="#ff0" stroke="#000" id="rect"/> <text font-family="monospace" font-size="16" transform="translate(64,141)" id="tsvg">Test Text</text> </svg> <script type="text/javascript"> var text = document.getElementById('tsvg'); alert(text); // ok var tw = text.getComputedTextLength(); alert(tw); // no var box = text.getBBox(); var w = box.width; var h = box.height; alert(w+" "+ h); // no </script> </body> </html> """ class MyBrowser(wx.Dialog): def __init__(self, *args, **kwds): wx.Dialog.__init__(self, *args, **kwds) sizer = wx.BoxSizer(wx.VERTICAL) self.browser = wx.html2.WebView.New(self) sizer.Add(self.browser, 1, wx.EXPAND, 10) self.SetSizer(sizer) self.SetSize((700, 700)) if __name__ == '__main__': app = wx.App() dialog = MyBrowser(None, -1) dialog.browser.SetPage(html_string, '') dialog.Show() app.MainLoop() RE: Script execution - ioprst - Jan-29-2019 Solution: library "cefpython3". Allows you to insert your browser (chromium) in wxPython. RE: Script execution - mtangoo - Feb-08-2019 It works here! Yellow box with works TestText |