Skip to main content
added 62 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Kinda like this.

enter image description hereenter image description here

In hoping for an answer to Instancing a space theme with a draw callback will add an edit to it here

If you pinset one node editor to world, it changes the color of the other, and labels the world one pinned(correctly). The idea is to both label and color the same one, but... hence the question.

import blf
import bpy


highlight_color = (0.48, 0, 0.5)

class DrawingClass:
    def __init__(self, prop):
        from bpy import context
        self.prop = prop
        self.col = context.preferences.themes[0].node_editor.space.back[:] 
        self.handle = bpy.types.SpaceNodeEditor.draw_handler_add(
            self.draw_text_callback, (), 'WINDOW', 'POST_PIXEL')

    def draw_text_callback(self):
        from bpy import context
        font_id = 0  # XXX, need to find out how best to get this.
        if not hasattr(context, "scene"):
            return None
        space = context.space_data
        if space.pinshader_type == 'WORLD':
            context.preferences.themes[0].node_editor.space.back = highlight_color
            # draw some text
            blf.position(font_id, 18, 50, 0)
            blf.size(font_id, 50, 72)
            blf.draw(font_id, f"{self.prop}")

        else:
            context.preferences.themes[0].node_editor.space.back = self.col

    def remove_handle(self):
        from bpy import context
        context.preferences.themes[0].node_editor.space.back = self.col
        bpy.types.SpaceNodeEditor.draw_handler_remove(self.handle, 'WINDOW')


dc = None


def register():
    global dc
    dc = DrawingClass("Foo""World")

def unregister():
    global dc
    if dc:
        dc.remove_handle()
        dc = None

if __name__ == "__main__":
    register()

Kinda like this.

enter image description here

In hoping for an answer to Instancing a space theme with a draw callback will add an edit to it here

If you pin one node editor, it changes the color of the other, and labels the one pinned. The idea is to both label and color the same one, but...

import blf
import bpy


highlight_color = (0.4, 0, 0.5)

class DrawingClass:
    def __init__(self, prop):
        from bpy import context
        self.prop = prop
        self.col = context.preferences.themes[0].node_editor.space.back[:] 
        self.handle = bpy.types.SpaceNodeEditor.draw_handler_add(
            self.draw_text_callback, (), 'WINDOW', 'POST_PIXEL')

    def draw_text_callback(self):
        from bpy import context
        font_id = 0  # XXX, need to find out how best to get this.
        if not hasattr(context, "scene"):
            return None
        space = context.space_data
        if space.pin:
            context.preferences.themes[0].node_editor.space.back = highlight_color
            # draw some text
            blf.position(font_id, 18, 50, 0)
            blf.size(font_id, 50, 72)
            blf.draw(font_id, f"{self.prop}")

        else:
            context.preferences.themes[0].node_editor.space.back = self.col

    def remove_handle(self):
        from bpy import context
        context.preferences.themes[0].node_editor.space.back = self.col
        bpy.types.SpaceNodeEditor.draw_handler_remove(self.handle, 'WINDOW')


dc = None


def register():
    global dc
    dc = DrawingClass("Foo")

def unregister():
    global dc
    if dc:
        dc.remove_handle()
        dc = None

if __name__ == "__main__":
    register()

Kinda like this.

enter image description here

In hoping for an answer to Instancing a space theme with a draw callback will add an edit to it here

If you set one node editor to world, it changes the color of the other, and labels the world one (correctly). The idea is to both label and color the same one, but... hence the question.

import blf
import bpy


highlight_color = (0.8, 0, 0.5)

class DrawingClass:
    def __init__(self, prop):
        from bpy import context
        self.prop = prop
        self.col = context.preferences.themes[0].node_editor.space.back[:] 
        self.handle = bpy.types.SpaceNodeEditor.draw_handler_add(
            self.draw_text_callback, (), 'WINDOW', 'POST_PIXEL')

    def draw_text_callback(self):
        from bpy import context
        font_id = 0  # XXX, need to find out how best to get this.
        if not hasattr(context, "scene"):
            return None
        space = context.space_data
        if space.shader_type == 'WORLD':
            context.preferences.themes[0].node_editor.space.back = highlight_color
            # draw some text
            blf.position(font_id, 18, 50, 0)
            blf.size(font_id, 50, 72)
            blf.draw(font_id, f"{self.prop}")

        else:
            context.preferences.themes[0].node_editor.space.back = self.col

    def remove_handle(self):
        from bpy import context
        context.preferences.themes[0].node_editor.space.back = self.col
        bpy.types.SpaceNodeEditor.draw_handler_remove(self.handle, 'WINDOW')


dc = None


def register():
    global dc
    dc = DrawingClass("World")

def unregister():
    global dc
    if dc:
        dc.remove_handle()
        dc = None

if __name__ == "__main__":
    register()
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Kinda like this.

enter image description here

In hoping for an answer to Instancing a space theme with a draw callback will add an edit to it here

If you pin one node editor, it changes the color of the other, and labels the one pinned. The idea is to both label and color the same one, but...

import blf
import bpy


highlight_color = (0.4, 0, 0.5)

class DrawingClass:
    def __init__(self, prop):
        from bpy import context
        self.prop = prop
        self.col = context.preferences.themes[0].node_editor.space.back[:] 
        self.handle = bpy.types.SpaceNodeEditor.draw_handler_add(
            self.draw_text_callback, (), 'WINDOW', 'POST_PIXEL')

    def draw_text_callback(self):
        from bpy import context
        font_id = 0  # XXX, need to find out how best to get this.
        if not hasattr(context, "scene"):
            return None
        space = context.space_data
        if space.pin:
            context.preferences.themes[0].node_editor.space.back = highlight_color
            # draw some text
            blf.position(font_id, 18, 50, 0)
            blf.size(font_id, 50, 72)
            blf.draw(font_id, f"{self.prop}")

        else:
            context.preferences.themes[0].node_editor.space.back = self.col

    def remove_handle(self):
        from bpy import context
        context.preferences.themes[0].node_editor.space.back = self.col
        bpy.types.SpaceNodeEditor.draw_handler_remove(self.handle, 'WINDOW')


dc = None


def register():
    global dc
    dc = DrawingClass("Foo")

def unregister():
    global dc
    if dc:
        dc.remove_handle()
        dc = None

if __name__ == "__main__":
    register()