Hi everyone, I created a tool using Qt Designer, where it has 3 QLineEdits
that is catered for translateX, translateY and translateZ.
For each QLineEdit, I have created a context menu that allows me to set a
keyframe for one of the above attribute depending on User's choice.
So instead of writing 3 separate functions that catered to each attribute,
I thought of 'recycling' them by using 1 method, but I am having issues
with it as I am not very sure if it will be possible since I am using a
single QAction.
class MyTool(QtGui.QWidget):
def __init__(self, parent=None):
super(MyTool, self).__init__(parent = parent)
# Read off from convert uic file.
self.ui = Ui_MyWidget()
self.ui.setupUi(self)
# translateX
self.ui.xLineEdit.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.ui.xLineEdit.customContextMenuRequested.connect(self.custom_menu)
# translateY
self.ui.yLineEdit.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.ui.yLineEdit.customContextMenuRequested.connect(self.custom_menu)
# translateZ
self.ui.zLineEdit.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.ui.zLineEdit.customContextMenuRequested.connect(self.custom_menu)
self.popMenu = QtGui.QMenu(self)
set_key_action = QtGui.QAction("Set Key at Current Frame", self)
# I am having issues here..
set_key_action.triggered.connect(self.set_key)
self.popMenu.addAction(set_key_action)
...
...
def set_key(self, attr):
# assuming I am trying to effect this locator1 that already exists
in the scene
current_item = "|locator1"
cmds.setKeyframe("{0}.{1}".format(current_item, attr))
def custom_menu(self, point):
self.popMenu.exec_(QtGui.QCursor.pos())
I thought of using `functools` so that my code will be something like :
class MyTool(QtGui.QWidget(:
def __init__(self, parent=None):
...
...
functools.partial(self.set_key, "tx")
def set_key(self, attr):
if attr == "tx":
# setkeyframe to translateX
elif attr == "ty":
# setkeyframe to translateY
Again, because it is only a single QAction and hence I was stumped... Or
will it be better for me to stick in using 3 separate functions instead?
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/a3c45192-ec1e-4a85-87de-63ac2de131a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.