Python Forum
[WxPython] Script execution
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[WxPython] Script execution
#1
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()
Reply
#2
Solution: library "cefpython3".
Allows you to insert your browser (chromium) in wxPython.
Reply
#3
It works here!
Yellow box with works TestText
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020