Adding controls to 2.5 property panel?

Hi All,

I am diving into creating a GUI.

I want to extend the properties panel. I want to add sliders, text input boxes, check boxes and color pickers.

But I can only get a button to show up. How do I add these items and how do I process the events they generate?

Here is my extension of the simple panel script.


import bpy

# All clicks route to here...why not?
def click_processor(passedName, passedLabel, passedContext):
    print("_click:" + passedName + " [" + passedLabel + "].")


# Click classes.  
class btn_UseCaps(bpy.types.Operator):
    bl_idname = "btn_use_caps"
    bl_label = "A click processor."
    def execute(self, context):
        click_processor(self.bl_idname, self.bl_label, context)
        return {'FINISHED'}
    
class OBJECT_PT_hello(bpy.types.Panel):
    bl_label = "Hello World Panel"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"

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

        obj = context.object

        row = layout.row()
        row.label(text="Hello world!", icon='WORLD_DATA')

        row = layout.row()
        row.label(text="Active object is: " + obj.name)
        row = layout.row()
        row.prop(obj, "name")
        row.operator("btn_use_caps", text="Make CAPS:OFF", icon='RENDER_STILL')

Thanks!

just add properties to it !

there was an example fo this 2 months ago

Salutations

Be more helpful please by giving a link to what you refer to :eyebrowlift:
Or be concrete …

i cannot find find where i put this menu example for this

i’m still searching it on my disk!

when i find it i 'll show it !

salutations

i was unable to find the original sample script for this!

but here is a modified script i did some times ago looks in the operators’ panel
see all sort of properties type


	
import bpy
	
	
import mathutils
from math import *
from bpy.props import *
	
"""
Name: 'General Triangles'
Blender: 250
	
"""
__author__ = ["Rickyblender  "]
__version__ = '0.0.1'
__url__ = ["                       "]
__bpydoc__ = """
	
	
		
Usage:
	
	
"""
	
last_method = 'None'
last_methodmenu1= 'None'
	
hypo=0.0
	
	
#####################################################################################################
	
	
	
#####################################################################################################
	

	
#####################################################################################################
	
########################################################################
	
	
	
	
stringsubtypes = [ 'FILE_PATH', 'DIR_PATH', 'FILENAME']
for subtype in stringsubtypes:
	bpy.types.Scene.StringProperty(  attr = 'String' + subtype, subtype= subtype)
	
bpy.types.Scene.BoolProperty(  attr = 'Myfirst label', default = True)
	
	
	
subtypes = ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE','XYZ', 'COLOR_GAMMA', 'LAYER']#, 'NONE']
for subtype in subtypes:
	bpy.types.Scene.FloatVectorProperty(  attr = 'FloatVector1' + subtype, default = [0.0, 0.0, 0.0], subtype= subtype)
	
	
	
	
class mytriangPanel1(bpy.types.Panel):				#  This is the panel
	
#  Panel
	
	bl_label = "Triangles  type "						#  Called this
	bl_space_type = "VIEW_3D"							#  in 3D view
	bl_region_type = "TOOL_PROPS"						#  in Operator's panel in tool shelf
	
	
	#	http://www.blender.org/documentation/250PythonDoc/bpy.types.Operator.html?highlight=bpy.types.operator#bpy.types.Operator.draw
	
	def draw(self, context):
	
	
		layout = self.layout
		scene = context.scene
	
		col = layout.column()
		row = col.row()
		row.label('Label1:')
		col.prop(scene, "Myfirst label", text = "the First label")
		col.separator()
		col.label('float Vector right here:') 
		subtype ='XYZ'
		col.prop(scene, 'FloatVector1' +subtype  )
	
		col.separator()
		col = layout.column()
		col.label(' A menu that executes operators:', 'UI')
		col.operator_menu_enum('view_3d.my_operator1', 'method1', 'Operate')		#  Here the operator menu is displayed
	
		print ('in Triangel panel  Selection =',last_methodmenu1)		# This is not printed  if inside the main class
	
	
######################################################
	
	
	
class mytrianglemenu1(bpy.types.Operator):				#   When an option in the operator menu is clicked, this is called
	
#	Operator
	
	bl_idname = 'view_3d.my_operator1'
	bl_label = 'Operator'
	
#	Define possible operations
	
	method1 = EnumProperty(items=(
		('1 inclass', 'List  1', 'The first item 111'),
		('2 inclass', 'List 2', 'The second item 222'),
		('3 inclass', 'Lsit 3', 'The third item 333'),
		('4 inclass', 'List 4', 'The Fourth item 444')))
	
	
	def execute(self, context):
		global last_methodmenu1							#  Make global so we can later draw it in the panel
	
		last_methodmenu1 = self.properties.method1		#  Store the choosen operation
	
	
		print ('in mytrianglemenu1  Selection =',last_methodmenu1)  
	
		return {'FINISHED'}
	
	
	
######################################################
	
#############################################################
	
	
	
#	http://www.blender.org/documentation/250PythonDoc/bpy.types.Operator.html?highlight=bpy.types.operator#bpy.types.Operator.draw
	
#############################################################
	
	
	
#	http://www.blender.org/documentation/250PythonDoc/bpy.types.Operator.html?highlight=bpy.types.operator#bpy.types.Operator.draw
	
	
	
class Add4545Triang(bpy.types.Operator):
	
	bl_idname = "mesh.primitive_4545TrianRect_add"
	bl_label = "Add 45X45_Tri_BH"
	bl_options = {'REGISTER', 'UNDO'}
	
	print ('my class add4545trigang')
	
	
	
#   Add a 45 D X 45 D Triang   mesh.
	
###############
	
	
	
	
	
	
	
	
bpy.types.Scene.BoolProperty(  attr = 'MyBoolProperty', default = True)
	
	
	
#bpy.types.Scene.FloatVectorProperty(  attr = 'FloatVector' + 'XYZ', default = [0.0, 0.0, 0.0], subtype= 'XYZ')
	
#bpy.types.Scene.FloatVectorProperty(  attr = 'FloatVector' + 'XYZ', default = [0.0, 0.0, 0.0], subtype= 'XYZ')
	
	
subtypes = ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE','XYZ', 'COLOR_GAMMA', 'LAYER']#, 'NONE']
for subtype in subtypes:
	bpy.types.Scene.FloatVectorProperty(  attr = 'FloatVector' + subtype, default = [0.0, 0.0, 0.0], subtype= subtype)
	
##############
	
last_method = 'None'
	
class myPanel(bpy.types.Panel):				#  This is the panel
	
#  Panel
	
	bl_label = "Menu Examples"					#  Called this
	bl_space_type = "VIEW_3D"					#  in 3D view
	bl_region_type = "TOOL_PROPS"				#  in Operator's panel in tool shelf
	
	def draw(self, context):
		global last_method						#  make this global to find the last operation
	
		layout = self.layout
		scene = context.scene
		
		col = layout.column()
		col.label(' A menu that executes operators:', 'UI')
		col.operator_menu_enum('view_3d.my_operator', 'method', 'Operate')		#  Here the operator menu is displayed
	
	# 'view_3d.my_operator' is the bl_idname of the operator called
	#  No box draw on GUI  only the Menu name  = Operate and list used is called = method
	
	
		col.separator()
		col.label('just a Label:')
		col.prop(scene, "MyBoolProperty", text = "the bool prop label")
		col.separator()        
		col.label('float Vector Properties:') 
		subtype ='XYZ'
		col.prop(scene, 'FloatVector' +subtype  )
		col.separator()        
		col.label('float Vector Color')
		subtype ='COLOR'
		col.prop(scene, 'FloatVector' +subtype )
	
	
	
	
	
##############
	
	
	
class myOperator(bpy.types.Operator):				#   When an option in the operator menu is clicked, this is called
	
#	Operator
	
	bl_idname = 'view_3d.my_operator'
	bl_label = 'Operator'
	
#	Define possible operations
	
	method = EnumProperty(items=(
		('1 inclass', 'One op', 'The first item 111'),
		('2 inclass', 'Two op', 'The second item 222'),
		('3 inclass', 'Three op', 'The third item 333'),
		('3 inclass', 'Fourth op', 'The Fourth item 444')))
	
	
	def execute(self, context):
		global last_method							#  Make global so we can later draw it in the panel
	
		last_method = self.properties.method		#  Store the choosen operation
	
	
		print ('in myoperator   Selection =',last_method)
	
		return {'FINISHED'}
	
	
	
	
	#######################  Menu addition #####################
	
class INFO_MT_mesh_trianglegen1_add(bpy.types.Menu):
	
	# Define the "Pipe Joints" menu
	
	bl_idname = "INFO_MT_mesh_trianglegen1_add"
	bl_label = "Triangles"
	
	def draw(self, context):
		layout = self.layout
		layout.operator_context = 'INVOKE_REGION_WIN'
	
		layout.operator("mesh.primitive_4545TrianRect_add",
			text="4545TriBH")
	
	
######################################################
	
	
import space_info
	
menu_func = (lambda self,
	context: self.layout.menu("INFO_MT_mesh_trianglegen1_add"))
	
	
# Register the operators/menus
	
	# First define the different  functions
	
	
	
	
def register():
	
	
	bpy.types.register(myOperator)
	bpy.types.register(myPanel)
	
	
# Then defined the Menu add function
	
	bpy.types.register(INFO_MT_mesh_trianglegen1_add)
	
	space_info.INFO_MT_mesh_add.append(menu_func)
	
	
	
	
def unregister():
	
	# Unregister the operators/menus.
	
	
	bpy.types.unregister(myOperator)
	bpy.types.unregister(myPanel)
	
	
	bpy.types.unregister(INFO_MT_mesh_trianglegen1_add)
	space_info.INFO_MT_mesh_add.remove(menu_func)
	
	
	
	
#####################################################################
	
	
	
if __name__ == "__main__":
	
#	register()					#  Call the first function
	pass
	
	
	
	
	
	
	
	
	
	
	
	
	
	
"""
	
	
	
	
#####################################################################
	
	
	
	
"""




tested in 626 so should work in later version i hope

Hope it helps happy 2.5

as rickyblender said just add properties.
http://www.blender.org/documentation/250PythonDoc/bpy.props.html
the best way would be to define them in a subclass of bpy.types

for example, if you want to extend you material settings with a color picker, you’d write something like


bpy.types.Material.FloatVectorProperty(attr="myColorValue", min=0, max=1, default=0, name="myColor", description="my cool color value i can use for anything i like", subtype="COLOR")

you can then access this property e.g. in your material panel UI class via:


layout.prop(context.material, "myColorValue")

and it will show a color picker in your UI panel

one thing not certain how to grab

is how do you get back the RGB values from the color picker

is it only single value or triple float?

and then pass it back let say to a mat color ?

thanks

the FloatVectorProperty just creates an array. so you can access all values as you would access a value in a normal array. in my example the red value would be accessed with myColorVaule[0] and so on. but as the diffuse color of a material is a property of the same type, you could just write:


material.diffuse_color = material.myColorValue

and read the link to the documentation i posted. the “size” parameter listed there lets you add more dimensions to your vector prop. thats imo very handy

@Rickyblender
Yes, something like your script is helping really (thanks from me too)
Peter

i won’t upate till this weekend

so is this working fine in latest built ?

Thanks