nortikin / sverchok

Sverchok
http://nortikin.github.io/sverchok/
GNU General Public License v3.0
2.22k stars 233 forks source link

How to visually display a warning on a node #4315

Closed wassimj closed 2 years ago

wassimj commented 2 years ago

My code does the following:

def processItem(cells):
    cellComplex = cells[0]
    for i in range(1,len(cells)):
        try:
            cellComplex = cellComplex.Merge(cells[i], False)
        except:
            raise Exception("Error: CellComplex.ByCells operation failed during processing the input Cells")
    if cellComplex.GetType() != 64: #64 is the type of a CellComplex
        warnings.warn("Warning: Input Cells do not form a CellComplex", UserWarning)
    return fixTopologyClass(cellComplex)

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?

Durman commented 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.

zeffii commented 2 years ago

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:

zeffii commented 2 years ago

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()
zeffii commented 2 years ago

the upside to using a tooltip are, to name a few:

downside,