Post #780: ![](https://blenderartists.org/user_avatar/blenderartists.org/frankieh/48/670768

📋 Metadata

  • Author: roaoao
  • Date: 2017-08-08 13:50:45
  • Type: answer
  • Quality Score: 9/10
  • Reply to: post_00778

🏷️ Tags

v1-14-0 popup-dialog python-scripting intermediate solved

  • Popup Dialog Editor
  • Python Scripting
  • Custom Operators
  • Command Tab

💬 Content

FrankieH:

I want to have a popup dialogue with a custom string in it. The string then feeds into a python script snippet and does something.

I’ll add some tool for this in PME 1.14.0.
In the current version the easiest way is to register a new operator with custom string property:

Save this file as pie_menu_editor/scripts/input_box.py file:

import bpy


class PME_OT_my_input_box(bpy.types.Operator):
    bl_idname = "pme.my_input_box"
    bl_label = "Input Box"
    bl_options = {'INTERNAL'}
    bl_property = "value"
    on_execute = None
    prev_value = ""

    value = bpy.props.StringProperty()

    def draw(self, context):
        self.layout.prop(self, "value", "")

    def execute(self, context):
        if PME_OT_my_input_box.on_execute:
            PME_OT_my_input_box.on_execute(self.value)
        PME_OT_my_input_box.prev_value = self.value
        return {'FINISHED'}

    def invoke(self, context, modal):
        return context.window_manager.invoke_props_dialog(self)


def input_box(func):
    if not hasattr(bpy.types, "PME_OT_my_input_box"):
        bpy.utils.register_class(PME_OT_my_input_box)

    PME_OT_my_input_box.on_execute = func
    bpy.ops.pme.my_input_box(
        'INVOKE_DEFAULT', value=PME_OT_my_input_box.prev_value)


def my_function(value):
    print(value)

And use it in Command tab:

from .scripts.input_box import input_box, my_function; input_box(my_function)

You can edit my_function ‘s code or replace it with some other function.


🔗 View on Blender Artists