~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/templates_py/ui_list.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import bpy
2
2
 
3
3
 
4
 
class MATERIAL_UL_matslots_example(bpy.types.UIList):
5
 
    # The draw_item function is called for each item of the collection that is visible in the list.
6
 
    #   data is the RNA object containing the collection,
7
 
    #   item is the current drawn item of the collection,
8
 
    #   icon is the "computed" icon for the item (as an integer, because some objects like materials or textures
9
 
    #   have custom icons ID, which are not available as enum items).
10
 
    #   active_data is the RNA object containing the active property for the collection (i.e. integer pointing to the
11
 
    #   active item of the collection).
12
 
    #   active_propname is the name of the active property (use 'getattr(active_data, active_propname)').
13
 
    #   index is index of the current item in the collection.
14
 
    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
15
 
        ob = data
16
 
        slot = item
17
 
        ma = slot.material
18
 
        # draw_item must handle the three layout types... Usually 'DEFAULT' and 'COMPACT' can share the same code.
 
4
class MESH_UL_mylist(bpy.types.UIList):
 
5
    # Constants (flags)
 
6
    # Be careful not to shadow FILTER_ITEM (i.e. UIList().bitflag_filter_item)!
 
7
    # E.g. VGROUP_EMPTY = 1 << 0
 
8
 
 
9
    # Custom properties, saved with .blend file. E.g.
 
10
    # use_filter_empty = bpy.props.BoolProperty(name="Filter Empty", default=False, options=set(),
 
11
    #                                           description="Whether to filter empty vertex groups")
 
12
 
 
13
    # Called for each drawn item.
 
14
    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag):
 
15
        # 'DEFAULT' and 'COMPACT' layout types should usually use the same draw code.
19
16
        if self.layout_type in {'DEFAULT', 'COMPACT'}:
20
 
            # You should always start your row layout by a label (icon + text), this will also make the row easily
21
 
            # selectable in the list!
22
 
            # We use icon_value of label, as our given icon is an integer value, not an enum ID.
23
 
            # Note "data" names should never be translated!
24
 
            layout.label(text=ma.name if ma else "", translate=False, icon_value=icon)
25
 
            # And now we can add other UI stuff...
26
 
            # Here, we add nodes info if this material uses (old!) shading nodes.
27
 
            if ma and not context.scene.render.use_shading_nodes:
28
 
                manode = ma.active_node_material
29
 
                if manode:
30
 
                    # The static method UILayout.icon returns the integer value of the icon ID "computed" for the given
31
 
                    # RNA object.
32
 
                    layout.label(text="Node %s" % manode.name, translate=False, icon_value=layout.icon(manode))
33
 
                elif ma.use_nodes:
34
 
                    layout.label(text="Node <none>", translate=False)
35
 
                else:
36
 
                    layout.label(text="")
 
17
            pass
37
18
        # 'GRID' layout type should be as compact as possible (typically a single icon!).
38
19
        elif self.layout_type in {'GRID'}:
39
 
            layout.alignment = 'CENTER'
40
 
            layout.label(text="", icon_value=icon)
41
 
 
42
 
 
43
 
# And now we can use this list everywhere in Blender. Here is a small example panel.
44
 
class UIListPanelExample(bpy.types.Panel):
45
 
    """Creates a Panel in the Object properties window"""
46
 
    bl_label = "UIList Panel"
47
 
    bl_idname = "OBJECT_PT_ui_list_example"
48
 
    bl_space_type = 'PROPERTIES'
49
 
    bl_region_type = 'WINDOW'
50
 
    bl_context = "object"
51
 
 
52
 
    def draw(self, context):
53
 
        layout = self.layout
54
 
 
55
 
        obj = context.object
56
 
 
57
 
        # template_list now takes two new args.
58
 
        # The first one is the identifier of the registered UIList to use (if you want only the default list,
59
 
        # with no custom draw code, use "UI_UL_list").
60
 
        layout.template_list("MATERIAL_UL_matslots_example", "", obj, "material_slots", obj, "active_material_index")
61
 
 
62
 
        # The second one can usually be left as an empty string. It's an additional ID used to distinguish lists in case you
63
 
        # use the same list several times in a given area.
64
 
        layout.template_list("MATERIAL_UL_matslots_example", "compact", obj, "material_slots",
65
 
                             obj, "active_material_index", type='COMPACT')
66
 
 
67
 
 
68
 
def register():
69
 
    bpy.utils.register_class(MATERIAL_UL_matslots_example)
70
 
    bpy.utils.register_class(UIListPanelExample)
71
 
 
72
 
 
73
 
def unregister():
74
 
    bpy.utils.unregister_class(MATERIAL_UL_matslots_example)
75
 
    bpy.utils.unregister_class(UIListPanelExample)
76
 
 
77
 
 
78
 
if __name__ == "__main__":
79
 
    register()
 
 
b'\\ No newline at end of file'
 
20
            pass
 
21
 
 
22
    # Called once to draw filtering/reordering options.
 
23
    def draw_filter(self, context, layout):
 
24
        # Nothing much to say here, it's usual UI code...
 
25
        pass
 
26
 
 
27
    # Called once to filter/reorder items.
 
28
    def filter_items(self, context, data, propname):
 
29
        # This function gets the collection property (as the usual tuple (data, propname)), and must return two lists:
 
30
        # * The first one is for filtering, it must contain 32bit integers were self.bitflag_filter_item marks the
 
31
        #   matching item as filtered (i.e. to be shown), and 31 other bits are free for custom needs. Here we use the
 
32
        #   first one to mark VGROUP_EMPTY.
 
33
        # * The second one is for reordering, it must return a list containing the new indices of the items (which
 
34
        #   gives us a mapping org_idx -> new_idx).
 
35
        # Please note that the default UI_UL_list defines helper functions for common tasks (see its doc for more info).
 
36
        # If you do not make filtering and/or ordering, return empty list(s) (this will be more efficient than
 
37
        # returning full lists doing nothing!).
 
38
 
 
39
        # Default return values.
 
40
        flt_flags = []
 
41
        flt_neworder = []
 
42
 
 
43
        # Do filtering/reordering here...
 
44
 
 
45
        return flt_flags, flt_neworder