[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53355] trunk/blender: This commit frees list ui items from their dependencies to Panel, and hence from all the limitations this implied (mostly, the " only one list per panel" one).

Bastien Montagne montagne29 at wanadoo.fr
Fri Dec 28 14:31:15 CET 2012


Arg, forgot to thanks Campbell for his useful review and advices for 
this patch! Sorry.

On 28/12/2012 10:20, Bastien Montagne wrote:
> Revision: 53355
>            http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53355
> Author:   mont29
> Date:     2012-12-28 09:20:16 +0000 (Fri, 28 Dec 2012)
> Log Message:
> -----------
> This commit frees list ui items from their dependencies to Panel, and hence from all the limitations this implied (mostly, the "only one list per panel" one).
>
> It introduces a new (py-extendable and registrable) RNA type, UIList (roughly similar to Panel one), which currently contains only "standard" list's scroll pos and size (but may be expended to include e.g. some filtering data, etc.). This now makes lists completely independent from Panels!
>
> This UIList has a draw_item callback which allows to customize items' drawing from python, that all addons can now use. Incidentally, this also greatly simplifies the C code of this widget, as we do not code any "special case" here anymore!
>
> To make all this work, other changes were also necessary:
>
> * Now all buttons (uiBut struct) have a 'custom_data' void pointer, used currently to store the uiList struct associated with a given uiLayoutListBox.
>
> * DynamicPaintSurface now exposes a new bool, use_color_preview (readonly), saying whether that surface has some 3D view preview data or not.
>
> * UILayout class has now four new (static) functions, to get the actual icon of any RNA object (important e.g. with materials or textures), and to get an enum item's UI name, description and icon.
>
> * UILayout's label() func now takes an optional 'icon_value' integer parameter, which if not zero will override the 'icon' one (mandatory to use "custom" icons as generated for material/texture/... previews).
>    Note: not sure whether we should add that one to all UILayout's prop funcs?
>
> Note: will update addons using template list asap.
>
> Modified Paths:
> --------------
>      trunk/blender/release/scripts/modules/bpy_types.py
>      trunk/blender/release/scripts/startup/bl_ui/__init__.py
>      trunk/blender/release/scripts/startup/bl_ui/properties_data_armature.py
>      trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py
>      trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py
>      trunk/blender/release/scripts/startup/bl_ui/properties_material.py
>      trunk/blender/release/scripts/startup/bl_ui/properties_particle.py
>      trunk/blender/release/scripts/startup/bl_ui/properties_physics_common.py
>      trunk/blender/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py
>      trunk/blender/release/scripts/startup/bl_ui/properties_render.py
>      trunk/blender/release/scripts/startup/bl_ui/properties_scene.py
>      trunk/blender/release/scripts/startup/bl_ui/properties_texture.py
>      trunk/blender/release/scripts/startup/bl_ui/space_clip.py
>      trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py
>      trunk/blender/source/blender/blenkernel/BKE_screen.h
>      trunk/blender/source/blender/blenloader/intern/readfile.c
>      trunk/blender/source/blender/blenloader/intern/writefile.c
>      trunk/blender/source/blender/editors/include/UI_interface.h
>      trunk/blender/source/blender/editors/include/UI_interface_icons.h
>      trunk/blender/source/blender/editors/interface/interface_handlers.c
>      trunk/blender/source/blender/editors/interface/interface_icons.c
>      trunk/blender/source/blender/editors/interface/interface_intern.h
>      trunk/blender/source/blender/editors/interface/interface_layout.c
>      trunk/blender/source/blender/editors/interface/interface_templates.c
>      trunk/blender/source/blender/editors/space_node/drawnode.c
>      trunk/blender/source/blender/makesdna/DNA_screen_types.h
>      trunk/blender/source/blender/makesrna/RNA_access.h
>      trunk/blender/source/blender/makesrna/RNA_enum_types.h
>      trunk/blender/source/blender/makesrna/intern/rna_dynamicpaint.c
>      trunk/blender/source/blender/makesrna/intern/rna_ui.c
>      trunk/blender/source/blender/makesrna/intern/rna_ui_api.c
>      trunk/blender/source/blender/python/intern/bpy_rna.c
>      trunk/blender/source/blender/windowmanager/WM_api.h
>      trunk/blender/source/blender/windowmanager/intern/wm.c
>      trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c
>      trunk/blender/source/blenderplayer/bad_level_call_stubs/stubs.c
>
> Modified: trunk/blender/release/scripts/modules/bpy_types.py
> ===================================================================
> --- trunk/blender/release/scripts/modules/bpy_types.py	2012-12-28 09:06:48 UTC (rev 53354)
> +++ trunk/blender/release/scripts/modules/bpy_types.py	2012-12-28 09:20:16 UTC (rev 53355)
> @@ -673,6 +673,10 @@
>       __slots__ = ()
>
>
> +class UIList(StructRNA, _GenericUI, metaclass=RNAMeta):
> +    __slots__ = ()
> +
> +
>   class Header(StructRNA, _GenericUI, metaclass=RNAMeta):
>       __slots__ = ()
>
>
> Modified: trunk/blender/release/scripts/startup/bl_ui/__init__.py
> ===================================================================
> --- trunk/blender/release/scripts/startup/bl_ui/__init__.py	2012-12-28 09:06:48 UTC (rev 53354)
> +++ trunk/blender/release/scripts/startup/bl_ui/__init__.py	2012-12-28 09:20:16 UTC (rev 53355)
> @@ -132,3 +132,9 @@
>
>   def unregister():
>       bpy.utils.unregister_module(__name__)
> +
> +# Define a default UIList, when a list does not need any custom drawing...
> +class UI_UL_list(bpy.types.UIList):
> +    pass
> +
> +bpy.utils.register_class(UI_UL_list)
>
> Modified: trunk/blender/release/scripts/startup/bl_ui/properties_data_armature.py
> ===================================================================
> --- trunk/blender/release/scripts/startup/bl_ui/properties_data_armature.py	2012-12-28 09:06:48 UTC (rev 53354)
> +++ trunk/blender/release/scripts/startup/bl_ui/properties_data_armature.py	2012-12-28 09:20:16 UTC (rev 53355)
> @@ -124,7 +124,7 @@
>           rows = 2
>           if group:
>               rows = 5
> -        row.template_list(pose, "bone_groups", pose.bone_groups, "active_index", rows=rows)
> +        row.template_list("UI_UL_list", "", pose, "bone_groups", pose.bone_groups, "active_index", rows=rows)
>
>           col = row.column(align=True)
>           col.active = (ob.proxy is None)
> @@ -184,7 +184,7 @@
>           if poselib:
>               # list of poses in pose library
>               row = layout.row()
> -            row.template_list(poselib, "pose_markers", poselib.pose_markers, "active_index", rows=5)
> +            row.template_list("UI_UL_list", "", poselib, "pose_markers", poselib.pose_markers, "active_index", rows=5)
>
>               # column of operators for active pose
>               # - goes beside list
>
> Modified: trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py
> ===================================================================
> --- trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py	2012-12-28 09:06:48 UTC (rev 53354)
> +++ trunk/blender/release/scripts/startup/bl_ui/properties_data_mesh.py	2012-12-28 09:20:16 UTC (rev 53355)
> @@ -18,7 +18,7 @@
>
>   #<pep8 compliant>
>   import bpy
> -from bpy.types import Menu, Panel
> +from bpy.types import Menu, Panel, UIList
>   from rna_prop_ui import PropertyPanel
>
>
> @@ -54,6 +54,57 @@
>           layout.operator("object.shape_key_add", icon='ZOOMIN', text="New Shape From Mix").from_mix = True
>
>
> +class MESH_UL_vgroups(UIList):
> +    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
> +        if not isinstance(item, bpy.types.VertexGroup):
> +            return
> +        vgroup = item
> +        if self.layout_type in {'DEFAULT', 'COMPACT'}:
> +            layout.label(vgroup.name, icon_value=icon)
> +            icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
> +            layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
> +        elif self.layout_type in {'GRID'}:
> +            layout.alignment = 'CENTER'
> +            layout.label("", icon_value=icon)
> +
> +
> +class MESH_UL_shape_keys(UIList):
> +    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
> +        if not isinstance(item, bpy.types.ShapeKey):
> +            return
> +        obj = active_data
> +        key = data
> +        key_block = item
> +        if self.layout_type in {'DEFAULT', 'COMPACT'}:
> +            split = layout.split(0.66, False)
> +            split.label(item.name, icon_value=icon)
> +            row = split.row(True)
> +            if key_block.mute or (obj.mode == 'EDIT' and not (obj.use_shape_key_edit_mode and obj.type == 'MESH')):
> +                row.active = False
> +            if not item.relative_key or index>  0:
> +                row.prop(key_block, "value", text="", emboss=False)
> +            else:
> +                row.label("")
> +            row.prop(key_block, "mute", text="", emboss=False)
> +        elif self.layout_type in {'GRID'}:
> +            layout.alignment = 'CENTER'
> +            layout.label("", icon_value=icon)
> +
> +
> +class MESH_UL_uvmaps_vcols(UIList):
> +    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
> +        if not isinstance(item, (bpy.types.MeshTexturePolyLayer, bpy.types.MeshLoopColorLayer)):
> +            print(item.__class__)
> +            return
> +        if self.layout_type in {'DEFAULT', 'COMPACT'}:
> +            layout.label(item.name, icon_value=icon)
> +            icon = 'RESTRICT_RENDER_OFF' if item.active_render else 'RESTRICT_RENDER_ON'
> +            layout.prop(item, "active_render", text="", icon=icon, emboss=False)
> +        elif self.layout_type in {'GRID'}:
> +            layout.alignment = 'CENTER'
> +            layout.label("", icon_value=icon)
> +
> +
>   class MeshButtonsPanel():
>       bl_space_type = 'PROPERTIES'
>       bl_region_type = 'WINDOW'
> @@ -144,8 +195,9 @@
>               rows = 5
>
>           row = layout.row()
> -        row.template_list(ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
> +        row.template_list("MESH_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
>
> +
>           col = row.column(align=True)
>           col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
>           col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="").all = False
> @@ -202,7 +254,7 @@
>           rows = 2
>           if kb:
>               rows = 5
> -        row.template_list(key, "key_blocks", ob, "active_shape_key_index", rows=rows)
> +        row.template_list("MESH_UL_shape_keys", "", key, "key_blocks", ob, "active_shape_key_index", rows=rows)
>
>           col = row.column()
>
> @@ -282,7 +334,7 @@
>           row = layout.row()
>           col = row.column()
>
> -        col.template_list(me, "uv_textures", me.uv_textures, "active_index", rows=2)
> +        col.template_list("MESH_UL_uvmaps_vcols", "", me, "uv_textures", me.uv_textures, "active_index", rows=2)
>
>           col = row.column(align=True)
>           col.operator("mesh.uv_texture_add", icon='ZOOMIN', text="")
> @@ -305,7 +357,7 @@
>           row = layout.row()
>           col = row.column()
>
> -        col.template_list(me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
> +        col.template_list("MESH_UL_uvmaps_vcols", "", me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
>
>           col = row.column(align=True)
>           col.operator("mesh.vertex_color_add", icon='ZOOMIN', text="")
>
> Modified: trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py
> ===================================================================
> --- trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py	2012-12-28 09:06:48 UTC (rev 53354)
> +++ trunk/blender/release/scripts/startup/bl_ui/properties_mask_common.py	2012-12-28 09:20:16 UTC (rev 53355)
> @@ -22,9 +22,27 @@
>   # menus are referenced `as is`
>
>   import bpy
> -from bpy.types import Menu
> +from bpy.types import Menu, UIList
>
>
> +class MASK_UL_layers(UIList):
> +    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
> +        if not isinstance(item, bpy.types.MaskLayer):
> +            return
> +        mask = item
> +        if self.layout_type in {'DEFAULT', 'COMPACT'}:
> +            split = layout.split()
> +            split.label(mask.name, icon_value=icon)
> +            row = split.row(align=True)
> +            row.prop(mask, "alpha", text="", emboss=False)
> +            row.prop(mask, "hide", text="", emboss=False)
> +            row.prop(mask, "hide_select", text="", emboss=False)
> +            row.prop(mask, "hide_render", text="", emboss=False)
> +        elif self.layout_type in {'GRID'}:
> +            layout.alignment = 'CENTER'
> +            layout.label("", icon_value=icon)
> +
> +
>   class MASK_PT_mask:
>       # subclasses must define...
>       #~ bl_space_type = 'CLIP_EDITOR'
> @@ -69,8 +87,7 @@
>           rows = 5 if active_layer else 2
>
>           row = layout.row()
> -        row.template_list(mask, "layers",
> -                          mask, "active_layer_index", rows=rows)
> +        row.template_list("MASK_UL_layers", "", mask, "layers", mask, "active_layer_index", rows=rows)
>
>           sub = row.column(align=True)
>
>
> Modified: trunk/blender/release/scripts/startup/bl_ui/properties_material.py
> ===================================================================
> --- trunk/blender/release/scripts/startup/bl_ui/properties_material.py	2012-12-28 09:06:48 UTC (rev 53354)
> +++ trunk/blender/release/scripts/startup/bl_ui/properties_material.py	2012-12-28 09:20:16 UTC (rev 53355)
> @@ -18,7 +18,7 @@
>
>   #<pep8 compliant>
>   import bpy
> -from bpy.types import Menu, Panel
> +from bpy.types import Menu, Panel, UIList
>   from rna_prop_ui import PropertyPanel
>
>
> @@ -69,6 +69,26 @@
>           layout.operator("material.paste", icon='PASTEDOWN')
>
>
> +class MATERIAL_UL_matslots(UIList):
> +    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
> +        if not isinstance(item, bpy.types.MaterialSlot):
> +            return
> +        ob = data
> +        slot = item
> +        ma = slot.material
> +        if self.layout_type in {'DEFAULT', 'COMPACT'}:
> +            layout.label(ma.name if ma else "", icon_value=icon)
> +            if ma and not context.scene.render.use_shading_nodes:
> +                manode = ma.active_node_material
> +                if manode:
> +                    layout.label("Node %s" % manode.name, icon_value=layout.icon(manode))
> +                elif ma.use_nodes:
> +                    layout.label("Node<none>")
> +        elif self.layout_type in {'GRID'}:
> +            layout.alignment = 'CENTER'
> +            layout.label("", icon_value=icon)
> +
> +
>   class MaterialButtonsPanel():
>       bl_space_type = 'PROPERTIES'
>       bl_region_type = 'WINDOW'
> @@ -104,7 +124,7 @@
>           if ob:
>               row = layout.row()
>
> -            row.template_list(ob, "material_slots", ob, "active_material_index", rows=2)
>
> @@ Diff output truncated at 10240 characters. @@
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>



More information about the Bf-committers mailing list