ops_ui.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # gonna start putting the UI operators in here so
  2. # that the nodegroup operators file is more focused
  3. import bpy
  4. from bpy.types import Operator
  5. from .utilities import (prRed, prGreen, prPurple, prWhite,
  6. prOrange,
  7. wrapRed, wrapGreen, wrapPurple, wrapWhite,
  8. wrapOrange,)
  9. def TellClasses():
  10. return [
  11. ColorPalleteAddSocket,
  12. ColorPalleteRemoveSocket,
  13. ]
  14. class ColorPalleteAddSocket(Operator):
  15. """Add a Color Set socket to the node"""
  16. bl_idname = "mantis.color_pallete_socket_add"
  17. bl_label = "Add Color Set"
  18. bl_options = {'REGISTER', 'UNDO'}
  19. tree_invoked : bpy.props.StringProperty(options ={'HIDDEN'})
  20. node_invoked : bpy.props.StringProperty(options ={'HIDDEN'})
  21. @classmethod
  22. def poll(cls, context):
  23. return True
  24. def execute(self, context):
  25. n = bpy.data.node_groups[self.tree_invoked].nodes[self.node_invoked]
  26. #name them uniquely
  27. number=0
  28. for o in n.outputs:
  29. if int(o.name[-3:]) == number:
  30. number = int(o.name[-3:]) + 1
  31. else: # my intention is to use the first number that isn't used
  32. break # so break here because we have reached the end or a 'gap'
  33. n.outputs.new("ColorSetSocket", "Color Set."+str(number).zfill(3))
  34. return {'FINISHED'}
  35. class ColorPalleteRemoveSocket(Operator):
  36. """Remove a Color Set socket from the node"""
  37. bl_idname = "mantis.color_pallete_socket_remove"
  38. bl_label = "X"
  39. bl_options = {'REGISTER', 'UNDO'}
  40. tree_invoked : bpy.props.StringProperty(options = {'HIDDEN'})
  41. node_invoked : bpy.props.StringProperty(options = {'HIDDEN'})
  42. socket_invoked : bpy.props.StringProperty(options = {'HIDDEN'})
  43. @classmethod
  44. def poll(cls, context):
  45. return True
  46. def execute(self, context):
  47. n = bpy.data.node_groups[self.tree_invoked].nodes[self.node_invoked]
  48. # the name doesn't matter, will probably be Color Set.001 or something instead
  49. for s in n.outputs:
  50. if s.identifier == self.socket_invoked:
  51. break
  52. n.outputs.remove(s)
  53. return {'FINISHED'}