【问题标题】:Create Dialog Box in Blender using C or Python使用 C 或 Python 在 Blender 中创建对话框
【发布时间】:2013-10-30 21:09:11
【问题描述】:

如何在搅拌机中创建一个对话框(退出/确定/取消等三个选项)并处理通过 python 或 C 输入的文本。我找不到任何好的教程。有什么帮助....?

【问题讨论】:

    标签: blender blender-2.61 blender-2.50 blender-2.49 blender-2.67


    【解决方案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 以获得更复杂的对话框

    【讨论】:

      【解决方案2】:

      blender 不提供对话框之类的功能。

      在外部模块上回答This previous question 可能会有所帮助。

      【讨论】:

      • class DialogOperator(bpy.types.Operator): bl_idname = "object.dialog_operator" bl_label = "在你退出之前保存!" def execute(self, context): message = "你还没有保存" 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")
      • 这是我为该对话框窗口生成的代码,但现在我正在尝试在其中插入 yes no cancel 选项.. 到目前为止我还没有找到任何有用的答案.. .如果可能的话,告诉如何在上面的代码中插入按钮......谢谢
      【解决方案3】:
      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")
      

      但这仅用于创建对话窗口。在此之后必须在此代码中插入按钮。如果有人知道这一点,请尝试发布答案。同时我也在努力解决这个问题。

      【讨论】:

      • 在blender中bpy.types.Operator是一个执行动作的类,也就是说当你说删除这个对象时,操作员执行删除对象的任务。 bpy.types.Panel 是窗口或属性窗口的侧窗格中的可折叠部分。虽然 DialogOperator 显示类似窗口的对话框,但它是一种更改操作员使用的值的方法,ok 按钮会自动添加,离开对话框会取消它,这些对话框通常通过按 F6 显示或显示在底部工具面板。
      • 在 bl_label 下添加的类属性将在对话框中进行调整并返回给操作员使用。自定义绘图是通过 DialogOperator 类中的def draw(self, context): 完成的。按钮通常通过添加运算符row.operator("render.render") 来显示在面板中,但不确定它是否会在运算符对话框中起作用。
      • 非常感谢....def draw(self, context): row.operator("render.render") 我试过了...这行不通你...
      猜你喜欢
      • 2014-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多