提供: wiki
移動先: 案内検索

Why Code Guidelines?

- Layout files are new in 2.5x, so it's the right time to write and keep them clean.

- Modifying the layout is also interesting for artists. Keep the code as readable as possible is important for them. Also coders who don't work on these files should be able to learn the code as fast as possible.

Which scripts?

These guidelines are for every official python script which use buttons inside of blenders interface. So, all button files inside of release/ui. And other scripts (for Render Povray in release/io) which are bundled with Blender.


Keep assignement names consistent:

"row" for a row layout
"col" for a column layout
"flow" for a column_flow layout. 

Please also use these names for split layouts. For example col = split.column().

Use "sub" for sublayouts, 
and if you need more subsub etc.

Example Code

Some examples how it should look.

The Basic Code of each panel

class MATERIAL_PT_material(MaterialButtonsPanel):
	bl_label = "Shading"

	def draw(self, context):
		layout = self.layout 

		mat = context.material
		ob = context.object
		slot = context.material_slot
		space = context.space_data

First define the layout.

Empty line.

Define all context you need for the panel. Use short and easy assignement names.

Layout Split Code

		split = layout.split()
		col = split.column()
		col.prop(mat, "alpha", slider=True)
		col.prop(mat, "ambient", slider=True)
		col.prop(mat, "emit")
		col.prop(mat, "translucency", slider=True)
		col = split.column()
		col.prop(mat, "z_transparency")
		col.prop(mat, "shadeless")	
		col.prop(mat, "tangent_shading")
		col.prop(mat, "cubic", slider=True)

If you need a sublayout because of align, greying out or something else, use sub as assignement name:

                sub = col.column(align=True)
                sub.prop(mat, "bla")

First define the split.

Empty line.

Now pack every column in 1 block, this improves the readability. Sub layout blocks can be separated as well if this improves the readability.

Greying out

#For greying out first define the active/enabled condition, then put the buttons there:

sub = col.column() = tex.distance_metric == 'MINKOVSKY'
sub.prop(tex, "minkovsky_exponent", text="Exponent")

sub = col.column()
sub.prop(tex, "minkovsky_exponent", text="Exponent") = tex.distance_metric == 'MINKOVSKY'