-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebviewer.py
49 lines (39 loc) · 1.15 KB
/
webviewer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import webview
import paho.mqtt.client as mqtt
# MQTT broker configuration
broker_address = "broker" # Replace with your broker's address
broker_port = 1883 # Replace with your broker's port
topic = "webview/url" # Topic to subscribe for URL updates
# Create a global variable to store the window instance
window = None
# MQTT callback function
def on_message(client, userdata, msg):
global window
url = msg.payload.decode()
print("Received URL:", url)
# Create the window if it doesn't exist
if window is None:
window = webview.create_window(
"Web View",
url,
fullscreen=True,
)
else:
# Load the new URL in the existing window
window.load_url(url)
# Create MQTT client and set up callback
client = mqtt.Client()
client.on_message = on_message
# Connect to MQTT broker and subscribe to topic
client.connect(broker_address, broker_port, 60)
client.subscribe(topic)
# Create an initial window with a placeholder URL
window = webview.create_window(
"Web View",
"about:blank",
fullscreen=True,
)
# Start MQTT loop
client.loop_start()
# Start web view
webview.start()