made sending data take the event and namespace names as args

This commit is contained in:
Ziad-I
2024-06-19 14:52:57 +03:00
committed by Dion Moult
parent 439595f04c
commit 6155edef0d
2 changed files with 11 additions and 8 deletions
+1 -1
View File
@@ -192,7 +192,7 @@ def refresh_ui_data():
bpy.context.scene.DocProperties.should_draw_decorations = bpy.context.scene.DocProperties.should_draw_decorations bpy.context.scene.DocProperties.should_draw_decorations = bpy.context.scene.DocProperties.should_draw_decorations
if bpy.context.scene.WebProperties.is_connected: if bpy.context.scene.WebProperties.is_connected:
tool.Web.send_webui_data() tool.Web.send_default_webui_data()
@persistent @persistent
+10 -7
View File
@@ -81,7 +81,7 @@ class Web(blenderbim.core.tool.Web):
ws_url = f"ws://localhost:{port}/blender" ws_url = f"ws://localhost:{port}/blender"
ws_thread.run_coro(cls.sio_connect(ws_url)) ws_thread.run_coro(cls.sio_connect(ws_url))
cls.set_is_connected(True) cls.set_is_connected(True)
cls.send_webui_data() cls.send_default_webui_data()
@classmethod @classmethod
def disconnect_websocket_server(cls): def disconnect_websocket_server(cls):
@@ -114,13 +114,16 @@ class Web(blenderbim.core.tool.Web):
print("Websocket server terminated successfully") print("Websocket server terminated successfully")
@classmethod @classmethod
def send_webui_data(cls): def send_default_webui_data(cls, event="default_data", namespace="/blender"):
global ws_thread
if not WebData.is_loaded: if not WebData.is_loaded:
WebData.load() WebData.load()
cls.send_webui_data(WebData.data, event=event, namespace=namespace)
ws_thread.run_coro(cls.sio_send(WebData.data)) @classmethod
def send_webui_data(cls, data, event="data", namespace="/blender"):
global ws_thread
if ws_thread is not None and bpy.context.scene.WebProperties.is_connected:
ws_thread.run_coro(cls.sio_send(data, event, namespace))
@classmethod @classmethod
def open_web_browser(cls, port): def open_web_browser(cls, port):
@@ -140,8 +143,8 @@ class Web(blenderbim.core.tool.Web):
await sio.disconnect() await sio.disconnect()
@classmethod @classmethod
async def sio_send(cls, data): async def sio_send(cls, data, event="data", namespace="/blender"):
await sio.emit("data", data, namespace="/blender") await sio.emit(event, data, namespace=namespace)
@classmethod @classmethod
def set_is_running(cls, is_running): def set_is_running(cls, is_running):