Particle UI

isMaya = False
try:
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
except ImportError:
    from PySide2.QtGui import *
    from PySide2.QtWidgets import *
    from PySide2.QtCore import *
    from PySide2.QtUiTools import *
    isMaya = True
    #import maya.cmds as cmds
        
import sys
import os
import math
from sliders import *
import particles
reload(particles)
import maya.cmds as cmds
import tab_panels
reload(tab_panels)
  
class Demo(QDialog):
    def __init__(self, parent=None):
        super(Demo, self).__init__(parent)
        self.setWindowFlags(Qt.WindowStaysOnTopHint)
        self.particleNames = []
        # Create the main vertical layout
        
        vlayout = QVBoxLayout()
        
        pathToLogo = os.path.join(os.path.dirname(__file__), 'icons', 'logo.jpg')
        pixmap = QPixmap(pathToLogo)
        pixmap2 = pixmap.scaled(400, 405)
        logoLabel = QLabel()
        logoLabel.setPixmap(pixmap2)
        logoLabel.setMask(pixmap2.mask())
        vlayout.addWidget(logoLabel)
        
        # Set the main vertical layout
        
        self.setLayout(vlayout)
        
        self.addTabbedPanels(vlayout)
  
        vlayout.addStretch()
        self.addRenderPanel(vlayout)
        self.addButtonPanel(vlayout)
        
        self.setFixedSize(400, 500)
        self.show()
    #-------------------------------------------------------------
    def addRenderPanel(self, parentLayout):
        hlayout = QHBoxLayout()
        self.radius = FloatSlider("Particle Radius", 0, 5.0, 1, hlayout, width=75)
        parentLayout.addLayout(hlayout)
    #-------------------------------------------------------------
    def addTabbedPanels(self, parentLayout):
        self.tabs = QTabWidget()
        panel_1 = tab_panels.DomeTabPanel("Dome")
        panel_2 = tab_panels.ShellTabPanel("Shell")
        panel_3 = tab_panels.WaveyTabPanel("Wave")
        panel_4 = tab_panels.TubeTabPanel("Tube")
        
        self.tabs.addTab(panel_1, panel_1.name)
        self.tabs.addTab(panel_2, panel_2.name)
        self.tabs.addTab(panel_3, panel_3.name)
        self.tabs.addTab(panel_4, panel_4.name)
        parentLayout.addWidget(self.tabs)
    #---------------------------------------------------------        
    def createParticlesAction(self):
        panel = self.tabs.currentWidget()
        name = panel.doAction()
        self.addRenderAttrs(name)
        self.particleNames.append(name)
    #---------------------------------------------------------        
    # Activated by the button being clicked
    def deleteParticlesAction(self):
        if len(self.particleNames) == 0:
            return
        if isMaya:
            cmds.delete(self.particleNames.pop())
        print('Particles Deleted')
    #---------------------------------------------------------    
    def addButtonPanel(self, parentLayout):
        self.deleteButton = QPushButton("Delete Particles")
        self.deleteButton.clicked.connect(self.deleteParticlesAction)
        
        self.createButton = QPushButton("Create Particles")
        self.createButton.clicked.connect(self.createParticlesAction)
        hlayout = QHBoxLayout()
        hlayout.addWidget(self.deleteButton)
        hlayout.addStretch()
        hlayout.addWidget(self.createButton)
        parentLayout.addLayout(hlayout)
    #---------------------------------------------------------
    def addRenderAttrs(self,name):
        shapename = cmds.listRelatives(name)[0]
        cmds.setAttr(shapename + '.particleRenderType', 4)
        cmds.addAttr(shapename, internalSet=True, ln='radius', at='float', min=0, max=10, dv=0.5)
        cmds.setAttr(shapename + '.radius', 0.05)
#---------------------------------------------------------
  
if __name__ == '__main__':
    # Create the Qt Application
    app = QApplication(sys.argv)
    demo = Demo()
    demo.show()
    sys.exit(app.exec_())