Blender でダイアログ ボックス (quit/OK/Cancel などの 3 つのオプション) を作成し、python または C で入力されたテキストを処理する方法。これに関する適切なチュートリアルが見つかりません。助けて……?
2443 次
3 に答える
1
手っ取り早い方法は、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 を参照してください。
于 2015-03-25T09:30:00.327 に答える
0
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")
ただし、これはダイアログ ウィンドウを作成するためだけのものです。この後、このコードにボタンを挿入する必要があります。誰かがこれを知っている場合は、回答を投稿してみてください。同時に、これを整理しようとしています。
于 2013-10-25T05:04:43.453 に答える