[Bf-extensions-cvs] [29f2b2f] master: Sculpt Paint Brush Menus: cleanup, refactor, various fixes

lijenstina noreply at git.blender.org
Sat Apr 22 03:58:21 CEST 2017


Commit: 29f2b2f34a8255828cf1621edd5c725167338f9f
Author: lijenstina
Date:   Sat Apr 22 03:54:45 2017 +0200
Branches: master
https://developer.blender.org/rBA29f2b2f34a8255828cf1621edd5c725167338f9f

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

===================================================================

D	space_view3d_brush_menus/Utils/__init__.py
M	space_view3d_brush_menus/__init__.py
M	space_view3d_brush_menus/brush_menu.py
M	space_view3d_brush_menus/brushes.py
M	space_view3d_brush_menus/curve_menu.py
M	space_view3d_brush_menus/dyntopo_menu.py
M	space_view3d_brush_menus/stroke_menu.py
M	space_view3d_brush_menus/symmetry_menu.py
M	space_view3d_brush_menus/texture_menu.py
R050	space_view3d_brush_menus/Utils/core.py	space_view3d_brush_menus/utils_core.py

===================================================================

diff --git a/space_view3d_brush_menus/Utils/__init__.py b/space_view3d_brush_menus/Utils/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/space_view3d_brush_menus/__init__.py b/space_view3d_brush_menus/__init__.py
index 6613b82..a591187 100644
--- a/space_view3d_brush_menus/__init__.py
+++ b/space_view3d_brush_menus/__init__.py
@@ -17,122 +17,115 @@
 # ##### END GPL LICENSE BLOCK #####
 # Modified by Meta-Androcto
 
-
 """ Copyright 2011 GPL licence applies"""
 
 bl_info = {
     "name": "Sculpt/Paint Brush Menus",
     "description": "Fast access to brushes & tools in Sculpt and Paint Modes",
     "author": "Ryan Inch (Imaginer)",
-    "version": (1, 1, 3),
+    "version": (1, 1, 4),
     "blender": (2, 7, 8),
     "location": "Alt V in Sculpt/Paint Modes",
-    "warning": '',  # used for warning icon and text in addons panel
-    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Advanced_UI_Menus",
+    "warning": '',
+    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
+                "Scripts/3D_interaction/Advanced_UI_Menus",
     "category": "3D View"}
 
-import sys
-import os
-from bl_ui.properties_paint_common import (
-        UnifiedPaintPanel,
-        brush_texture_settings,
-        brush_texpaint_common,
-        brush_mask_texture_settings,
-        )
-from .Utils.core import *
 
-from . import brush_menu
-from . import brushes
-from . import curve_menu
-from . import dyntopo_menu
-from . import stroke_menu
-from . import symmetry_menu
-from . import texture_menu
+if "bpy" in locals():
+    import importlib
+    importlib.reload(utils_core)
+    importlib.reload(brush_menu)
+    importlib.reload(brushes)
+    importlib.reload(curve_menu)
+    importlib.reload(dyntopo_menu)
+    importlib.reload(stroke_menu)
+    importlib.reload(symmetry_menu)
+    importlib.reload(texture_menu)
+else:
+    from . import utils_core
+    from . import brush_menu
+    from . import brushes
+    from . import curve_menu
+    from . import dyntopo_menu
+    from . import stroke_menu
+    from . import symmetry_menu
+    from . import texture_menu
+
+
+import bpy
+from bpy.types import AddonPreferences
+from bpy.props import (
+        EnumProperty,
+        IntProperty,
+        )
 
-# Use compact brushes menus #
-def UseBrushesLists():
-    # separate function just for more convience
-    useLists = bpy.context.user_preferences.addons[__name__].preferences.use_brushes_lists
 
-    return bool(useLists)
+class VIEW3D_MT_Brushes_Pref(AddonPreferences):
+    bl_idname = __name__
 
-class VIEW3D_MT_Brush_Selection1(bpy.types.Menu):
-    bl_label = "Brush Tool"
+    use_brushes_menu_type = EnumProperty(
+        name="Choose Brushes Selection",
+        description="",
+        items=[('lists', "Use compact Menus",
+                "Use more compact menus instead  \n"
+                "of thumbnails for displaying brushes"),
+               ('template', "Template ID Preview",
+                "Use Template ID preview menu (thumbnails) for brushes\n"
+                "(Still part of the menu)"),
+               ('popup', "Pop up menu",
+                "Use a separate pop-up window for accessing brushes")
+            ],
+        default='lists'
+        )
+    column_set = IntProperty(
+        name="Number of Columns",
+        description="Number of columns used for the brushes menu",
+        default=2,
+        min=1,
+        max=10
+        )
 
     def draw(self, context):
         layout = self.layout
-        settings = UnifiedPaintPanel.paint_settings(context)
-
-        # check if brush exists (for instance, in paint mode before adding a slot)
-        if hasattr(settings, 'brush'):
-            brush = settings.brush
-        else:
-            brush = None
-
-        if not brush:
-            return
-
-        if not context.particle_edit_object:
-            if UseBrushesLists():
-                flow = layout.column_flow(columns=3)
-
-                for brsh in bpy.data.brushes:
-                    if (context.sculpt_object and brsh.use_paint_sculpt):
-                        props = flow.operator("wm.context_set_id", text=brsh.name,
-                                              icon_value=layout.icon(brsh))
-                        props.data_path = "tool_settings.sculpt.brush"
-                        props.value = brsh.name
-                    elif (context.image_paint_object and brsh.use_paint_image):
-                        props = flow.operator("wm.context_set_id", text=brsh.name,
-                                              icon_value=layout.icon(brsh))
-                        props.data_path = "tool_settings.image_paint.brush"
-                        props.value = brsh.name
-                    elif (context.vertex_paint_object and brsh.use_paint_vertex):
-                        props = flow.operator("wm.context_set_id", text=brsh.name,
-                                              icon_value=layout.icon(brsh))
-                        props.data_path = "tool_settings.vertex_paint.brush"
-                        props.value = brsh.name
-                    elif (context.weight_paint_object and brsh.use_paint_weight):
-                        props = flow.operator("wm.context_set_id", text=brsh.name,
-                                              icon_value=layout.icon(brsh))
-                        props.data_path = "tool_settings.weight_paint.brush"
-                        props.value = brsh.name
-            else:
-                layout.template_ID_preview(settings, "brush", new="brush.add", rows=3, cols=8)
-
-
-class VIEW3D_MT_Brushes_Pref(bpy.types.AddonPreferences):
-    bl_idname = __name__
 
+        col = layout.column(align=True)
+        row = col.row(align=True)
+        row.prop(self, "use_brushes_menu_type", expand=True)
+        col.prop(self, "column_set", slider=True)
 
-    use_brushes_lists = bpy.props.BoolProperty(
-        name="Use compact menus for brushes",
-        default=True,
-        description=("Use more compact menus instead  \n"
-                     "of thumbnails for displaying brushes")
-    )
 
-    def draw(self, context):
-        layout = self.layout
-        row = layout.row()
-        row.prop(self, "use_brushes_lists")
+# New hotkeys and registration
+
+addon_keymaps = []
+
 
 def register():
     # register all blender classes
     bpy.utils.register_module(__name__)
-    
-    # register brush menu
-    brush_menu.register()
+
+    # set the add-on name variable to access the preferences
+    utils_core.get_addon_name = __name__
+
+    # register hotkeys
+    wm = bpy.context.window_manager
+    modes = ['Sculpt', 'Vertex Paint', 'Weight Paint', 'Image Paint', 'Particle']
+
+    for mode in modes:
+        km = wm.keyconfigs.addon.keymaps.new(name=mode)
+        kmi = km.keymap_items.new('wm.call_menu', 'V', 'PRESS', alt=True)
+        kmi.properties.name = "VIEW3D_MT_sv3_brush_options"
+        addon_keymaps.append((km, kmi))
+
 
 def unregister():
-    # unregister brush menu
-    brush_menu.unregister()
-    
-    # delete all the properties you have created
-    del_props()
-    
+    for km, kmi in addon_keymaps:
+        km.keymap_items.remove(kmi)
+    addon_keymaps.clear()
+
     # unregister all blender classes
     bpy.utils.unregister_module(__name__)
 
+
 if __name__ == "__main__":
     register()
diff --git a/space_view3d_brush_menus/brush_menu.py b/space_view3d_brush_menus/brush_menu.py
index 91daf19..6940304 100644
--- a/space_view3d_brush_menus/brush_menu.py
+++ b/space_view3d_brush_menus/brush_menu.py
@@ -1,156 +1,212 @@
-from bpy.props import *
-from .Utils.core import *
+# gpl author: Ryan Inch (Imaginer)
+
+import bpy
+from bpy.types import (
+        Operator,
+        Menu,
+        )
+from bpy.props import BoolProperty
+from . import utils_core
+from bl_ui.properties_paint_common import UnifiedPaintPanel
+
 
 def get_current_brush_icon(tool):
-    if get_mode() == sculpt:
-        icons = {"BLOB":'BRUSH_BLOB',
-                "CLAY":'BRUSH_CLAY',
-                "CLAY_STRIPS":'BRUSH_CLAY_STRIPS',
-                "CREASE":'BRUSH_CREASE',
-                "DRAW":'BRUSH_SCULPT_DRAW',
-                "FILL":'BRUSH_FILL',
-                "FLATTEN":'BRUSH_FLATTEN',
-                "GRAB":'BRUSH_GRAB',
-                "INFLATE":'BRUSH_INFLATE',
-                "LAYER":'BRUSH_LAYER',
-                "MASK":'BRUSH_MASK',
-                "NUDGE":'BRUSH_NUDGE',
-                "PINCH":'BRUSH_PINCH',
-                "ROTATE":'BRUSH_ROTATE',
-                "SCRAPE":'BRUSH_SCRAPE',
-                "SIMPLIFY":'BRUSH_SUBTRACT',
-                "SMOOTH":'BRUSH_SMOOTH',
-                "SNAKE_HOOK":'BRUSH_SNAKE_HOOK',
-                "THUMB":'BRUSH_THUMB'}
-
-    elif get_mode() == vertex_paint:
-        icons = {"ADD":'BRUSH_ADD',
-                "BLUR":'BRUSH_BLUR',
-                "DARKEN":'BRUSH_DARKEN',
-                "LIGHTEN":'BRUSH_LIGHTEN',
-                "MIX":'BRUSH_MIX',
-                "MUL":'BRUSH_MULTIPLY',
-                "SUB":'BRUSH_SUBTRACT'}
-
-    elif get_mode() == weight_paint:
-        icons = {"ADD":'BRUSH_ADD',
-                "BLUR":'BRUSH_BLUR',
-                "DARKEN":'BRUSH_DARKEN',
-                "LIGHTEN":'BRUSH_LIGHTEN',
-                "MIX":'BRUSH_MIX',
-                "MUL":'BRUSH_MULTIPLY',
-                "SUB":'BRUSH_SUBTRACT'}
-
-    elif get_mode() == texture_paint:
-        icons = {"CLONE":'BRUSH_CLONE',
-                "DRAW":'BRUSH_TEXDRAW',
-                "FILL":'BRUSH_TEXFILL',
-                "MASK":'BRUSH_TEXMASK',
-                "SMEAR":'BRUSH_SMEAR',
-                "SOFTEN":'BRUSH_SOFTEN'}
-                
+    if utils_core.get_mode() == utils_core.sculpt:
+        icons = {"BLOB": 'BRUSH_BLOB',
+                "CLAY": 'BRUSH_CLAY',
+                "CLAY_STRIPS": 'BRUSH_CLAY_STRIPS',
+                "CREASE": 'BRUSH_CREASE',
+                "DRAW": 'BRUSH_SCULPT_DRAW',
+                "FILL": 'BRUSH_FILL',
+                "FLATTEN": 'BRUSH_FLATTEN',
+                "GRAB": 'BRUSH_GRAB',
+                "INFLATE": 'BRUSH_INFLATE',
+                "LAYER": 'BRUSH_LAYER',
+               

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list