Weird Context Sensitive Bug

I am encountering a weird context sensitive bug. The same code that works fine when run elsewhere gives an error when run by the redraw command “draw” for the panel I’ve created.

I’ve isolated the bug into a much shorter “demonstration” script to showcase the problem:


import bpy

#The script sets the test vert to the position specified.
#(not very usefull just demonstrates the bug
#Only meant to work in object mode 
#with a mesh containting at least one vert.

print('===== Script Begin =====')

bpy.context.object['testProp'] = 4.0

def setVert(position,vert):
    vert.co[0] = position[0]
    vert.co[1] = position[1]
    vert.co[2] = position[2]

class ToolsPanel(bpy.types.Panel):
    bl_label = "Test Panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"

    def draw(self,context):
        #This works:
        self.layout.prop(context.object,'["testProp"]',text='')
        self.layout.operator('test.test',text='setVert')
        
        #This doesn't work: 
#        bpy.ops.test.test() # <---- Bug

        #This doesn't work either:
#        testPosition = [bpy.context.object['testProp'],2,0]
#        testVert = bpy.context.object.data.vertices[0] #this is just for the test.
#        setVert(testPosition , testVert)

class MESH_test(bpy.types.Operator):
    bl_idname = "test.test"
    bl_label = ""
    
    def execute(self, context):
        print(bpy.context.object.mode)
        testPosition = [bpy.context.object['testProp'],2,0]
        testVert = bpy.context.object.data.vertices[0] #this is just for the test.
        setVert(testPosition , testVert)
        return{'FINISHED'}

bpy.utils.register_class(ToolsPanel)
bpy.utils.register_class(MESH_test)

#...but this works:
testPosition = [bpy.context.object['testProp'],2,0]
testVert = bpy.context.object.data.vertices[0] #this is just for the test.
setVert(testPosition , testVert)

I suspect that the reason is that meshes cannot be edited when the interface redraws, but must be called my an event or something like that. I really don’t know.

What I would like is for the mesh to continuously update without having to use an update button.

Anyone know what the problem is?

(Blender 2.58, Windows 64 bit)