Jan-30-2019, 09:04 AM
Python 3.4. GUI - wxPython.
It is necessary to calculate the size of the text in pixels declared in the SVG document.
Found a way to calculate text size via JS:
I need to use the values computed in JS in my GUI program in Python.
The web engine built into wxPython doesn’t pull it (some old IE is there).
Advised cefpython3 library - Chromium Embedded Framework. It allows you to connect the browser to the GUI. It works fine.
As I understood from the tutorial, i can call JS methods from Python by first declaring them.
But I could not manage to implement the mechanism in any way, so that after executing the JS function, I would return the result back to Python and use it.
Is it even possible? If yes, please tell me which way to dig.
It is necessary to calculate the size of the text in pixels declared in the SVG document.
<svg viewBox="0 0 {width} {height}" xmlns="http://www.w3.org/2000/svg" id="svg" height="100%" width="100%"> <text font-family="{font}" font-size="{size}" id="user_text">{text}</text> </svg>Using Python and wxPython does not work. wxPython allows you to determine the size, which will occupy the text with a specific font, size, etc., but they are not true for SVG (due to scaling of the svg-document, as I understood it).
Found a way to calculate text size via JS:
let text = document.getElementById("user_text"); let box = text.getBBox(); let w = box.width; let h = box.height;This solution gives the right result.
I need to use the values computed in JS in my GUI program in Python.
The web engine built into wxPython doesn’t pull it (some old IE is there).
Advised cefpython3 library - Chromium Embedded Framework. It allows you to connect the browser to the GUI. It works fine.
As I understood from the tutorial, i can call JS methods from Python by first declaring them.
But I could not manage to implement the mechanism in any way, so that after executing the JS function, I would return the result back to Python and use it.
Is it even possible? If yes, please tell me which way to dig.