MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / send_theme_data

Method send_theme_data

src/bonsai/bonsai/tool/web.py:775–839  ·  view source on GitHub ↗

this method retrieves the theme colors from Blender preferences, calculates the mixed colors, and sends the theme data to the Web UI.

(cls)

Source from the content-addressed store, hash-verified

773
774 @classmethod
775 def send_theme_data(cls) -> None:
776 """
777 this method retrieves the theme colors from Blender preferences,
778 calculates the mixed colors, and sends the theme data to the Web UI.
779 """
780
781 def to_tuple(theme: Union[Color, bpy.types.bpy_prop_array[float]]) -> tuple[float, ...]:
782 return tuple(theme[:])
783
784 def mix_colors(color1, color2):
785 alpha1 = color1[3] * 255 if len(color1) > 3 else 255
786 alpha2 = color2[3] * 255 if len(color2) > 3 else 255
787
788 alpha = 255 - ((255 - alpha1) * (255 - alpha2) / 255)
789 red = (color1[0] * (255 - alpha2) + color2[0] * alpha2) / 255
790 green = (color1[1] * (255 - alpha2) + color2[1] * alpha2) / 255
791 blue = (color1[2] * (255 - alpha2) + color2[2] * alpha2) / 255
792 return red, green, blue, alpha / 255
793
794 assert (blender_preferences := bpy.context.preferences)
795 blender_theme = blender_preferences.themes[0]
796 prefs = blender_theme.preferences.space
797
798 if tool.Blender.BLENDER_5 or TYPE_CHECKING:
799 theme_ui = blender_theme.user_interface
800 theme_regions = blender_theme.regions
801 panel_header, panel_back, panel_sub_back = (
802 theme_ui.panel_header,
803 theme_ui.panel_back,
804 theme_ui.panel_sub_back,
805 )
806 tab_back, tab_outline = theme_regions.sidebars.tab_back, theme_ui.wcol_tab.outline
807 else:
808 # Removed in Blender 5.0.
809 panel = prefs.panelcolors
810 tab_back, tab_outline = prefs.tab_back, prefs.tab_outline
811 panel_header, panel_back, panel_sub_back = panel.header, panel.back, panel.sub_back
812
813 view_3d = blender_theme.view_3d
814 top_bar = blender_theme.topbar.space
815 info = blender_theme.info
816 outliner = blender_theme.outliner
817 ui = blender_theme.user_interface
818
819 theme = {
820 "window_background": prefs.back[:],
821 "text": to_tuple(prefs.text),
822 "tab_background": to_tuple(tab_back),
823 "tab_outline": to_tuple(tab_outline),
824 "panel_header": to_tuple(panel_header),
825 "panel_background": mix_colors(to_tuple(panel_back), to_tuple(panel_sub_back)),
826 "top_bar_header": to_tuple(top_bar.header),
827 "top_bar_header_text": to_tuple(top_bar.header_text),
828 "active_object": to_tuple(view_3d.object_active),
829 "selected_object": to_tuple(view_3d.object_selected),
830 "info_warning": to_tuple(info.info_warning_text),
831 "odd_row": to_tuple(outliner.space.back),
832 "even_row": mix_colors(to_tuple(outliner.space.back), to_tuple(outliner.row_alternate)),

Callers 1

connect_websocket_serverFunction · 0.80

Calls 2

to_tupleFunction · 0.85
send_webui_dataMethod · 0.80

Tested by

no test coverage detected