# maya/scripts/qt_dev/particles_ui.py
# Execute the following code in a python tab of Maya's script editor.
"""
import particles_ui as pui
reload(pui)
dialog = pui.ParticlesDialog()
"""
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtUiTools import *
from sliders import *
from gen_points1 import *
from gen_points_Ring import*
import particles_tabs_ui
reload(particles_tabs_ui)
import maya.cmds as cmds
class ParticlesDialog(QDialog):
# "__init__" is a special function that is automatically called
# by python when an instance of our DemoDialog class is created.
def __init__(self, parent=None):
# Because our class is derived from QDialog its constructor is called.
QDialog.__init__(self, parent)
# This maintains a list of the particle transform node names
self.particle_transforms = []
# Ensure our window stays in front and give it a title
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.setWindowTitle("NParticle Maker")
self.setFixedSize(437, 200)
# Create and assign the main (vertical) layout.
vlayout = QVBoxLayout()
self.setLayout(vlayout)
# We want to have the tabs at the top of the dialog
self.addTabsPanel(vlayout)
# We want to have the sliders at the top of the dialog
#self.addSlidersPanel(vlayout)
# Ensure the buttonPanel is pushed down to the lower edge of the
# Dialog window.
vlayout.addStretch()
self.addButtonPanel(vlayout)
self.show()
#-------------------------------------------------------------
def addTabsPanel(self, parentLayout):
self.tabs = QTabWidget()
page_1 = particles_tabs_ui.BoxTabPage("Box")
page_2 = particles_tabs_ui.SphereTabPage("Sphere")
page_3 = particles_tabs_ui.ConeTabPage("Cone")
page_4 = particles_tabs_ui.DiskTabPage("Disk")
page_5 = particles_tabs_ui.CylinderTabPage("Cylinder")
page_6 = particles_tabs_ui.RingTabPage("Ring")
page_7 = particles_tabs_ui.TorousTabPage("Torous")
self.tabs.addTab(page_1, page_1.name)
self.tabs.addTab(page_2, page_2.name)
self.tabs.addTab(page_3, page_3.name)
self.tabs.addTab(page_4, page_4.name)
self.tabs.addTab(page_5, page_5.name)
self.tabs.addTab(page_6, page_6.name)
self.tabs.addTab(page_7, page_7.name)
parentLayout.addWidget(self.tabs)
#-------------------------------------------------------------
def addButtonPanel(self, parentLayout):
# Add a Button and connect it to our custom buttonAction() method.
self.okButton = QPushButton("OK")
#self.okButton.setEnabled(False)
self.okButton.clicked.connect(self.createAction)
self.deleteButton = QPushButton("Delete")
self.deleteButton.setEnabled(False)
self.deleteButton.clicked.connect(self.deleteAction)
# For easthetics we add the button to a horizonal layout and use
# stretch() to ensure it is pushed to the right hand edge.
hlayout = QHBoxLayout()
hlayout.addWidget(self.deleteButton)
hlayout.addStretch()
hlayout.addWidget(self.okButton)
parentLayout.addLayout(hlayout)
#--------------------------------------------------------------------
def createAction(self):
page = self.tabs.currentWidget()
#page.doAction()
#print("button has been clicked")
tnode = page.doAction()
self.particle_transforms.append(tnode)
self.deleteButton.setEnabled(True)
#--------------------------------------------------------------------
def deleteAction(self):
if len(self.particle_transforms) > 0:
tnode = self.particle_transforms.pop()
# Check if the particles exists before trying to
# delete it !!!
cmds.delete(tnode)
if len(self.particle_transforms) == 0:
self.deleteButton.setEnabled(False)