I just can't figure out how to create a custom popup which can receive data etc. What I want to do is let the user select one of the currently selected UV-layers and just hand that back to me. So I created a class like this:
class UVLayerPrompt(Operator):
"""
Prompts the user for the uv-layer he wishes to select for each object
"""
bl_idname = "mhmu.uvprompt"
bl_label = "Choose the uv-layer"
uv_layerPos = 0
def execute(self, context):
print('HI')
def invoke(self, context, event):
self.layout.template_list("UI_UL_list", #is this correct? I guess not...
list_id="UVLayer_LIST", # I guess yes
dataptr=context.object.data, # my guess: yes
propname="uv_textures", # yes?
active_dataptr=context.scene, # I could use some other location, okay
active_propname="uv_layerPos") # I have to assign a IntegerProperty to this, right?
return {'RUNNING_MODAL'}
after I registered my class etc.
when I call
window_manager.invoke_popup(UVLayerPrompt)
then it says:TypeError: WindowManager.invoke_popup(): error with argument 1, "operator" - >Function.operator expected a Operator type, not OrderedMeta
I realized that this is not correct. Still I don't know how to react with the context (how do I popup a new instance? with python code ofc?, how do I read the chosen value from that?)
EDIT: I will try to clarify my question: I have an export script that may export several objects. For each of these objects I want to ask the user in a responsive way which uv-texture he wants to be exported. Only one layer per object should be possible and of course I have to call the popup within my script (NOT by the user) and after it run I have to know the result of it.
How far have I gotten with this by now? Using the answer below me I realized that I should use a script that is 'INTERNAL'. Secondly I think I now finally understand how Operators are supposed to work.
I figured out how to do it: if you want to call a script from inside a script you have to call bpy.ops.operator.name('INVOKE_DEFAULT')