User Input using MaxPlus/PySide/QtGui?

Anyone used the keyboard to input Text or Anything into a MaxPlus/PySide/QtGui??

Whenever I try to type with the keyboard, the input simply goes into 3DS Max instead of the input field of the QtGui.

Any Suggestions??

Here is an example using a quick edit of the Autodesk sample:



from PySide import QtGui
import MaxPlus


class _GCProtector(object):
    widgets = []


def make_cylinder():
    obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Cylinder)
    obj.ParameterBlock.Radius.Value = 10.0
    obj.ParameterBlock.Height.Value = 30.0
    node = MaxPlus.Factory.CreateNode(obj)
    time = MaxPlus.Core.GetCurrentTime()
    MaxPlus.ViewportManager.RedrawViews(time)

    return


app = QtGui.QApplication.instance()
if not app:
    app = QtGui.QApplication([])




def main():
    MaxPlus.FileManager.Reset(True)
    w = QtGui.QWidget()
    w.resize(250, 100)
    w.setWindowTitle('Window')
    _GCProtector.widgets.append(w)

    w.show()

    main_layout = QtGui.QVBoxLayout()
    label = QtGui.QLineEdit()
    main_layout.addWidget(label)

    cylinder_btn = QtGui.QPushButton("Cylinder")
    main_layout.addWidget(cylinder_btn)
    w.setLayout(main_layout)

    cylinder_btn.clicked.connect(make_cylinder)

    hwnd = w.winId()
    import ctypes
    ctypes.pythonapi.PyCObject_AsVoidPtr.restype = ctypes.c_void_p
    ctypes.pythonapi.PyCObject_AsVoidPtr.argtypes = [ctypes.py_object]
    int_hwnd = ctypes.pythonapi.PyCObject_AsVoidPtr(hwnd)
    MaxPlus.Win32_Set3dsMaxAsParentWindow(int_hwnd)

if __name__ == '__main__':
    main()


Thanks

Check this: YCDIVFX_MaxPlus/packages/maxhelpers/MaxPlusConsole.py at master · ycdivfx/YCDIVFX_MaxPlus · GitHub

You need to install an app filter to handle the focus event so you can toggle accelerators.

A more in-depth explanation at Chris blog: http://area.autodesk.com/blogs/chris/pyqt-ui-in-3ds-max-2014-extension

Thanks for the info, didn’t know.

Is this the only way, or could there be another way that just hasn’t been tried yet?

EDIT: Also, does anyone know how Max usually sets up its window system? Could we access that somehow and register our python window there?

EDIT2: There is another way around this, with its own limitations and wont work for everything, that can be used right out of the box.
Just overwrite the class and implement the mousePressEvent function.

It works for QLineEdit, but not for QLineDateTimeEdit.


class QLineEditMax(PySide.QtGui.QLineEdit):
    def __init__(self):
        super(QLineEditMax, self).__init__()

    def mousePressEvent(self, event):
            MaxPlus.CUI_DisableAccelerators()

I was also looking for a way to INCLUDE the children rects in the ‘mousePressEvent’ of the entire window if possible, so one doesn’t even have to overwrite the class, just do this for the main window/widget