This post has been updated for Blender 2.5 build 31315
Script example 2
# version 1.3.0
# tested on 31315
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
bl_label = "Ping Pong"
display = 0
def draw_header(self, context):
layout = self.layout
def draw(self, context):
layout = self.layout
row = layout.row()
split = row.split(percentage=0.5)
colL = split.column()
colR = split.column()
if self.display == 0:
bl_label = "PingPong operator"
bl_idname = "pipo"
bl_description = "Move the ball"
def invoke(self, context, event):
self.report("INFO", "Moving the ball")
bpy.types.OBJECT_PT_pingpong.display = 1 - bpy.types.OBJECT_PT_pingpong.display
You'll find the new panel at the bottom of the object properties.
Whenever you press the button, another button shows up and the text "Moving the ball" is displayed in Blender's infobar (usually top right of your screen).
The OBJECT_PT_pingpong class is to draw the gui.
'bl_space_type' is the kind of space it shows upis. "PROPERTIES" is the new name for what the buttons window was in Blender 2.4x, so that's where you'll find it.
'bl_region_type' is the kind of region it shows up in.
'bl_context' is when the panel will show (so you will need to have an object selected, for the panel to show up).
'bl_label' is the text displayed in the header.
'display' is a custom variable which we use te determine which button needs to be displayed.
'draw_header' is used to draw extra things in the header. In our case an icon. You can also use it to draw a checkbox that enables or disables all the settings in the panel.
'draw' defines the content of the panel. There is a single row, which is split in half. Each half contains a column. Aditionally we draw a button in one of these columns. The 'display' variable determines which one we draw. 0 = the left one, 1 = the right one. These buttons refer to an operator called 'pipo', which is the idname of the next class.
The OBJECT_OT_pingpong class defines our custom operator.
'bl_label' is the default text that's used by buttons in the user-interface (which we overwrite by for instance: text="Ping" )
'bl_idname' is what we use to refer to this operator.
'bl_description' is the text that shows up when you hover over a button that calls this operator (a bit like a tooltip).
'invoke' is called whenever a button calls the class.
'report' displays a message in the main header of Blender. After this line we also set the 'display' variable to the other value (0 if it's 1 right now, and vice versa).
Please feel free to discuss this example, or add your own examples. I'll add a table of contents to the first post with direct links to the posts containing the examples.