def camMenu(self):
allCams = cmds.ls(type='camera', visible = 1)
camLs = cmds.listRelatives(allCams, p=1)
menu = QMenu("menu", self.camSelBtn)
for n in camLs:
menu.addAction(QAction(n, menu))
self.camSelBtn.setMenu(menu)
def createConnections(self):
self.connect(self.setCameraBtn, SIGNAL('clicked()'), self.setCamera)
def setCamera(self):
for sel in self.camMenu.menu():
self.currentCamTxt.setText()
def camMenu(self):
allCams = cmds.ls(type='camera', visible = 1)
camLs = cmds.listRelatives(allCams, p=1)
menu = QMenu("menu", self.camSelBtn)
for n in
camLs:
menu.addAction(n)
self.camSelBtn.setMenu(menu)
menu.triggered.connect(self._camSelected)
def _camSelected(self, action):
self.currentCamTxt.setText(action.text())
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2c9cdcc9-9263-4b8b-a7ce-47fbe9004cff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9b8acefa-41f6-4895-bb37-1b3ad8a39dae%40googlegroups.com.
You have complete freedom to clear the menu or add more items at any time, but there is no live binding between the number of cameras in the scene and the menu. You would need to update the menu instance based on some action or trigger
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/19726fe9-72a5-4c05-81ed-33713f5cd5e2%40googlegroups.com.
You have a couple ways to go about it. Either your camMenu function gets called whenever you need to trigger an update, and it will replace the button menu with a new one. Or it can edit the same menu over and over. Or, you can create the menu once and connect it's aboutToShow signal to a function that will update it.
I actually would prefer the last one. You can just clear and repopulate the menu each time they click it, which means that you don't need to keep the menu updated at any other time.
Hi Justin, thank you for the reply.
Based on what you have mentioned, can I actually placed the updating within the camMenu function? Or should I re-define it as another function?
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9a5730d9-e73c-4fd3-85b8-21282c2f6536%40googlegroups.com.
self.connect(self.setCameraBtn, SIGNAL("pressed()"), self.camMenu)
You have a couple ways to go about it. Either your camMenu function gets called whenever you need to trigger an update, and it will replace the button menu with a new one. Or it can edit the same menu over and over. Or, you can create the menu once and connect it's aboutToShow signal to a function that will update it.
I actually would prefer the last one. You can just clear and repopulate the menu each time they click it, which means that you don't need to keep the menu updated at any other time.
On 3/10/2014 4:21 PM, "likage" <dissid...@gmail.com> wrote:
Hi Justin, thank you for the reply.--
Based on what you have mentioned, can I actually placed the updating within the camMenu function? Or should I re-define it as another function?
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 python_inside_maya+unsub...@googlegroups.com.
...
menu = QtGui.QMenu(self)
self.setMenu(menu)
menu.aboutToShow.connect(self._updateMenu)
def _updateMenu(self):
menu = self.menu()
menu.clear()
allCams = cmds.ls(type='camera', visible=True)
if not allCams:
return
camLs = cmds.listRelatives(allCams, p=True)
for item in camLs:
menu.addAction(item)
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/18628e12-5447-49a3-80ae-8fcf9383d730%40googlegroups.com.
camLs = []
class orientCameraUI(QDialog):
def __init__(self, parent=None):
super(orientCameraUI, self).__init__(parent)
self.setMinimumWidth(300)
self.setMaximumHeight(80)
self.initUI()
self.camMenu()
self.createConnections()
def initUI(self):
...
def createConnections(self):
self.connect(self.setCameraBtn, SIGNAL('aboutToShow()'), self._updateMenu)
def camMenu(self):
allCams = [c for c in cmds.listRelatives(cmds.ls(cameras=1),parent=1) if not cmds.camera(c, q=True, startupCamera=True)]
camLs.extend(allCams)
menu = QMenu("menu", self.setCameraBtn)
for item in camLs:
menu.addAction(QAction(item, menu))
self.setCameraBtn.setMenu(menu)
menu.aboutToShow.connect(self._updateMenu)
menu.triggered.connect(self._camSelected)
def _camSelected(self, action):
self.currentCamTxt.setText(action.text())
def _updateMenu(self):
menu = QMenu("menu", self.setCameraBtn)
menu.clear()
allCams = [c for c in cmds.listRelatives(cmds.ls(cameras=1),parent=1) if not cmds.camera(c, q=True, startupCamera=True)]
if not allCams:
return
del camLs[:]
camLs.extend(allCams)
## No globals
# camLs = []
class orientCameraUI(QDialog):
def __init__(self, parent=None):
super(orientCameraUI, self).__init__(parent)
# You have a class, so you should store state in the class
self.__camLs = []
self.setMinimumWidth(300)
self.setMaximumHeight(80)
self._initUI()
self._camMenu()
# self.createConnections()
def _initUI(self):
...
## Get rid of this. The QPushButton doesn't have aboutToShow()
# def createConnections(self):
# self.connect(self.setCameraBtn, SIGNAL('aboutToShow()'), self._updateMenu)
def _camMenu(self):
menu = QMenu("menu", self.setCameraBtn)
self.setCameraBtn.setMenu(menu)
menu.aboutToShow.connect(self._updateMenu)
menu.triggered.connect(self._camSelected)
def _camSelected(self, action):
self.currentCamTxt.setText(action.text())
def _updateMenu(self):
## You were creating a brand new menu and clearing it
## each time, instead of clearing the one already set
## on the QPushButton. So nothing was really changing.
# menu = QMenu("menu", self.setCameraBtn)
menu = self.setCameraBtn.menu()
menu.clear()
cams = cmds.listRelatives(cmds.ls(cameras=True), parent=True)
if not cams:
return
allCams = [c for c in cams if not cmds.camera(c, q=True, startupCamera=True)]
self.__camLs = allCams
if not allCams:
return
for item in camLs:
menu.addAction(item)
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4fead427-96fa-4891-919b-26564df30b23%40googlegroups.com.
I see and I do not think there is a need for me to define an instance attribute - self.__camLs seeing that I am not really using it anywhere...
By the way, may I ask if menu = QMenu("menu", self.setCameraBtn) is not equivalent to menu = self.setCameraBtn.menu()? Can I take it that the latter one creates a new menu while the former is attaching the QMenu onto the setCameraBtn?
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2492857a-9e98-4131-affb-1f1cc348b5de%40googlegroups.com.