67 import maya.OpenMaya
as OpenMaya
68 import maya.OpenMayaMPx
as OpenMayaMPx
69 import maya.OpenMayaUI
as OpenMayaUI
71 kPluginCmdName =
"spMathTableControl"
74 kNopLongFlag =
"-noOperation"
76 kMultLongFlag =
"-multiplyVals"
78 kAddLongFlag =
"-addVals"
80 kRedrawFlagLong =
"-redraw"
84 kNop =
lambda x,y:
"cell(%d,%d)" % (x,y)
85 kMult =
lambda x,y: str(x*y)
86 kAdd =
lambda x,y: str(x+y)
90 class MathTableControlCmd(OpenMayaMPx.MPxControlCommand):
92 OpenMayaMPx.MPxControlCommand.__init__(self)
95 def makeControl(self):
96 control = MathTableControl(self)
97 control.setOperation(kNop)
98 control.setNumberOfRows(5)
99 control.setNumberOfColumns(3)
100 return OpenMayaMPx.asMPxPtr(control)
103 def doEditFlags(self):
104 theParser = self._parser()
105 theControl = kPythonPtrTable.get(OpenMayaMPx.asHashable(self._control()),
None)
107 if theParser.isFlagSet(kNopFlag):
108 theControl.setOperation(kNop)
109 elif theParser.isFlagSet(kMultFlag):
110 theControl.setOperation(kMult)
111 elif theParser.isFlagSet(kAddFlag):
112 theControl.setOperation(kAdd)
113 elif theParser.isFlagSet(kRedrawFlag):
114 theControl.redrawCells()
115 theControl.redrawLabels()
117 OpenMayaMPx.MPxControlCommand.doEditFlags(self)
120 def doQueryFlags(self):
121 return OpenMayaMPx.MPxControlCommand.doQueryFlags(self)
124 def appendSyntax(self):
125 theSyntax = self._syntax()
126 theSyntax.addFlag(kNopFlag, kNopLongFlag)
127 theSyntax.addFlag(kMultFlag, kMultLongFlag)
128 theSyntax.addFlag(kAddFlag, kAddLongFlag)
129 theSyntax.addFlag(kRedrawFlag, kRedrawFlagLong)
132 class MathTableControl(OpenMayaMPx.MPxUITableControl):
133 def __init__(self, command):
134 OpenMayaMPx.MPxUITableControl.__init__(self, command)
135 self.__myOperation =
None
136 kPythonPtrTable[OpenMayaMPx.asHashable(self)] = self
140 del kPythonPtrTable[OpenMayaMPx.asHashable(self)]
143 def cellString(self, row, column, isValidCell):
145 if callable(self.__myOperation):
146 result = self.__myOperation(row, column)
147 OpenMaya.MScriptUtil.setBool(isValidCell, bool(result))
151 def labelString(self, labelType, index):
153 if labelType == OpenMayaMPx.MPxUITableControl.kRowLabel:
154 value =
"[Row %d]" % index
155 elif labelType == OpenMayaMPx.MPxUITableControl.kColumnLabel:
156 value =
"[Col %d]" % index
160 def setOperation(self, op):
161 self.__myOperation = op
169 return OpenMayaMPx.asMPxPtr(MathTableControlCmd())
172 def initializePlugin(mobject):
173 mplugin = OpenMayaMPx.MFnPlugin(mobject,
"Autodesk",
"1.0",
"Any")
175 mplugin.registerControlCommand(kPluginCmdName, cmdCreator)
177 sys.stderr.write(
"Failed to register command: %s\n" % kPluginCmdName)
181 def uninitializePlugin(mobject):
182 mplugin = OpenMayaMPx.MFnPlugin(mobject)
184 mplugin.deregisterControlCommand(kPluginCmdName)
186 sys.stderr.write(
"Failed to unregister command: %s\n" % kPluginCmdName)