Advertisement
Guest User

UI Main

a guest
Nov 22nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.16 KB | None | 0 0
  1. import maya.mel as mel
  2. import maya.OpenMayaUI as apiUI
  3. import os,sys, random
  4.  
  5.  
  6.  
  7. try:
  8.     from PySide2.QtCore import *
  9.     from PySide2.QtGui import *
  10.     from PySide2.QtWidgets import *
  11.     from PySide2.QtUiTools import *
  12.     from shiboken2 import wrapInstance
  13. except ImportError:
  14.     from PySide2.QtCore import *
  15.     from PySide2.QtGui import *
  16.     from PySide2.QtWidgets import *
  17.     from PySide2.QtUiTools import *
  18.     from shiboken2 import wrapInstance
  19.  
  20.  
  21.  
  22. def getMayaWindow():
  23.     """
  24. Get the main Maya Window as a QtGui.QMainWindow instance
  25. """
  26.    
  27.     ptr = apiUI.MQtUtil.mainWindow()
  28.     if ptr is not None:
  29.         return wrapInstance(long(ptr), QWidget)
  30.        
  31. class cgpWindow(QMainWindow):
  32.     def __init__(self,parent= getMayaWindow()):
  33.         super(cgpWindow,self).__init__()
  34.        
  35.         #Set variables
  36.         self.setWindowTitle("PLUG IN SUNSHINE")
  37.         self.winWidth  = 300
  38.         self.winHeight = 100
  39.         self.setGeometry(10,20,self.winWidth,self.winHeight)
  40.         self.setWindowFlags(Qt.Tool)
  41.         self.setAttribute(Qt.WA_DeleteOnClose)
  42.         self.setWindowFlags(Qt.WindowStaysOnTopHint)
  43.         self.currentWidgets=[]
  44.         #Set initialize
  45.         self.initUI()
  46.        
  47.     def initUI(self):
  48.         """
  49.    Method for initializing the UI
  50.    Create default MainWindow Widget
  51.    """
  52.         mainWidget= QWidget()
  53.         self.mainLayout =QVBoxLayout()
  54.        
  55.         #Create items for the UI
  56.         self.loadObjUi()
  57.         self.loadCrvUi()
  58.         self.executeAleatorio()
  59.         self.CentrarObjeto()
  60.         self.loadNumObjUi()
  61.         self.loadComBox()
  62.        
  63.         """
  64.      self.MinMaxToUi()
  65.      self.RotarsToUi()
  66.      self.TranslateToUi()
  67.      self.ScalartsToUi()
  68.      self.Ejecutar()
  69.      """
  70.        
  71.        
  72.        
  73.        
  74.         #Set signals and slots
  75.         """self.loadObjButton.clicked.connect(self.mainLoadObj)
  76.       self.loadCrvButton.clicked.connect(self.mainLoadObj)
  77.       self.OrdenAleatorioButton.clicked.connect(self.randomizeTranslate)
  78.       self.CenterButton.clicked.connect(self.randomizeTranslate)
  79.  
  80.      
  81.      self.loadRotateButton.clicked.connect(self.executeOverideRotate)
  82.      self.loadTranslateButton.clicked.connect(self.executeOverideTranslate)
  83.      self.loadScalartsButton.clicked.connect(self.executeOverideScalarts)
  84.      self.EjecutarButton.clicked.connect(self.AhoraSiEjecuta)"""
  85.        
  86.        
  87.        
  88.         #Partent Widget to Layout and Layout to QMainWindow
  89.         mainWidget.setLayout(self.mainLayout)
  90.         self.setCentralWidget(mainWidget)
  91.        
  92.         #Show UI
  93.         self.show()
  94.        
  95.     def loadObjUi(self):
  96.         """
  97.      Method for adding the Ui elements for the Load Obj
  98.      """
  99.         #Label Items
  100.         loadObjLabel= QLabel("Load Object:")
  101.        
  102.        
  103.        
  104.         #Line Edit Items
  105.         self.loadObjLineEdit = QLineEdit()
  106.         self.loadObjLineEdit.setEnabled(False)
  107.        
  108.         #Button Edit Items
  109.         self.loadObjButton =QPushButton ("<< Load")
  110.         self.loadObjButton.setToolTip("Selecciona uno o más objetos")
  111.        
  112.         #Create Layout
  113.         loadObjLayout = QHBoxLayout()
  114.         loadObjLayout.addWidget(loadObjLabel)
  115.         loadObjLayout.addWidget(self.loadObjLineEdit)
  116.         loadObjLayout.addWidget(self.loadObjButton)
  117.          
  118.         #Add layout to MainWindow
  119.         self.mainLayout.addLayout(loadObjLayout)
  120.        
  121.     def loadCrvUi(self):
  122.         """
  123.      Método para insertar curva en el UI
  124.      """
  125.         #Label Items
  126.         loadCrvLabel= QLabel("Agrega tu curva:")
  127.        
  128.        
  129.        
  130.         #Line Edit Items
  131.         self.loadCrvLineEdit = QLineEdit()
  132.         self.loadCrvLineEdit.setEnabled(False)
  133.        
  134.         #Button Edit Items
  135.         self.loadCrvButton =QPushButton ("<< Load")
  136.         self.loadCrvButton.setToolTip("Selecciona una o más curvas")
  137.        
  138.         #Create Layout
  139.         loadCrvLayout = QHBoxLayout()
  140.         loadCrvLayout.addWidget(loadCrvLabel)
  141.         loadCrvLayout.addWidget(self.loadCrvLineEdit)
  142.         loadCrvLayout.addWidget(self.loadCrvButton)
  143.          
  144.         #Add layout to MainWindow
  145.         self.mainLayout.addLayout(loadCrvLayout)
  146.        
  147.     def executeAleatorio(self):
  148.         """
  149.    Method for executing oren Aleatorio
  150.    """
  151.         #Label Items
  152.         loadOrdenAleatorioLabel= QLabel("   ")
  153.      
  154.         #Create Buttom
  155.         self.OrdenAleatorioButton= QCheckBox ("Aleatorio")
  156.        
  157.         #Button Edit Items
  158.         self.OrdenAleatorioButton.setToolTip("Orden en el que aparecen los objetos. Al desactivar será el orden de selección")
  159.        
  160.         #Parent Under main Layout
  161.         OrdenAleatorioBtLayout =QHBoxLayout()
  162.         OrdenAleatorioBtLayout.addWidget(loadOrdenAleatorioLabel)
  163.         OrdenAleatorioBtLayout.addWidget(self.OrdenAleatorioButton)
  164.        
  165.         #Add layout to MainWindow
  166.         self.mainLayout.addLayout(OrdenAleatorioBtLayout)
  167.        
  168.        
  169.     def CentrarObjeto(self):
  170.         """
  171.    Method for Centrar Objeto
  172.    """
  173.  
  174.      
  175.         #Create Buttom
  176.         self.CenterButton= QPushButton ("Centra tu Objeto")
  177.        
  178.         #Button Edit Items
  179.         self.CenterButton.setToolTip("Colocar pivote en el centro del objeto")
  180.        
  181.         #Parent Under main Layout
  182.         CenterBtLayout =QHBoxLayout()
  183.         CenterBtLayout.addWidget(self.CenterButton)
  184.  
  185.        
  186.        
  187.         self.mainLayout.addLayout(CenterBtLayout)
  188.        
  189.     def loadNumObjUi(self):
  190.         """
  191.      Method for adding the Ui el numero de objetos que vas a agregar
  192.      """
  193.         #Label Items
  194.         loadNumLabel= QLabel("# Objetos a crear")
  195.        
  196.        
  197.        
  198.         #Line Edit Items
  199.         self.loadNumSpinBox = QSpinBox()
  200.         self.loadNumSpinBox.setMaximum(1000)
  201.         self.loadNumSpinBox.setMinimum(1)
  202.        
  203.         #Button Edit Items
  204.         self.loadNumButton =QPushButton ("<< Load")
  205.         self.loadNumButton.setToolTip("Cuantos objetos quieres crear")
  206.        
  207.         #Create Layout
  208.         loadNumLayout = QHBoxLayout()
  209.         loadNumLayout.addWidget(loadNumLabel)
  210.         loadNumLayout.addWidget(self.loadNumSpinBox)
  211.         loadNumLayout.addWidget(self.loadNumButton)
  212.          
  213.         #Add layout to MainWindow
  214.         self.mainLayout.addLayout(loadNumLayout)
  215.        
  216.        
  217.     def loadComBox(self):
  218.         """
  219.      Method for adding the Ui un combo box
  220.      """
  221.  
  222.        
  223.  
  224.  
  225.         #Button Edit Items
  226.         self.loadComboBox =QComboBox()
  227.         listaOpciones=["None","Orientar/Rotar","Trasladar","Escalar"]
  228.         self.loadComboBox.insertItems(4,listaOpciones)
  229.  
  230.         self.loadComboBox.activated.connect(self.Seleccion)
  231.         self.loadComboBox.setToolTip("Cambia para editar los objetos")
  232.        
  233.         #Create Layout
  234.         loadComboBoxLayout = QHBoxLayout()
  235.  
  236.         loadComboBoxLayout.addWidget(self.loadComboBox)
  237.        
  238.          
  239.         #Add layout to MainWindow
  240.         self.mainLayout.addLayout(loadComboBoxLayout)
  241.        
  242.        
  243.     def Seleccion(self):
  244.         Opcion=self.loadComboBox.currentText()    
  245.         test = SecondPopWin(Opcion)
  246.  
  247.         #Antes de añadir nuevo Widget, borramos todos los que tenemos añadidos
  248.         self.cleanWidget(self.currentWidgets)
  249.         self.currentWidgets.append(test)
  250.        
  251.         self.mainLayout.addWidget(test)
  252.        
  253.     def cleanWidget(self,widget):
  254.         for i in widget:
  255.            
  256.             self.mainLayout.removeWidget(i)      
  257.             i.setParent(None)
  258.             widget.remove(i)
  259.        
  260.  
  261. #-----------------------------------------------------------
  262. #------------------------------------------------------------
  263. #---------------------------------------------------------
  264.  
  265. """
  266. Clase para hacer un UI que aparezca y desaparezca según lo que se le pida
  267. """
  268.  
  269.  
  270. #-----------------------------------------------------------
  271. #------------------------------------------------------------
  272. #---------------------------------------------------------
  273.  
  274. def showUi():
  275.     global win
  276.    
  277.     try:
  278.         win.close()
  279.     except:
  280.         pass
  281.        
  282.     win = cgpWindow()
  283.  
  284.  
  285. showUi()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement