From BlenderWiki

Jump to: navigation, search

Declarative UI In Blender

For the sourcecode for this see:

This script is pure python declaration. its cumbersome but easy enough to follow if you know python.

Notice each item is a tuple, the first item is a string, the second 2 are am optional dict and an optional list of sub-elements.

class RENDER_PT_stamp(RenderButtonsPanel, bpy.types.Panel):
    bl_label = "Stamp"
    bl_default_closed = True
    COMPAT_ENGINES = {'BLENDER_RENDER'}
 
    draw_header = [
        ("prop", dict(data="context.scene.render", property="render_stamp", text="")),
        ]
 
    draw = [
        ("split", [
          ("column", [
            ("prop", dict(data="context.scene.render", property="stamp_time", text="Time")),
            ("prop", dict(data="context.scene.render", property="stamp_date", text="Date")),
            ("prop", dict(data="context.scene.render", property="stamp_render_time", text="RenderTime")),
            ("prop", dict(data="context.scene.render", property="stamp_frame", text="Frame")),
            ("prop", dict(data="context.scene.render", property="stamp_scene", text="Scene")),
            ("prop", dict(data="context.scene.render", property="stamp_camera", text="Camera")),
            ("prop", dict(data="context.scene.render", property="stamp_filename", text="Filename")),
            ("prop", dict(data="context.scene.render", property="stamp_marker", text="Marker")),
            ("prop", dict(data="context.scene.render", property="stamp_sequencer_strip", text="Seq. Strip")),
            ]
          ),
          ("column", [
            ("active", dict(expr="context.scene.render.render_stamp")),
            ("prop", dict(data="context.scene.render", property="stamp_foreground", slider=True)),
            ("prop", dict(data="context.scene.render", property="stamp_background", slider=True)),
            ("separator", ),
            ("prop", dict(data="context.scene.render", property="stamp_font_size", text="Font Size")),
            ]
          )
        ]),
        ("split", dict(percentage=0.2), [
          ("prop", dict(data="context.scene.render", property="stamp_note", text="Note")),
            ("row", [
              ("active", dict(expr="context.scene.render.stamp_note")),
              ("prop", dict(data="context.scene.render", property="stamp_note_text", text="")),
              ]
            )
          ]
        )
      ]

This example is still pure python but relies on defining custom classes (in our own internal api) which can expand into a basic python data structure like the one above.

Note that this is fully functional and we can use this in blender now.

class RENDER_PT_stamp(RenderButtonsPanel, bpy.types.Panel):
    bl_label = "Stamp"
    bl_default_closed = True
    COMPAT_ENGINES = {'BLENDER_RENDER'}
 
    draw_header = [
        prop(data="context.scene.render", property="render_stamp", text="")
      ]
 
    draw = [
        split() [
          column() [
            prop(data="context.scene.render", property="stamp_time", text="Time"),
            prop(data="context.scene.render", property="stamp_date", text="Date"),
            prop(data="context.scene.render", property="stamp_render_time", text="RenderTime"),
            prop(data="context.scene.render", property="stamp_frame", text="Frame"),
            prop(data="context.scene.render", property="stamp_scene", text="Scene"),
            prop(data="context.scene.render", property="stamp_camera", text="Camera"),
            prop(data="context.scene.render", property="stamp_filename", text="Filename"),
            prop(data="context.scene.render", property="stamp_marker", text="Marker"),
            prop(data="context.scene.render", property="stamp_sequencer_strip", text="Seq. Strip"),
          ],
          column() [
            active(expr="context.scene.render.render_stamp"),
            prop(data="context.scene.render", property="stamp_foreground", slider=True),
            prop(data="context.scene.render", property="stamp_background", slider=True),
            separator(),
            prop(data="context.scene.render", property="stamp_font_size", text="Font Size"),
          ]
        ],
        split(percentage=0.2) [
          prop(data="context.scene.render", property="stamp_note", text="Note"),
          row() [
            active(expr="context.scene.render.stamp_note"),
            prop(data="context.scene.render", property="stamp_note_text", text=""),
          ]
        ]
      ]