add new webui demo panel in demo module

This commit is contained in:
Ziad-I
2024-08-18 19:27:13 +03:00
committed by Dion Moult
parent d3d1ca0169
commit b375579dcd
5 changed files with 47 additions and 0 deletions
@@ -36,8 +36,10 @@ from . import ui, prop, operator
classes = (
operator.DemonstrateHelloWorld,
operator.DemonstrateRenameProject,
operator.SendWebUiDemoMessage,
prop.BIMDemoProperties,
ui.BIM_PT_demo,
ui.BIM_PT_webui_demo,
)
@@ -76,3 +76,17 @@ class DemonstrateRenameProject(bpy.types.Operator, tool.Ifc.Operator):
# properties (such as an input field) or data from the scene (like the
# actively selected object).
core.demonstrate_rename_project(tool.Ifc, tool.Demo, name=bpy.context.scene.BIMDemoProperties.name)
class SendWebUiDemoMessage(bpy.types.Operator):
bl_idname = "bim.send_webui_demo_message"
bl_label = "Send Web UI Demo Message"
bl_description = "Sends a demo message to the currently connected Web UI"
def execute(self, context):
# First, we need to make sure that we are connected to the Web UI
# We do that by checking the Web module properties' is_connected prop
# and calling the operator connect_websocket_server if we aren't connected to a Web UI
if not context.scene.WebProperties.is_connected:
bpy.ops.bim.connect_websocket_server(page="demo")
core.send_webui_demo_message(tool.Web, message=bpy.context.scene.BIMDemoProperties.webui_message)
@@ -59,3 +59,4 @@ class BIMDemoProperties(PropertyGroup):
# an input text field in the ui.py.
message: StringProperty(name="Message")
show_hints: BoolProperty(name="Show Hints", default=False)
webui_message: StringProperty(name="Web UI Message", default="Hello, Web UI!")
+24
View File
@@ -130,3 +130,27 @@ class BIM_PT_demo(bpy.types.Panel):
if self.props.show_hints:
row = self.layout.row()
row.label(text="Name cannot be blank!")
class BIM_PT_webui_demo(bpy.types.Panel):
bl_label = "Web UI Demo"
bl_idname = "BIM_PT_webui_demo"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "scene"
# we specify that this panel is closed by default
bl_options = {"DEFAULT_CLOSED"}
# here we reference the demo panel to create a sub panel
# for the web UI demo
bl_parent_id = "BIM_PT_demo"
def draw(self, context):
self.props = context.scene.BIMDemoProperties
row = self.layout.row()
# we create an input field for the property webui_message
row.prop(self.props, "webui_message")
row = self.layout.row()
# here we create a button referencing the operator send_webui_message
row.operator("bim.send_webui_demo_message")
+6
View File
@@ -72,3 +72,9 @@ def demonstrate_rename_project(ifc, demo, name=None):
demo.hide_user_hints()
else:
demo.show_user_hints()
# here this core function uses the web tool to send a message to the web UI
# we call the send_webui_data method to send any kind of data to the web UI
def send_webui_demo_message(web, message="Hello"):
web.send_webui_data(data=message, data_key="demo_message", event="demo_data")