There actually isn't anything wrong if you want to do that approach. It is
just a stylistic thing I do, where I tend to keep the connections within
the same block of code where the widgets are created, usually at the
bottom, just for the association. I only did it here to write shorter code.

On Tue, Sep 30, 2014 at 9:20 PM, likage <[email protected]> wrote:

> Hey,
>
> This is totally cool! Gets my stuff working!!
>
> Just curious though, why couldn't I use connecting/connections, basically
> in a similar fashion that I did in my code? Thought it may be a good thing
> to standardized my code style?
>
>
> On Tuesday, September 30, 2014 3:58:48 PM UTC+8, Justin Israel wrote:
>>
>> Hey there,
>>
>> You want to get the camera that was selected from the QMenu? Then instead
>> of connecting to the button click, you probably want to watch the signals
>> on the actual QMenu, which will tell you exactly which action was selected.
>> Here is a simplified version:
>>
>> 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())
>>
>> ​
>>
>>
>>
>> On Tue, Sep 30, 2014 at 7:57 PM, likage <[email protected]> wrote:
>>
>>> I am trying to get the selection that was listed in the qMenu and based
>>> on the user selection from the qMenu - camSelBtn, it will display the
>>> selection into a qLineEdit - currentCamTxt
>>>
>>> However while I am able to get the menu working, the  grabbing of text
>>> of the selection is not working.
>>>
>>>
>>> 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()
>>>
>>>
>>>
>>>  --
>>> 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/2c9cdcc9-9263-4b8b-a7ce-
>>> 47fbe9004cff%40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/2c9cdcc9-9263-4b8b-a7ce-47fbe9004cff%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> 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/9b8acefa-41f6-4895-bb37-1b3ad8a39dae%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/9b8acefa-41f6-4895-bb37-1b3ad8a39dae%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAPGFgA1r1QhO9BABbWeSOZnMk806PEh1yFB%2Bi8XkTGHXJC5DOA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to