Python Forum
cefpython3. JS and Python connection
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cefpython3. JS and Python connection
#1
Python 3.4. GUI - wxPython.
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I don't know what is wrong (Python and SQL connection) shereen 2 161 Yesterday, 06:46 PM
Last Post: menator01
  No Internet connection when running a Python script basil_555 8 444 Mar-11-2024, 11:02 AM
Last Post: snippsat
  Connection LTspice-Python with PyLTSpice bartel90 0 281 Feb-05-2024, 11:46 AM
Last Post: bartel90
  Virtual Env changing mysql connection string in python Fredesetes 0 326 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  connection python and SQL dawid294 4 587 Dec-12-2023, 08:22 AM
Last Post: Pedroski55
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 679 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  Python MYSQL connection does not work after 1h idle zazas321 9 6,625 Oct-07-2021, 12:02 PM
Last Post: ndc85430
  Serial connection connection issue Joni_Engr 15 7,838 Aug-30-2021, 04:46 PM
Last Post: deanhystad
  How can I make a plot representing connection relationship with python matplotlib? Berlintofind 1 1,907 May-08-2020, 09:27 PM
Last Post: jefsummers
  Connection DATABASE to Python MenThoLLt 3 2,377 Jan-17-2020, 10:35 PM
Last Post: DT2000

Forum Jump:

User Panel Messages

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