Processing Events In a 2.5 Property Panel?

Hi All,

I have taken Ricky’s panel demo code and modified it into a first draft for the BlendText conversion.
The modification I made was for the draw routine to draw controls in the properties panel of the active object
instead of in the tools panel as Ricky had.
BlendText is going to extend an existing object (typically an empty), not generate one.

Paste this code in to a text window and run it with ALT-P.
Then select the object properties TAB and
the BlendText panel will appear when you move your mouse into the properties area.

Here is the code:


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

    
###############
    
bpy.types.Scene.BoolProperty(  attr = 'MyBoolProperty', 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 = '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 = "BlendText"                    #  Called this
    #bl_space_type = "VIEW_3D"                    #  in 3D view
    #bl_region_type = "TOOL_PROPS"                #  in Operator's panel in tool shelf
    
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"               #  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('Font Metrics:')
        col.prop(scene, "MyBoolProperty", text = "Generate Font CAPs")
        col.separator()        
        col.label('Effector Scale Influence:') 
        subtype ='XYZ'
        col.prop(scene, 'FloatVector' +subtype  )
        col.separator()        
        col.label('Font Material:')
        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'}

So now I have some controls in a panel under the object context.
But the only control that generates an event seems to be the menu,
because it is initiated as an operator.

Q: How can I get events like the check box click or number change to appear in my code for processing?

Q: What kind of callbacks or setups need to be done so I can capture these events for processing?

use a if statement to check the value of the checkbox in execute portion of the class
true or false then execute what you need!

you shoudl remove what’s not needed in script liike buttons ect…

i can see the new panel in object propertie panel with new name

note: you can remove my name there it’s only a general script example free to use!

happy 2.5

The execute currently in the class is only for the operator. If I click the checkbox, an event never shows up in that intercept.

Can you post code that shows me how to print something when the checkbox changes or a value in one of the numbers change?

i tried the script you uploaded and cannot see any checkbox ?

not certain why it’s not working

did you remove this checkbox button ?

i have to go back to the first script i uploaded to do some test!

salutations

here is the ckeck box button
look on the console for print the buttons state


import mathutils
from math import *
from bpy.props import *
import bpy
 
###############
 
bpy.types.Scene.BoolProperty(  attr = 'MyCkeckbox1', 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 = '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 = "BlendText"                    #  Called this
    #bl_space_type = "VIEW_3D"                    #  in 3D view
    #bl_region_type = "TOOL_PROPS"                #  in Operator's panel in tool shelf
 
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"               #  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('Font Metrics:')
        col.prop(scene, "MyCkeckbox1", text = "Generate Font CAPs")
        col.separator()        
        col.label('Effector Scale Influence:') 
        subtype ='XYZ'
        col.prop(scene, 'FloatVector' +subtype  )
        col.separator()        
        col.label('Font Material:')
        subtype ='COLOR'
        col.prop(scene, 'FloatVector' +subtype )
 
        print (' Check Button =',scene.MyCkeckbox1)
 
 
##############
 
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'}
 
 
 

but always depends what you want to do and how !

happy 2.5

i have only one problem with this panel class

look on the console and it looks like it is looping 6 to 10 times
before stopping

that’s a problem

if anybody knows how to stop it from looping please let us know !

salutations

The code you have posted is not really that different. It also does not show how to process the event when a checkbox is activated. All you did was put a print in the draw routine. I need a click routine that only fires when a user clicks on a checkbox or changes a numeric value.

This is very common is every language I have used. Even 2.49 had callbacks for controls. 2.5 does not?

Event processing is my main concern, hence the title of the this thread.

I feel like we are treading on grounds that developers may not have completed yet…?

sorry i don’t think there are any events in 2.5!

it just loop in the class panel and then you can check out if one vars has been click
or if you use operator class then you can check there and do something in that class

but as i said you can add a if statement to check if there is a change in the checkbox value!

happy 2.5

Did anybody find a proper solution for this? Calling the print statement from draw looks like a clumsy way to do it…