I would like to show a widget to the user when a "hotkey" is pressed. I have done some tests and found three ways to do this.
* Using the Hotkey editor, add a hotkey for a custom runtime command.
* Install an eventfilter to the main maya window and intercept a specific keypress.
* Add a QAction (with a "key shortcut") to the maya main window.
Feels like the the first approach is more flexible for the user as they can choose how to call the script with the hotkey editor. And the other two feels a bit "invasive".
To run this I create a hotkey for a custom script and add a runtime command.
Below you will find a snippet of a stripped version of the script.
from PySide2 import QtGui
from PySide2 import QtCore
from PySide2 import QtWidgets
from shiboken2 import wrapInstance
from maya import OpenMayaUI as omui
def __init__(self, parent=None):
vbox = QtWidgets.QVBoxLayout(self)
self.line_edit = QtWidgets.QLineEdit()
btn = QtWidgets.QPushButton('Button')
mainWin = wrapInstance(long(omui.MQtUtil.mainWindow()), QtWidgets.QWidget)
widget = CustomWidget(mainWin)
The reason for using a global variable for the widget is that I would like to keep whatever state the user has set in the widget(in this simple example only the text in the line edit)
I would like to get some feedback on this subject, are there some best practices that I am missing, other ways to do this. Any constructive feedback is much appreciated!