0

我正在用 python 为 3DS Max 2018 编写 UI,但我无法让任何文本输入正常工作,尽管到目前为止我尝试过的所有其他方法都可以正常工作。由于某种原因,它似乎没有读取击键。它们是由 Max 注册的,它会执行适当的操作,例如当我按下“m”而不是输入“m”时启动材质编辑器。我尝试打印出按键,但它看起来像是控制、alt 和 shift 工作。

我什至尝试运行 Max 附带的示例脚本并得到相同的错误,所以我意识到这可能是某种错误,但是我不相信 Autodesk 现在修复它,所以我正在寻找解决方法......

这是一个测试示例:

from PySide2 import QtWidgets, QtCore, QtGui
import MaxPlus
import os

class SampleUI(QtWidgets.QDialog):
    def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
        super(SampleUI, self).__init__(parent)
        self.initUI()

    def initUI(self):
        self.testBtn = QtWidgets.QPushButton("Test")
        mainLayout = QtWidgets.QHBoxLayout()
        testBox = QtWidgets.QLineEdit("Test!")
        mainLayout.addWidget(testBox)
        self.setLayout(mainLayout)

if __name__ == "__main__":
    try:
        ui.close()
    except:
        pass

    ui = SampleUI()
    ui.show()
4

2 回答 2

0

叹息终于找到了:https ://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__developer_troubleshooting_3ds_max_python_a_html

“为了捕获 Qt 窗口的键盘输入,您必须在 UI 控件获得焦点时调用以下命令来禁用 3ds Max 键盘加速器:”

供参考的命令是:MaxPlus.CUI.DisableAccelerators()

当你的脚本失去焦点时不要忘记撤消它:MaxPlus.CUI.EnableAccelerators()

于 2017-10-14T04:34:46.127 回答
0

这是我在 Autodesks 论坛页面上找到的一个简单的 ui:

http://help.autodesk.com/view/3DSMAX/2018/ENU/?guid=__developer_what_s_new_in_3ds_max_python_api_what_s_new_in_the_3ds_max_2018_p_html

最大文档中存在很多歧义,一直如此,但希望它有所帮助。我在另一个脚本中对此进行了一些编辑,在其中我将 self 添加到控件中,以便能够访问控件并在不同的功能中设置连接,并且效果很好。

虽然这很无聊,但我仍然觉得 python 实现既笨重又麻烦。我仍然更喜欢使用 Maya Python,它一直很可靠,但我现在必须使用 MaxPlus。

from PySide2 import QtWidgets, QtCore, QtGui
import MaxPlus
import os

class SuperDuperText(QtWidgets.QLineEdit):
    def focusInEvent(self, event):
        MaxPlus.CUI.DisableAccelerators()

    def focusOutEvent(self, event):
        MaxPlus.CUI.EnableAccelerators()


class SuperDuperUI(QtWidgets.QDialog):

 def __init__(self, parent=MaxPlus.GetQMaxMainWindow()):
     super(SuperDuperUI, self).__init__(parent)
     self.setWindowTitle("Sample UI")
     self.initUI()


 def initUI(self):
     mainLayout = QtWidgets.QVBoxLayout()

     maxScriptsDir = MaxPlus.PathManager.GetScriptsDir()
     testLabel = QtWidgets.QLabel("Your scripts dir is: " + maxScriptsDir)
     mainLayout.addWidget(testLabel)

     testBtn = QtWidgets.QPushButton("This does nothing.")
     mainLayout.addWidget(testBtn)

     testEdit = SuperDuperText()
     testEdit.setPlaceholderText("You can type in here if you like...")
     mainLayout.addWidget(testEdit)

     self.setLayout(mainLayout)


if __name__ == "__main__":

 try:
    ui.close()
 except:
    pass

 ui = SuperDuperUI()
 ui.show()
于 2017-11-06T18:17:21.113 回答