3D tool add-on window locks/freezes when importing an image with Python

Code:

    import bpy
from bpy.props import *

class primitive_object_add(bpy.types.Operator):
'''Add a minecraft item'''
bl_idname = "mesh.primitive_object_add"
bl_label = "Add a Minecraft item"
bl_options = {'REGISTER', 'UNDO'}
img_str = StringProperty(name="Path:", default="", subtype='FILE_PATH')
opt = IntProperty(name="Option 2:")

def execute(self, context):
if self.img_str != "":
path = r"" + bpy.path.abspath(self.img_str)
image = bpy.data.images.load(path)
return {'FINISHED'}

def menu_func(self, context):
self.layout.operator("mesh.primitive_object_add", text="Object", icon='OBJECT_DATA')
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_mesh_add.append(menu_func)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_mesh_add.remove(menu_func)
if __name__ == "__main__":
register()


So if running this code, following happens:

You get up the menu and everything just fine

Then clicking the file browser icon, which will bring up the file browser, so far everything is working.

However, now when selecting an image and pressing accept, will load the image into blender properly, but it locks/freezes the toolbar, so now I cannot change Option 2 if I would like to.

I've spent pretty much the entire day yesterday trying to fix this, but without any luck. I discovered that for some reason if you where to press "Object" in the add menu 2 times and then using the file browser to load in an image it works, and it will work until you close and open blender again.

Does anyone have any idea on why this might be happening, and a way to fix it or go around the problem?

• see this alternative blender.stackexchange.com/a/17829/5113 – Chebhou May 26 '15 at 16:09
• @Chebhou The problem using 'bpy.ops.image.open("INVOKE_DEFAULT")' is that for the add-on I'm working on I need a reference to the image, and the action needs to happen when pressing a button, and if I'm not mistaken it's not possible to add buttons in the current panel I'm using. – Nils Söderman May 26 '15 at 16:37
• you can add buttons, and if you need a ref to the image store a list of the images before calling the Op then compare it with the new list the new entry is yours – Chebhou May 26 '15 at 16:39
• @Chebho Sounds like that could work, however with my limited knowledge of Python I have no idea on how I would do this. Any chance you could help me out? (It would of course be paid). If you're interested, hit me up at contact@rymdnisse.net – Nils Söderman May 26 '15 at 17:48
• there's a problem that the image is not pushed into the bpy.data until the operator is finished which make it impossible to find a reference for so you may have to create a panel for your addon to avoid all this hustle if you can add more details I may be able to help – Chebhou May 27 '15 at 2:36