# Use multiple bl_space_types to place the same toolbar on multiple locations

So I'm not sure if this will be possible at all, but someone might have an idea for a workaround for this problem.

So if I have made a toolbar, e.g. (short version)

class add_item(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'


But I would like to have this toolbar placed in multiple toolbars so it'd become something like this (code below doesn't actually work, just an example of what I'd like):

class add_item(Panel):
bl_space_type = ['VIEW_3D', 'IMAGE_EDITOR', 'NODE_EDITOR']
bl_region_type = 'TOOLS'


Would something similar to this be possible to do without duplicating all the code for the toolbar multiple times, just to then change the bl_space_type?

You can do this using a loop to generate dynamically named panels, each with the desired bl_space_type (based on this nice answer):

import bpy

def panelFactory( spaceType ):
class NewClass( bpy.types.Panel ):
bl_space_type = spaceType
bl_region_type = 'TOOLS'

def draw( self, context ):
layout = self.layout

return NewClass

spaceTypes = ['VIEW_3D', 'IMAGE_EDITOR', 'NODE_EDITOR']

for spaceType in spaceTypes:
panelFactory( spaceType )

def register():
bpy.utils.register_module(__name__)

def unregister():
bpy.utils.unregister_module(__name__)

if __name__ == "__main__":
register()


This code will add the "Add Mesh Cube" operator in a new panel to the "Misc" tab in each of the desired windows (space types).

You can use inheritance to share code between panels while customising parts that are unique to each editor.

class MyBasePanel(bpy.types.Panel):
"""A Panel to show in many places"""
bl_label = "My Tools Panel"
bl_region_type = 'TOOLS'

def mydraw(self, context):
# do nothing here so each class can add it's own thing'
pass

def draw(self, context):
self.mydraw(context)
row = self.layout.row()
row.label(text="Hello world!", icon='WORLD_DATA')

class My3DViewPanel(MyBasePanel):
bl_space_type = 'VIEW_3D'

class MyNodesPanel(MyBasePanel):
bl_label = "My Nodes Panel"
bl_space_type = 'NODE_EDITOR'

class MyImagePanel(MyBasePanel):
bl_space_type = 'IMAGE_EDITOR'

def mydraw(self, context):
row = self.layout.row()
row.label('For the Image editor')