diff options
author | lijenstina <lijenstina@gmail.com> | 2017-04-22 04:54:45 +0300 |
---|---|---|
committer | lijenstina <lijenstina@gmail.com> | 2017-04-22 04:54:45 +0300 |
commit | 29f2b2f34a8255828cf1621edd5c725167338f9f (patch) | |
tree | d478f0eb44d078137d62ad5b76d7320bbaf4f494 /space_view3d_brush_menus/texture_menu.py | |
parent | 3fe42bb946bd780e7732afc4c1d100d13830d7e3 (diff) |
Sculpt Paint Brush Menus: cleanup, refactor, various fixes
Bumped version to 1.1.4
Remove the Utils folder and move it to file utils_core
Remove star imports and replace them with namespace
Remove unused imports
Use importlib for reloading files
Add customization to the brushes (column size, 3 types of menus)
Remove the VIEW3D_MT_Brush_Selection1 menu
Remove versioning code
Add some helper functions in utils_core
Fix crash with poll functions get_mode if no active object
Fix several crashes with unlinked missing active brush
(hope i got it all)
Move the shortcut register to the init
Update wiki link
NOTE:
Remove unused operators and functions
Part of it is something to do with properties creation
Haven't seen the code used anywhere so it was removed
If it is needed for something it could be restored later
Diffstat (limited to 'space_view3d_brush_menus/texture_menu.py')
-rw-r--r-- | space_view3d_brush_menus/texture_menu.py | 344 |
1 files changed, 197 insertions, 147 deletions
diff --git a/space_view3d_brush_menus/texture_menu.py b/space_view3d_brush_menus/texture_menu.py index 1f44bc8f..d961410b 100644 --- a/space_view3d_brush_menus/texture_menu.py +++ b/space_view3d_brush_menus/texture_menu.py @@ -1,87 +1,98 @@ -from bpy.props import * -from .Utils.core import * +# gpl author: Ryan Inch (Imaginer) +import bpy +from bpy.types import Menu +from . import utils_core -class TextureMenu(bpy.types.Menu): + +class TextureMenu(Menu): bl_label = "Texture Options" bl_idname = "VIEW3D_MT_sv3_texture_menu" @classmethod def poll(self, context): - if get_mode() in [sculpt, vertex_paint, texture_paint]: - return True - else: - return False + return utils_core.get_mode() in ( + utils_core.sculpt, + utils_core.vertex_paint, + utils_core.texture_paint + ) def draw(self, context): - menu = Menu(self) + menu = utils_core.Menu(self) - if get_mode() == sculpt: + if utils_core.get_mode() == utils_core.sculpt: self.sculpt(menu, context) - elif get_mode() == vertex_paint: + elif utils_core.get_mode() == utils_core.vertex_paint: self.vertpaint(menu, context) else: self.texpaint(menu, context) def sculpt(self, menu, context): - tex_slot = context.tool_settings.sculpt.brush.texture_slot - + has_brush = utils_core.get_brush_link(context, types="brush") + tex_slot = has_brush.texture_slot if has_brush else None + # Menus menu.add_item().menu(Textures.bl_idname) menu.add_item().menu(TextureMapMode.bl_idname) + menu.add_item().separator() # Checkboxes - if tex_slot.map_mode != '3D': - if tex_slot.map_mode in ['RANDOM', 'VIEW_PLANE', 'AREA_PLANE']: - if bpy.app.version >= (2, 75): + if tex_slot: + if tex_slot.map_mode != '3D': + if tex_slot.map_mode in ['RANDOM', 'VIEW_PLANE', 'AREA_PLANE']: menu.add_item().prop(tex_slot, "use_rake", toggle=True) menu.add_item().prop(tex_slot, "use_random", toggle=True) - else: - menu.add_item().menu(TextureAngleSource.bl_idname) - # Sliders - menu.add_item().prop(tex_slot, "angle", text=PIW+"Angle", slider=True) - - if tex_slot.tex_paint_map_mode in ['RANDOM', 'VIEW_PLANE'] and tex_slot.use_random: - menu.add_item().prop(tex_slot, "random_angle", text=PIW+"Random Angle", slider=True) - - # Operator - if tex_slot.tex_paint_map_mode == 'STENCIL': - menu.add_item().operator("brush.stencil_reset_transform") + # Sliders + menu.add_item().prop(tex_slot, "angle", + text=utils_core.PIW + "Angle", slider=True) + + if tex_slot.tex_paint_map_mode in ['RANDOM', 'VIEW_PLANE'] and tex_slot.use_random: + menu.add_item().prop(tex_slot, "random_angle", + text=utils_core.PIW + "Random Angle", slider=True) + + # Operator + if tex_slot.tex_paint_map_mode == 'STENCIL': + menu.add_item().operator("brush.stencil_reset_transform") + else: + menu.add_item().label("No Texture Slot available", icon="INFO") def vertpaint(self, menu, context): - tex_slot = context.tool_settings.vertex_paint.brush.texture_slot - + has_brush = utils_core.get_brush_link(context, types="brush") + tex_slot = has_brush.texture_slot if has_brush else None + # Menus menu.add_item().menu(Textures.bl_idname) menu.add_item().menu(TextureMapMode.bl_idname) # Checkboxes - if tex_slot.tex_paint_map_mode != '3D': + if tex_slot and tex_slot.tex_paint_map_mode != '3D': if tex_slot.tex_paint_map_mode in ['RANDOM', 'VIEW_PLANE']: - if bpy.app.version >= (2, 75): - menu.add_item().prop(tex_slot, "use_rake", toggle=True) - menu.add_item().prop(tex_slot, "use_random", toggle=True) - else: - menu.add_item().menu(TextureAngleSource.bl_idname) + menu.add_item().prop(tex_slot, "use_rake", toggle=True) + menu.add_item().prop(tex_slot, "use_random", toggle=True) # Sliders - menu.add_item().prop(tex_slot, "angle", text=PIW+"Angle", slider=True) - + menu.add_item().prop(tex_slot, "angle", + text=utils_core.PIW + "Angle", slider=True) + if tex_slot.tex_paint_map_mode in ['RANDOM', 'VIEW_PLANE'] and tex_slot.use_random: - menu.add_item().prop(tex_slot, "random_angle", text=PIW+"Random Angle", slider=True) - + menu.add_item().prop(tex_slot, "random_angle", + text=utils_core.PIW + "Random Angle", slider=True) + # Operator if tex_slot.tex_paint_map_mode == 'STENCIL': menu.add_item().operator("brush.stencil_reset_transform") + else: + menu.add_item().label("No Texture Slot available", icon="INFO") def texpaint(self, menu, context): - tex_slot = context.tool_settings.image_paint.brush.texture_slot - mask_tex_slot = context.tool_settings.image_paint.brush.mask_texture_slot - + has_brush = utils_core.get_brush_link(context, types="brush") + tex_slot = has_brush.texture_slot if has_brush else None + mask_tex_slot = has_brush.mask_texture_slot if has_brush else None + # Texture Section menu.add_item().label(text="Texture", icon='TEXTURE') @@ -90,20 +101,19 @@ class TextureMenu(bpy.types.Menu): menu.add_item().menu(TextureMapMode.bl_idname) # Checkboxes - if tex_slot.tex_paint_map_mode != '3D': + if tex_slot and tex_slot.tex_paint_map_mode != '3D': if tex_slot.tex_paint_map_mode in ['RANDOM', 'VIEW_PLANE']: - if bpy.app.version >= (2, 75): - menu.add_item().prop(tex_slot, "use_rake", toggle=True) - menu.add_item().prop(tex_slot, "use_random", toggle=True) - else: - menu.add_item().menu(TextureAngleSource.bl_idname) + menu.add_item().prop(tex_slot, "use_rake", toggle=True) + menu.add_item().prop(tex_slot, "use_random", toggle=True) # Sliders - menu.add_item().prop(tex_slot, "angle", text=PIW+"Angle", slider=True) + menu.add_item().prop(tex_slot, "angle", + text=utils_core.PIW + "Angle", slider=True) if tex_slot.tex_paint_map_mode in ['RANDOM', 'VIEW_PLANE'] and tex_slot.use_random: - menu.add_item().prop(tex_slot, "random_angle", text=PIW+"Random Angle", slider=True) - + menu.add_item().prop(tex_slot, "random_angle", + text=utils_core.PIW + "Random Angle", slider=True) + # Operator if tex_slot.tex_paint_map_mode == 'STENCIL': menu.add_item().operator("brush.stencil_reset_transform") @@ -118,37 +128,40 @@ class TextureMenu(bpy.types.Menu): menu.add_item().menu(MaskMapMode.bl_idname) # Checkboxes - if mask_tex_slot.mask_map_mode in ['RANDOM', 'VIEW_PLANE']: - if bpy.app.version >= (2, 75): + if mask_tex_slot: + if mask_tex_slot.mask_map_mode in ['RANDOM', 'VIEW_PLANE']: menu.add_item().prop(mask_tex_slot, "use_rake", toggle=True) menu.add_item().prop(mask_tex_slot, "use_random", toggle=True) - else: - menu.add_item().menu(TextureAngleSource.bl_idname) - # Sliders - menu.add_item().prop(mask_tex_slot, "angle", text=PIW+"Angle", icon_value=5, slider=True) + # Sliders + menu.add_item().prop(mask_tex_slot, "angle", + text=utils_core.PIW + "Angle", icon_value=5, slider=True) - if mask_tex_slot.mask_map_mode in ['RANDOM', 'VIEW_PLANE'] and mask_tex_slot.use_random: - menu.add_item().prop(mask_tex_slot, "random_angle", text=PIW+"Random Angle", slider=True) - - # Operator - if mask_tex_slot.mask_map_mode == 'STENCIL': - prop = menu.add_item().operator("brush.stencil_reset_transform") - prop.mask = True + if mask_tex_slot.mask_map_mode in ['RANDOM', 'VIEW_PLANE'] and \ + mask_tex_slot.use_random: + menu.add_item().prop(mask_tex_slot, "random_angle", + text=utils_core.PIW + "Random Angle", slider=True) + # Operator + if mask_tex_slot.mask_map_mode == 'STENCIL': + prop = menu.add_item().operator("brush.stencil_reset_transform") + prop.mask = True + else: + menu.add_item().label("Mask Texture not available", icon="INFO") -class Textures(bpy.types.Menu): + +class Textures(Menu): bl_label = "Brush Texture" bl_idname = "VIEW3D_MT_sv3_texture_list" def init(self): - if get_mode() == sculpt: + if utils_core.get_mode() == utils_core.sculpt: datapath = "tool_settings.sculpt.brush.texture" - elif get_mode() == vertex_paint: + elif utils_core.get_mode() == utils_core.vertex_paint: datapath = "tool_settings.vertex_paint.brush.texture" - elif get_mode() == texture_paint: + elif utils_core.get_mode() == utils_core.texture_paint: datapath = "tool_settings.image_paint.brush.texture" else: @@ -158,8 +171,10 @@ class Textures(bpy.types.Menu): def draw(self, context): datapath = self.init() - current_texture = eval("bpy.context.{}".format(datapath)) - menu = Menu(self) + has_brush = utils_core.get_brush_link(context, types="brush") + current_texture = eval("bpy.context.{}".format(datapath)) if \ + has_brush else None + menu = utils_core.Menu(self) # get the current texture's name if current_texture: @@ -169,7 +184,7 @@ class Textures(bpy.types.Menu): menu.add_item().separator() # add an item to set the texture to None - menuprop(menu.add_item(), "None", "None", + utils_core.menuprop(menu.add_item(), "None", "None", datapath, icon='RADIOBUT_OFF', disable=True, disable_icon='RADIOBUT_ON', custom_disable_exp=[None, current_texture], @@ -177,7 +192,7 @@ class Textures(bpy.types.Menu): # add the menu items for item in bpy.data.textures: - menuprop(menu.add_item(), item.name, + utils_core.menuprop(menu.add_item(), item.name, 'bpy.data.textures["%s"]' % item.name, datapath, icon='RADIOBUT_OFF', disable=True, @@ -186,121 +201,156 @@ class Textures(bpy.types.Menu): path=True) -class TextureMapMode(bpy.types.Menu): +class TextureMapMode(Menu): bl_label = "Brush Mapping" bl_idname = "VIEW3D_MT_sv3_texture_map_mode" def draw(self, context): - menu = Menu(self) + menu = utils_core.Menu(self) + has_brush = utils_core.get_brush_link(context, types="brush") menu.add_item().label(text="Brush Mapping") menu.add_item().separator() - if get_mode() == sculpt: - path = "tool_settings.sculpt.brush.texture_slot.map_mode" - - # add the menu items - for item in context.tool_settings.sculpt.brush.texture_slot.bl_rna.properties['map_mode'].enum_items: - menuprop(menu.add_item(), item.name, item.identifier, path, - icon='RADIOBUT_OFF', - disable=True, - disable_icon='RADIOBUT_ON') - - elif get_mode() == vertex_paint: - path = "tool_settings.vertex_paint.brush.texture_slot.tex_paint_map_mode" - - # add the menu items - for item in context.tool_settings.vertex_paint.brush.texture_slot.bl_rna.properties['tex_paint_map_mode'].enum_items: - menuprop(menu.add_item(), item.name, item.identifier, path, - icon='RADIOBUT_OFF', - disable=True, - disable_icon='RADIOBUT_ON') - + if has_brush: + if utils_core.get_mode() == utils_core.sculpt: + path = "tool_settings.sculpt.brush.texture_slot.map_mode" + + # add the menu items + for item in has_brush. \ + texture_slot.bl_rna.properties['map_mode'].enum_items: + utils_core.menuprop( + menu.add_item(), item.name, item.identifier, path, + icon='RADIOBUT_OFF', + disable=True, + disable_icon='RADIOBUT_ON' + ) + elif utils_core.get_mode() == utils_core.vertex_paint: + path = "tool_settings.vertex_paint.brush.texture_slot.tex_paint_map_mode" + + # add the menu items + for item in has_brush. \ + texture_slot.bl_rna.properties['tex_paint_map_mode'].enum_items: + utils_core.menuprop( + menu.add_item(), item.name, item.identifier, path, + icon='RADIOBUT_OFF', + disable=True, + disable_icon='RADIOBUT_ON' + ) + else: + path = "tool_settings.image_paint.brush.texture_slot.tex_paint_map_mode" + + # add the menu items + for item in has_brush. \ + texture_slot.bl_rna.properties['tex_paint_map_mode'].enum_items: + utils_core.menuprop( + menu.add_item(), item.name, item.identifier, path, + icon='RADIOBUT_OFF', + disable=True, + disable_icon='RADIOBUT_ON' + ) else: - path = "tool_settings.image_paint.brush.texture_slot.tex_paint_map_mode" - - # add the menu items - for item in context.tool_settings.image_paint.brush.texture_slot.bl_rna.properties['tex_paint_map_mode'].enum_items: - menuprop(menu.add_item(), item.name, item.identifier, path, - icon='RADIOBUT_OFF', - disable=True, - disable_icon='RADIOBUT_ON') + menu.add_item().label("No brushes available", icon="INFO") -class MaskTextures(bpy.types.Menu): +class MaskTextures(Menu): bl_label = "Mask Texture" bl_idname = "VIEW3D_MT_sv3_mask_texture_list" def draw(self, context): - menu = Menu(self) + menu = utils_core.Menu(self) datapath = "tool_settings.image_paint.brush.mask_texture" - current_texture = eval("bpy.context.{}".format(datapath)) + has_brush = utils_core.get_brush_link(context, types="brush") + current_texture = eval("bpy.context.{}".format(datapath)) if \ + has_brush else None menu.add_item().label(text="Mask Texture") menu.add_item().separator() - # get the current texture's name - if current_texture: - current_texture = current_texture.name + if has_brush: + # get the current texture's name + if current_texture: + current_texture = current_texture.name - # add an item to set the texture to None - menuprop(menu.add_item(), "None", "None", - datapath, icon='RADIOBUT_OFF', disable=True, - disable_icon='RADIOBUT_ON', - custom_disable_exp=[None, current_texture], - path=True) + # add an item to set the texture to None + utils_core.menuprop( + menu.add_item(), "None", "None", + datapath, icon='RADIOBUT_OFF', disable=True, + disable_icon='RADIOBUT_ON', + custom_disable_exp=[None, current_texture], + path=True + ) - # add the menu items - for item in bpy.data.textures: - menuprop(menu.add_item(), item.name, 'bpy.data.textures["%s"]' % item.name, - datapath, icon='RADIOBUT_OFF', disable=True, - disable_icon='RADIOBUT_ON', - custom_disable_exp=[item.name, current_texture], - path=True) + # add the menu items + for item in bpy.data.textures: + utils_core.menuprop( + menu.add_item(), item.name, 'bpy.data.textures["%s"]' % item.name, + datapath, icon='RADIOBUT_OFF', disable=True, + disable_icon='RADIOBUT_ON', + custom_disable_exp=[item.name, current_texture], + path=True + ) + else: + menu.add_item().label("No brushes available", icon="INFO") -class MaskMapMode(bpy.types.Menu): +class MaskMapMode(Menu): bl_label = "Mask Mapping" bl_idname = "VIEW3D_MT_sv3_mask_map_mode" def draw(self, context): - menu = Menu(self) - + menu = utils_core.Menu(self) path = "tool_settings.image_paint.brush.mask_texture_slot.mask_map_mode" + has_brush = utils_core.get_brush_link(context, types="brush") menu.add_item().label(text="Mask Mapping") menu.add_item().separator() - - # add the menu items - for item in context.tool_settings.image_paint.brush.mask_texture_slot.bl_rna.properties['mask_map_mode'].enum_items: - menuprop(menu.add_item(), item.name, item.identifier, path, - icon='RADIOBUT_OFF', - disable=True, - disable_icon='RADIOBUT_ON') + if has_brush: + items = has_brush. \ + mask_texture_slot.bl_rna.properties['mask_map_mode'].enum_items + # add the menu items + for item in items: + utils_core.menuprop( + menu.add_item(), item.name, item.identifier, path, + icon='RADIOBUT_OFF', + disable=True, + disable_icon='RADIOBUT_ON' + ) + else: + menu.add_item().label("No brushes available", icon="INFO") -class TextureAngleSource(bpy.types.Menu): +class TextureAngleSource(Menu): bl_label = "Texture Angle Source" bl_idname = "VIEW3D_MT_sv3_texture_angle_source" def draw(self, context): - menu = Menu(self) + menu = utils_core.Menu(self) + has_brush = utils_core.get_brush_link(context, types="brush") - if get_mode() == sculpt: - items = context.tool_settings.sculpt.brush.bl_rna.properties['texture_angle_source_random'].enum_items - path = "tool_settings.sculpt.brush.texture_angle_source_random" + if has_brush: + if utils_core.get_mode() == utils_core.sculpt: + items = has_brush. \ + bl_rna.properties['texture_angle_source_random'].enum_items + path = "tool_settings.sculpt.brush.texture_angle_source_random" - elif get_mode() == vertex_paint: - items = context.tool_settings.vertex_paint.brush.bl_rna.properties['texture_angle_source_random'].enum_items - path = "tool_settings.vertex_paint.brush.texture_angle_source_random" + elif utils_core.get_mode() == utils_core.vertex_paint: + items = has_brush. \ + bl_rna.properties['texture_angle_source_random'].enum_items + path = "tool_settings.vertex_paint.brush.texture_angle_source_random" - else: - items = context.tool_settings.image_paint.brush.bl_rna.properties['texture_angle_source_random'].enum_items - path = "tool_settings.image_paint.brush.texture_angle_source_random" + else: + items = has_brush. \ + bl_rna.properties['texture_angle_source_random'].enum_items + path = "tool_settings.image_paint.brush.texture_angle_source_random" - # add the menu items - for item in items: - menuprop(menu.add_item(), item[0], item[1], path, - icon='RADIOBUT_OFF', - disable=True, - disable_icon='RADIOBUT_ON') + # add the menu items + for item in items: + utils_core.menuprop( + menu.add_item(), item[0], item[1], path, + icon='RADIOBUT_OFF', + disable=True, + disable_icon='RADIOBUT_ON' + ) + else: + menu.add_item().label("No brushes available", icon="INFO") |