[Bf-extensions-cvs] [eb20c644] master: Update sculpt brush menus: T42564

meta-androcto noreply at git.blender.org
Sun Mar 19 06:40:51 CET 2017


Commit: eb20c644e6bd93d0e8aa42ce23274f3c7aeda5e6
Author: meta-androcto
Date:   Sun Mar 19 16:40:20 2017 +1100
Branches: master
https://developer.blender.org/rBACeb20c644e6bd93d0e8aa42ce23274f3c7aeda5e6

Update sculpt brush menus: T42564

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

M	space_view3d_brush_menus/Utils/core.py
D	space_view3d_brush_menus/Utils/keymodes.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

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

diff --git a/space_view3d_brush_menus/Utils/core.py b/space_view3d_brush_menus/Utils/core.py
index 4c7afadf..ea73a87b 100644
--- a/space_view3d_brush_menus/Utils/core.py
+++ b/space_view3d_brush_menus/Utils/core.py
@@ -12,47 +12,52 @@ weight_paint = 'WEIGHT_PAINT'
 texture_paint = 'TEXTURE_PAINT'
 particle_edit = 'PARTICLE_EDIT'
 pose = 'POSE'
+gpencil_edit = 'GPENCIL_EDIT'
 
-a_props = []
+PIW = '       '
 
+a_props = []
 
 class Menu():
-
     def __init__(self, menu):
         self.layout = menu.layout
         self.items = {}
         self.current_item = None
 
-    def add_item(self, ui_type="row", parent=None, **kwargs):
+    def add_item(self, ui_type="row", parent=None, name=None, **kwargs):
         # set the parent layout
         if parent:
             layout = parent
         else:
             layout = self.layout
 
+        # set unique identifier for new items
+        if not name:
+            name = len(self.items) + 1
+            
         # create and return a ui layout
         if ui_type == "row":
-            self.current_item = self.items[len(self.items) + 1] = layout.row(**kwargs)
+            self.current_item = self.items[name] = layout.row(**kwargs)
 
             return self.current_item
 
         elif ui_type == "column":
-            self.current_item = self.items[len(self.items) + 1] = layout.column(**kwargs)
+            self.current_item = self.items[name] = layout.column(**kwargs)
 
             return self.current_item
 
         elif ui_type == "column_flow":
-            self.current_item = self.items[len(self.items) + 1] = layout.column_flow(**kwargs)
+            self.current_item = self.items[name] = layout.column_flow(**kwargs)
 
             return self.current_item
 
         elif ui_type == "box":
-            self.current_item = self.items[len(self.items) + 1] = layout.box(**kwargs)
+            self.current_item = self.items[name] = layout.box(**kwargs)
 
             return self.current_item
 
         elif ui_type == "split":
-            self.current_item = self.items[len(self.items) + 1] = layout.split(**kwargs)
+            self.current_item = self.items[name] = layout.split(**kwargs)
 
             return self.current_item
 
@@ -60,14 +65,42 @@ class Menu():
             print("Unknown Type")
 
 
-def get_mode():
-    return bpy.context.object.mode
+def get_selected():
+    # get the number of verts from the information string on the info header
+    sel_verts_num = (e for e in bpy.context.scene.statistics().split(" | ")
+                     if e.startswith("Verts:")).__next__()[6:].split("/")
+
+    # turn the number of verts from a string to an int
+    sel_verts_num = int(sel_verts_num[0].replace("," ,""))
+
+    # get the number of edges from the information string on the info header
+    sel_edges_num = (e for e in bpy.context.scene.statistics().split(" | ")
+                     if e.startswith("Edges:")).__next__()[6:].split("/")
+
+    # turn the number of edges from a string to an int
+    sel_edges_num = int(sel_edges_num[0].replace(",", ""))
+
+    # get the number of faces from the information string on the info header
+    sel_faces_num = (e for e in bpy.context.scene.statistics().split(" | ")
+                     if e.startswith("Faces:")).__next__()[6:].split("/")
 
+    # turn the number of faces from a string to an int
+    sel_faces_num = int(sel_faces_num[0].replace(",", ""))
 
-def menuprop(item, name, value, data_path, icon='NONE',
-             disable=False, disable_icon=None,
-             custom_disable_exp=None,
-             method=None, path=False):
+    return sel_verts_num, sel_edges_num, sel_faces_num
+
+
+def get_mode():
+    if bpy.context.gpencil_data and \
+    bpy.context.object.mode == object_mode and \
+    bpy.context.scene.grease_pencil.use_stroke_edit_mode:
+        return gpencil_edit
+    else:
+        return bpy.context.object.mode
+
+def menuprop(item, name, value, data_path,
+             icon='NONE', disable=False, disable_icon=None,
+             custom_disable_exp=None, method=None, path=False):
 
     # disable the ui
     if disable:
@@ -112,7 +145,7 @@ def menuprop(item, name, value, data_path, icon='NONE',
     # sets the path to what is changed
     prop.data_path = data_path
 
-
+# used for global blender properties
 def set_prop(prop_type, path, **kwargs):
     kwstring = ""
 
@@ -121,6 +154,10 @@ def set_prop(prop_type, path, **kwargs):
         if type(v) is str:
             v = '"{}"'.format(v)
 
+        if callable(v):
+            exec("from {0} import {1}".format(v.__module__, v.__name__))
+            v = v.__name__
+            
         kwstring += "{0}={1}, ".format(k, v)
 
     kwstring = kwstring[:-2]
@@ -133,10 +170,35 @@ def set_prop(prop_type, path, **kwargs):
 
     return eval(path)
 
-
+# used for removing properties created with set_prop
 def del_props():
     for prop in a_props:
         exec("del {}".format(prop))
 
     a_props.clear()
-
+    
+class SendReport(bpy.types.Operator):
+    bl_label = "Send Report"
+    bl_idname = "view3d.send_report"
+    
+    message = bpy.props.StringProperty()
+    
+    def draw(self, context):
+        self.layout.label("Error", icon='ERROR')
+        self.layout.label(self.message)
+    
+    def invoke(self, context, event):
+        wm = context.window_manager
+        return wm.invoke_popup(self, width=400, height=200)
+    
+    def execute(self, context):
+        self.report({'INFO'}, self.message)
+        print(self.message)
+        return {'FINISHED'}
+    
+def send_report(message):
+    def report(scene):
+        bpy.ops.view3d.send_report('INVOKE_DEFAULT', message=message)
+        bpy.app.handlers.scene_update_pre.remove(report)
+        
+    bpy.app.handlers.scene_update_pre.append(report)
diff --git a/space_view3d_brush_menus/Utils/keymodes.py b/space_view3d_brush_menus/Utils/keymodes.py
deleted file mode 100644
index 6efc460c..00000000
--- a/space_view3d_brush_menus/Utils/keymodes.py
+++ /dev/null
@@ -1,31 +0,0 @@
-from .core import *
-
-# this is a list of keys to deactivate with a list of modes to deactivate them in
-keymodes = [  # key    any   shift  ctrl   alt   oskey               modes
-
-    ['V', False, False, False, True, False, ['Object Non-modal', 'Sculpt', 'Vertex Paint', 'Weight Paint', 'Image Paint']],
-
-]
-
-
-def opposingkeys(activation):
-    wm = bpy.context.window_manager
-
-    # deactivate the opposing keys to prevent clashing and reactivate them on unregister
-    # keymode is a list containing the mode and key you want changed
-    for key in keymodes:
-        # mode is the mode you want the key to be (de)activated for.
-        for mode in key[6]:
-            km = wm.keyconfigs.active.keymaps[mode]
-
-            # this iterates through all the keys in the current
-            # hotkey layout and (de)activates the ones that
-            # match the key we want to (de)activate
-            for kmi in km.keymap_items:
-                #print(kmi.type, "shift={0}".format(kmi.shift), "ctrl={0}".format(kmi.ctrl), "alt={0}".format(kmi.alt))
-                if kmi.type == key[0] and kmi.any == key[1] \
-                        and kmi.shift == key[2] and kmi.ctrl == key[3] \
-                        and kmi.alt == key[4] and kmi.oskey == key[5]:
-
-                    # (de)activate the current key
-                    kmi.active = activation
diff --git a/space_view3d_brush_menus/__init__.py b/space_view3d_brush_menus/__init__.py
index 5f1d5246..6613b82f 100644
--- a/space_view3d_brush_menus/__init__.py
+++ b/space_view3d_brush_menus/__init__.py
@@ -21,10 +21,10 @@
 """ Copyright 2011 GPL licence applies"""
 
 bl_info = {
-    "name": "Sculpt/Paint Menus",
-    "description": "",
-    "author": "Ryan Inch",
-    "version": (1, 1, 2),
+    "name": "Sculpt/Paint Brush Menus",
+    "description": "Fast access to brushes & tools in Sculpt and Paint Modes",
+    "author": "Ryan Inch (Imaginer)",
+    "version": (1, 1, 3),
     "blender": (2, 7, 8),
     "location": "Alt V in Sculpt/Paint Modes",
     "warning": '',  # used for warning icon and text in addons panel
@@ -40,7 +40,6 @@ from bl_ui.properties_paint_common import (
         brush_mask_texture_settings,
         )
 from .Utils.core import *
-from .Utils import keymodes
 
 from . import brush_menu
 from . import brushes
@@ -50,15 +49,6 @@ from . import stroke_menu
 from . import symmetry_menu
 from . import texture_menu
 
-addon_files = [
-    brush_menu,
-    curve_menu,
-    dyntopo_menu,
-    stroke_menu,
-    symmetry_menu,
-    texture_menu,
-]
-
 # Use compact brushes menus #
 def UseBrushesLists():
     # separate function just for more convience
@@ -111,21 +101,6 @@ class VIEW3D_MT_Brush_Selection1(bpy.types.Menu):
                 layout.template_ID_preview(settings, "brush", new="brush.add", rows=3, cols=8)
 
 
- at bpy.app.handlers.persistent
-def scene_update_post_reg(scene):
-    # remove handler
-    bpy.app.handlers.scene_update_post.remove(scene_update_post_reg)
-
-    # disable conflicting hotkeys
-    keymodes.opposingkeys(False)
-
-    # register all blender classes
-    bpy.utils.register_module(__name__)
-
-    # register all files
-    for addon_file in addon_files:
-        addon_file.register()
-
 class VIEW3D_MT_Brushes_Pref(bpy.types.AddonPreferences):
     bl_idname = __name__
 
@@ -143,23 +118,21 @@ class VIEW3D_MT_Brushes_Pref(bpy.types.AddonPreferences):
         row.prop(self, "use_brushes_lists")
 
 def register():
-    # add a handler so blender registers keymaps and stuff after everything has loaded
-    bpy.app.handlers.scene_update_post.append(scene_update_post_reg)
-
+    # register all blender classes
+    bpy.utils.register_module(__name__)
+    
+    # register brush menu
+    brush_menu.register()
 
 def unregister():
-    # unregister all files
-    for addon_file in addon_files:
-        addon_file.unregister()
-
-    # unregister all blender classes
-    bpy.utils.unregister_module(__name__)
-
-    # re-enable all the keymaps you disabled
-    keymodes.opposingkeys(True)
-
+    # unregister brush menu
+    brush_menu.unregister()
+    
     # delete all the properties you have created
     del_props()
+    
+    # unregister all blender

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list