Closed wassimj closed 2 years ago
There is no way to display warnings now, only errors. It could be useful to have such feature but I'm not sure about real example of using this feature.
if it's vital to user friendliness there are still options using a few bpy features. One thing you could do in the meantime is:
show_warning: StringProperty()
property to the nodenode.show_warning = "your message"
, and else node.show_warning = ''
(reset it to empty string if there is no warning message)here's a small demo a do_nothing node.
# demo do nothing node
import bpy
from bpy.props import StringProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import node_id, updateNode
class WM_OT_svtopo_tooltip(bpy.types.Operator):
bl_idname = "node.sv_topo_custom_warning_operator"
bl_label = 'Warning:'
arg: StringProperty()
@classmethod
def description(cls, context, properties):
return properties.arg
class SvDoNothingNode(bpy.types.Node, SverchCustomTreeNode):
bl_idname = 'SvDoNothingNode'
bl_label = 'Do Nothing'
bl_icon = 'VIEW_PAN'
show_message: StringProperty()
def sv_init(self, context):
self.inputs.new('SvStringsSocket', 'A')
self.inputs.new('SvStringsSocket', 'B')
def draw_buttons(self, context, layout):
row = layout.row(align=True)
if self.show_message:
row.alert = True
row.enabled = False
op = row.operator("node.sv_topo_custom_warning_operator", icon="QUESTION", text="")
op.arg = self.show_message
def process(self):
self.show_message = ""
if not all([s.is_linked for s in self.inputs]):
self.show_message = "Socket A and B must be linked"
classes = [WM_OT_svtopo_tooltip, SvDoNothingNode]
register, unregister = bpy.utils.register_classes_factory(classes)
if __name__ == "__main__":
register()
the upside to using a tooltip are, to name a few:
|_________some node _______________________|
| socket_name [?] o
o [?] some_name A |
o [?] some_name B |
|__________________________________________|
box node
already implements it. (hover with your mouse in the empty space between label and socket will produce a tooltip )
self.outputs.new('SvVerticesSocket', "Vers").description = "Box vertices"
downside,
My code does the following:
How can I display that warning visually in the GUI (perhaps by changing the colour of the node and/or display the warning text? Is there a standard way to do it?