Module sverchok.utils.nodes_mixins.show_3d_properties
Expand source code
# This file is part of project Sverchok. It's copyrighted by the contributors
# recorded in the version control history of the file, available from
# its original location https://github.com/nortikin/sverchok/commit/master
#
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE
import bpy
class Show3DProperties:
"""
Mixin for classes which should show their properties in 3D panel
It is better to use this mixin because if any changes it simpler to fix them in one place
"""
draw_3dpanel: bpy.props.BoolProperty(
name="To 3D Panel",
description="Show this node in 3D panel",
default=False,
update=lambda n, c: bpy.context.scene.sv_ui_node_props.update_properties() # automatically add/remove item
)
def draw_buttons_3dpanel(self, layout, in_menu=False):
"""
This method should draw properties in 3D panel
In current implementation UI should be drawn only in one row
:param in_menu: in case if node draw properties more than in one row it can use popup menu
"""
raise AttributeError(f'Method="draw_buttons_3dpanel" should be implemented in class="{type(self).__name__}"')
# just example of popup menu
if not in_menu:
menu = layout.operator('node.popup_3d_menu', 'Sho props')
menu.tree_name = self.id_data.name
menu.node_name = self.name
else:
layout.prop(self, 'mu_prop')
def draw_buttons_ext(self, context, layout):
layout.prop(self, 'draw_3dpanel', icon='PLUGIN', text='to 3dview')
if hasattr(super(), 'draw_buttons_ext'):
super().draw_buttons_ext(context, layout) # in case if mixin override other class with such method
class Popup3DMenu(bpy.types.Operator):
"""
Popup menu for showing node properties in 3D panel
It will call 'draw_buttons_3dpanel' method with extra argument 'in_menu=True'
"""
bl_idname = "node.popup_3d_menu"
bl_label = "Show properties"
bl_options = {'INTERNAL'}
tree_name: bpy.props.StringProperty()
node_name: bpy.props.StringProperty()
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_popup(self)
def draw(self, context):
tree = bpy.data.node_groups.get(self.tree_name)
node = tree.nodes.get(self.node_name)
getattr(node, 'draw_buttons_3dpanel')(self.layout, in_menu=True)
register, unregister = bpy.utils.register_classes_factory([Popup3DMenu])
Classes
class Popup3DMenu (...)
-
Popup menu for showing node properties in 3D panel It will call 'draw_buttons_3dpanel' method with extra argument 'in_menu=True'
Expand source code
class Popup3DMenu(bpy.types.Operator): """ Popup menu for showing node properties in 3D panel It will call 'draw_buttons_3dpanel' method with extra argument 'in_menu=True' """ bl_idname = "node.popup_3d_menu" bl_label = "Show properties" bl_options = {'INTERNAL'} tree_name: bpy.props.StringProperty() node_name: bpy.props.StringProperty() def execute(self, context): return {'FINISHED'} def invoke(self, context, event): wm = context.window_manager return wm.invoke_popup(self) def draw(self, context): tree = bpy.data.node_groups.get(self.tree_name) node = tree.nodes.get(self.node_name) getattr(node, 'draw_buttons_3dpanel')(self.layout, in_menu=True)
Ancestors
- bpy_types.Operator
- builtins.bpy_struct
Class variables
var bl_idname
var bl_label
var bl_options
var bl_rna
var node_name : <_PropertyDeferred,
, {'attr': 'node_name'}> var tree_name : <_PropertyDeferred,
, {'attr': 'tree_name'}>
Methods
def draw(self, context)
-
Expand source code
def draw(self, context): tree = bpy.data.node_groups.get(self.tree_name) node = tree.nodes.get(self.node_name) getattr(node, 'draw_buttons_3dpanel')(self.layout, in_menu=True)
def execute(self, context)
-
Expand source code
def execute(self, context): return {'FINISHED'}
def invoke(self, context, event)
-
Expand source code
def invoke(self, context, event): wm = context.window_manager return wm.invoke_popup(self)
class Show3DProperties
-
Mixin for classes which should show their properties in 3D panel It is better to use this mixin because if any changes it simpler to fix them in one place
Expand source code
class Show3DProperties: """ Mixin for classes which should show their properties in 3D panel It is better to use this mixin because if any changes it simpler to fix them in one place """ draw_3dpanel: bpy.props.BoolProperty( name="To 3D Panel", description="Show this node in 3D panel", default=False, update=lambda n, c: bpy.context.scene.sv_ui_node_props.update_properties() # automatically add/remove item ) def draw_buttons_3dpanel(self, layout, in_menu=False): """ This method should draw properties in 3D panel In current implementation UI should be drawn only in one row :param in_menu: in case if node draw properties more than in one row it can use popup menu """ raise AttributeError(f'Method="draw_buttons_3dpanel" should be implemented in class="{type(self).__name__}"') # just example of popup menu if not in_menu: menu = layout.operator('node.popup_3d_menu', 'Sho props') menu.tree_name = self.id_data.name menu.node_name = self.name else: layout.prop(self, 'mu_prop') def draw_buttons_ext(self, context, layout): layout.prop(self, 'draw_3dpanel', icon='PLUGIN', text='to 3dview') if hasattr(super(), 'draw_buttons_ext'): super().draw_buttons_ext(context, layout) # in case if mixin override other class with such method
Subclasses
- sverchok.nodes.color.color_input.SvColorInputNode
- sverchok.nodes.exchange.bezier_in.SvBezierInNode
- sverchok.nodes.exchange.nurbs_in.SvExNurbsInNode
- sverchok.nodes.logic.custom_switcher.SvCustomSwitcher
- sverchok.nodes.number.list_input.SvListInputNode
- sverchok.nodes.number.numbers.SvNumberNode
- sverchok.nodes.scene.get_objects_data.SvGetObjectsData
- sverchok.nodes.viz.mesh_viewer.SvMeshViewer
Class variables
var draw_3dpanel : <_PropertyDeferred,
, {'name': 'To 3D Panel', 'description': 'Show this node in 3D panel', 'default': False, 'update': Show3DProperties. at 0x7f2f1b0fe5e0>, 'attr': 'draw_3dpanel'}>
Methods
-
This method should draw properties in 3D panel In current implementation UI should be drawn only in one row :param in_menu: in case if node draw properties more than in one row it can use popup menu
Expand source code
def draw_buttons_3dpanel(self, layout, in_menu=False): """ This method should draw properties in 3D panel In current implementation UI should be drawn only in one row :param in_menu: in case if node draw properties more than in one row it can use popup menu """ raise AttributeError(f'Method="draw_buttons_3dpanel" should be implemented in class="{type(self).__name__}"') # just example of popup menu if not in_menu: menu = layout.operator('node.popup_3d_menu', 'Sho props') menu.tree_name = self.id_data.name menu.node_name = self.name else: layout.prop(self, 'mu_prop')
-
Expand source code
def draw_buttons_ext(self, context, layout): layout.prop(self, 'draw_3dpanel', icon='PLUGIN', text='to 3dview') if hasattr(super(), 'draw_buttons_ext'): super().draw_buttons_ext(context, layout) # in case if mixin override other class with such method