Page MenuHome

Ping Pong: introduction to panels and operators
Closed, ArchivedPublicPATCH

Description

Project: Blender Extensions
Tracker: Py Scripts Upload
Blender: 2.54
Category: Templates
Python: 3.1
Script name: Ping Pong
Author(s): Crouch
Status: Closed

This script is uploaded as a simple example to get started with scripting in Blender. Below you'll find an explanation of how it works.



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).

Event Timeline

I've uploaded this script as I got a request by PKHG to make it publicly available in the tracker. This makes it easier for other people to alter and keep track of changes.

I have added the description and the source code to the Blender 2.5 Python Cookbook here: http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Python/Panels_and_Operators:Ping_Pong
Any additional changes, etc. can be added/discussed there.

Any problems with this, please contact me.

Jonathan Smith (jaydez) changed the task status from Unknown Status to Unknown Status.Dec 22 2010, 2:17 PM