user2797984
user2797984

Reputation:

Create Dialog Box in Blender using C or Python

How to make a dialog box (three options like quit/OK/Cancel) in blender and processing the text entered through python or in C. I'm unable to find any good tutorial on this. Any help....?

Upvotes: 0

Views: 3073

Answers (3)

user2797984
user2797984

Reputation:

class DialogOperator(bpy.types.Operator)
    bl_idname = "object.dialog_operator"
    bl_label = "Save Before You QUIT!"

    def execute(self, context):
        message = " You didn't saved yet "
        self.report({'INFO'}, message)
        print(message)
        return {'FINISHED'}
    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self)

class DialogPanel(bpy.types.Panel)
    bl_label = "Dialog"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"

    def draw(self, context):
        self.layout.operator("object.dialog_operator")

But this is only for creating a dialog window. after this have to insert buttons in this code.If anyone known this try to post the answer. At the same time I'm also trying to sort out this.

Upvotes: 0

Mario Rossi
Mario Rossi

Reputation: 71

A quick and dirty way is to use zenity command (should be included by default in any python distribution). Try this short example script, it works in my Blender 2.69 on Ubuntu 14.04.

import bpy # bpy or bge does not matter 
import subprocess as SP
# call an OS subprocess $ zenity --entry --text "some text"
# (this will ask OS to open a window with the dialog)
res=SP.Popen(['zenity','--entry','--text',
'please write some text'], stdout=SP.PIPE)
# get the user input string back
usertext=str(res.communicate()[0][:-1])
# adjust user input string 
text=usertext[2:-1]
print("I got this text from the user: %s"%text)

See the zenity --help for more complex dialogs

Upvotes: 1

sambler
sambler

Reputation: 7079

blender doesn't offer things like dialogs.

Answers to This previous question on external modules may be helpful.

Upvotes: 0

Related Questions