Thank you so much for the help!😊

On Tuesday, April 7, 2020 at 4:24:13 PM UTC+5:30, Justin Israel wrote:
>
>
>
> On Tue, Apr 7, 2020, 9:32 PM Soham Parmar <soha...@gmail.com <javascript:>> 
> wrote:
>
>> Thanks a lot for help.
>> That did worked and managed to to apply icons also.
>> i have multiple questions if you can help.
>>
>> 1. I want icons left aligned and Text centre aligned. is it possible? (i 
>> have attache image for thet)
>>
>
> You can read up on using stylesheets to customise the QPushButton:
>
> https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-a-qpushbutton-using-the-box-model
>
>
>> 2. How to check window exists if exist delete it coz every time i run its 
>> opening new window.
>> if cmds.window(self, exists=True):
>> self.close()
>> cmds.deleteUI(self)
>> I tried both thing close() and deleteUI both is not working.
>> but if i run whole code through maya script editor it's working fine but 
>> if i source this code in maya reload it and run its not working.
>> i am running this in my __init__
>>
>
> You can't mix the python cmds api with PySide2 like that. cmds.window() is 
> a different api operating on the ELF UI widget string paths. 
>
> If you want to delete a window you can call window.deleteLater(). However, 
> the constructor of your window is not the right place, since your instance 
> will always exist when you are constructing it. What you would need is a 
> "singleton". That is, a single instance that you keep a global reference to 
> and delete it before creating a new instance and assigning it again. You 
> could store the instance in your module or as a class level attribute. You 
> can even provide a classmethod constructor on your window like create(cls) 
> which will destroy the previous instance stored on the class. 
>
>
>> 3. one situation is i am creating dialog window also.
>> when dialog is open i and i am closing main window dialog is not getting 
>> closed.
>> i want when i close main window every sub windows should close too.
>>
>
> Set the main window as the parent of the dialog. It should delete the 
> children when you delete the parent. But only closing the main window won't 
> close children. Depends on if you want closing the window to delete it or 
> not? 
>
>
>> Sorry for so many questions!😝
>>
>> On Tuesday, April 7, 2020 at 2:13:27 AM UTC+5:30, Justin Israel wrote:
>>>
>>> setObjectName isn't the correct api call for setting the label text of 
>>> the button. That is used for another purpose. What you want is to use 
>>> setText() 
>>> <https://doc.qt.io/qtforpython/PySide2/QtWidgets/QAbstractButton.html#PySide2.QtWidgets.PySide2.QtWidgets.QAbstractButton.setText>
>>> Also, when creating a dynamic number of widgets, it would be better to 
>>> save them into a list or dict instead of just setting the last button you 
>>> create in a single field (although you could always look them up again 
>>> anyways by iterating the layout)
>>>
>>> self.module_buttons = []
>>> for icon in icons:
>>>     objectName = icon.split("__")[1].split(".")[0] + " Module Button" 
>>>     button = QtWidgets.QPushButton()
>>>     button.setText(objectName)
>>>     self.module_buttons.append(button)
>>>     self.verticalLayout_2.addWidget(button)
>>>
>>> Hope that solves your issue.
>>>
>>>
>>> On Tue, Apr 7, 2020 at 8:16 AM Soham Parmar <soha...@gmail.com> wrote:
>>>
>>>>
>>>> Hi Guys,
>>>>
>>>> I am tring to create one window with pyside2. I have never worked with 
>>>> pyside before.
>>>> I have already created the basic window from QtDesigner.
>>>> What i want is, i want to create as many buttons as there is an icon 
>>>> available in specific folder.
>>>> Below code is creating the button as many icons there but its not 
>>>> giving name and i can give only one button pressed command, every button 
>>>> will work exactly same.
>>>> I have uploaded the image of ui created in maya running below code.
>>>>
>>>> Can anybody help me with this?
>>>> Thanks in advance.
>>>>
>>>> This is the code from QtDesigner:- fileName (createModuleUI.py)
>>>> from PySide2 import QtCore, QtGui, QtWidgets
>>>>
>>>> class Ui_Form(object):
>>>>     def setupUi(self, Form):
>>>>         Form.setObjectName("Form")
>>>>         Form.resize(299, 457)
>>>>         self.verticalLayout = QtWidgets.QVBoxLayout(Form)
>>>>         self.verticalLayout.setObjectName("verticalLayout")
>>>>         self.searchLine = QtWidgets.QLineEdit(Form)
>>>>         self.searchLine.setText("")
>>>>         self.searchLine.setObjectName("searchLine")
>>>>         self.verticalLayout.addWidget(self.searchLine)
>>>>         self.scrollArea = QtWidgets.QScrollArea(Form)
>>>>         self.scrollArea.setWidgetResizable(True)
>>>>         self.scrollArea.setObjectName("scrollArea")
>>>>         self.scrollAreaWidgetContents = QtWidgets.QWidget()
>>>>         self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 
>>>> 273, 366))
>>>>         
>>>> self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
>>>>         self.verticalLayout_2 = 
>>>> QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
>>>>         self.verticalLayout_2.setObjectName("verticalLayout_2")
>>>>         self.scrollArea.setWidget(self.scrollAreaWidgetContents)
>>>>         self.verticalLayout.addWidget(self.scrollArea)
>>>>         self.createModuleButton = QtWidgets.QPushButton(Form)
>>>>         self.createModuleButton.setObjectName("createModuleButton")
>>>>         self.verticalLayout.addWidget(self.createModuleButton)
>>>>
>>>>         self.retranslateUi(Form)
>>>>         QtCore.QMetaObject.connectSlotsByName(Form)
>>>>
>>>>     def retranslateUi(self, Form):
>>>>         Form.setWindowTitle(QtWidgets.QApplication.translate("Form", 
>>>> "Create Module", None, -1))
>>>>         
>>>> self.createModuleButton.setText(QtWidgets.QApplication.translate("Form", 
>>>> "Create Module", None, -1))
>>>>
>>>>
>>>> This is the part of code where i am looking for icons and creating 
>>>> buttons.
>>>>
>>>>
>>>> class createModule(createModuleUI.Ui_Form, QtWidgets.QDialog):
>>>> def __init__(self, parentWin=getMayaWindow()):
>>>> super(createModule, self).__init__(parentWin)
>>>> self.setupUi(self)
>>>> self.setProperty("saveWindowPref", True)
>>>> self.populateCreateModuleButtons()
>>>> def populateCreateModuleButtons(self):
>>>> iconPath = cmds.internalVar(usd=True).rsplit("/", 3)[0] + 
>>>> "/scripts/spDev/rigging/sp_modularRig/sp_UI/icons"
>>>> icons = []  # to removeWarning.
>>>> try:
>>>> icons = sorted(listdir(iconPath))
>>>> except:
>>>> cmds.error("Icons path not found.")
>>>> for icon in icons:
>>>> objectName = icon.split("__")[1].split(".")[0] + " Module Button"
>>>> self.ModuleButton = QtWidgets.QPushButton()
>>>> self.ModuleButton.setObjectName(objectName)
>>>> self.verticalLayout_2.addWidget(self.ModuleButton)
>>>> spacerItem = QtWidgets.QSpacerItem(20, 40, 
>>>> QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
>>>> self.verticalLayout_2.addItem(spacerItem)
>>>>
>>>> Icon naming is [biped__Hand.png, biped__Leg.png, biped__Torso.png] 
>>>> currently only 3 is there.
>>>>
>>>> -- 
>>>> 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+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/python_inside_maya/fd805401-dfeb-46dc-a4ce-5f119dd95d8d%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/python_inside_maya/fd805401-dfeb-46dc-a4ce-5f119dd95d8d%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> -- 
>> 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+unsubscr...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/python_inside_maya/25dfda90-7bfb-4212-a392-2a22241fc32d%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/python_inside_maya/25dfda90-7bfb-4212-a392-2a22241fc32d%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/ce9cc09f-fcc0-45aa-ae9f-3750019718ed%40googlegroups.com.

Reply via email to