【发布时间】:2013-10-30 21:09:11
【问题描述】:
如何在搅拌机中创建一个对话框(退出/确定/取消等三个选项)并处理通过 python 或 C 输入的文本。我找不到任何好的教程。有什么帮助....?
【问题讨论】:
标签: blender blender-2.61 blender-2.50 blender-2.49 blender-2.67
如何在搅拌机中创建一个对话框(退出/确定/取消等三个选项)并处理通过 python 或 C 输入的文本。我找不到任何好的教程。有什么帮助....?
【问题讨论】:
标签: blender blender-2.61 blender-2.50 blender-2.49 blender-2.67
一种快速而肮脏的方法是使用 zenity 命令(应该默认包含在任何 python 发行版中)。试试这个简短的示例脚本,它适用于我在 Ubuntu 14.04 上的 Blender 2.69。
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)
查看 zenity --help 以获得更复杂的对话框
【讨论】:
blender 不提供对话框之类的功能。
在外部模块上回答This previous question 可能会有所帮助。
【讨论】:
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")
但这仅用于创建对话窗口。在此之后必须在此代码中插入按钮。如果有人知道这一点,请尝试发布答案。同时我也在努力解决这个问题。
【讨论】:
bpy.types.Operator是一个执行动作的类,也就是说当你说删除这个对象时,操作员执行删除对象的任务。 bpy.types.Panel 是窗口或属性窗口的侧窗格中的可折叠部分。虽然 DialogOperator 显示类似窗口的对话框,但它是一种更改操作员使用的值的方法,ok 按钮会自动添加,离开对话框会取消它,这些对话框通常通过按 F6 显示或显示在底部工具面板。
def draw(self, context): 完成的。按钮通常通过添加运算符row.operator("render.render") 来显示在面板中,但不确定它是否会在运算符对话框中起作用。