Kinda like this.
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()