Closed JerryFox closed 9 months ago
I just test it and it's working fine. Can you share your code?
from webui import webui
MyWindow1 = webui.window()
MyWindow2 = webui.window()
count = 10
def events(e : webui.event):
global count
count = count + 1
MyWindow2.show(f'<html><script src="webui.js"></script> count = {count} </html>')
MyWindow1.bind("test", events)
MyWindow1.show('<html><script src="webui.js"></script> <button id="test">update window 2</button> </html>')
webui.wait()
ERR_CONNECTION_REFUSED - it was probably my fault
Your code works fine on my comp too.
Here is my code:
from webui import webui
import time
MyWindow = webui.window()
html = "<html>Hello</html>"
new_html = "<html>New World!</html>"
# Open a window
MyWindow.show(html, webui.browser.chrome)
# it is OK
input("press...")
# Refresh the same window with the new content
MyWindow.show(new_html, webui.browser.chrome)
# it opens a new window
input("press...")
MyWindow.close()
# it does not close the window
input("press...")
I see the issue. when you call .show()
, the window needs a couple of second to be ready (running the web browser and connect to websocket). So the second .show()
will be missed.
I noticed some users adding a delay after .show()
, which is not the best thing to do... I guess we should make WebUI itself wait for window to connect. So, let me fix this. Thank you for the report.
You are not right. There is an input() function in the code between the two calls of show() method. I was afraid of that what you said and due to it I tried to wait different time between the two calls of the show() command. The second call is not missed but it shows a SECOND window.
And why the close() method does not close the window???
Thx!
J.
Sorry, I didn't catch that you are missing webui.js
in your HTML. So just update your code with this:
html = '<html><script src="webui.js"></script> Hello</html>'
new_html = '<html><script src="webui.js"></script> New World!</html>'
However, WebUI v2.4.2 has now .Show
that wait for connection.
Thanks again for the report.
Yes, that was the problem! The online documentation is little bit confusing...
Thanks!
J.
Yes, it's old (2.4.0)... It will be updated soon 👍
The update is started: https://webui.me/docs/2.4/#/ Thank you.
Python API
Problem with MyWindow.show() method
in documentation:
If you need to update the whole UI content, you can also use the same function show(), which allows you to refresh the window UI with any new HTML content.
on my computer (windows 11 OS):
in ipython or normal python console: The second show() method does not refresh the actual window content but shows another window.
in a python program running from cmd.exe: The first show() method - normal behaviour. The second show() method also creates a second window but does not show the corrent content but ERR_CONNECTION_REFUSED. In the head of the second window is only "localhost" without any number. The same behaviour in chrome and in edge too.
Problem with MyWindow.close() method
The method does not close the window.
I found this project on purpose. I hope it could be helpful for me. I need the Python interface. I am just testing it if it is suitable for me. Is it a good way to communicate through issues or is there another better way?
Thank you!
Jaroslav Vysoký Czech Republic