osmeldu

radialWindows

Aug 19th, 2018
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.40 KB | None | 0 0
  1. from PySide.QtCore import *
  2. from PySide.QtGui import *
  3. import PySide.QtGui as QtGui
  4. import PySide.QtCore as QtCore
  5. import maya.OpenMayaUI as omu
  6. import maya.cmds as mc
  7. from shiboken import wrapInstance
  8. from functools import partial
  9. import random
  10. from functools import partial
  11. import math
  12.      
  13. class CustomButtom(QtGui.QPushButton):
  14.     def __init__(self):
  15.         super(CustomButtom, self).__init__()
  16.    
  17.     def closeWindow(self, windowsToClose):
  18.             for w in windowsToClose:
  19.                 w.resize(55,55)
  20.                 w.deleteLater()
  21.                
  22.     def mouseMoveEvent(self, event):
  23.         print("in focus")
  24.        
  25.     def enterEvent(self, event):
  26.         print("Enter")
  27.         #button.setStyleSheet("background-color:#45b545;")
  28.  
  29.     def leaveEvent(self, event):
  30.         #button.setStyleSheet("background-color:yellow;")
  31.         print("Leave")
  32.                  
  33.     def buttonCreator(self, parentWindow, buttonName, windowsList):
  34.         #create buttons function
  35.         self.icon = QtGui.QIcon(":/clusterHandle.svg")
  36.         self.buttonTest = QtGui.QPushButton(parent = parentWindow)
  37.         self.buttonTest.setObjectName(buttonName)
  38.         self.buttonTest.setGeometry(QtCore.QRect(0, 0, 50, 50))
  39.         self.buttonTest.setIconSize(QSize(50, 50))
  40.  
  41.         self.buttonTest.setText("test")
  42.         self.buttonTest.clicked.connect(partial(self.closeWindow, windowsList))
  43.         self.buttonTest.setMouseTracking(1)
  44.         self.buttonTest.pressed.connect(PrintTestClass)
  45.         self.buttonTest.setStyleSheet("hover: background-color:blue;")
  46.        
  47.  
  48. class PrintTestClass(object):
  49.     def __init__(self):
  50.         print("this a test")
  51.  
  52. class RadialMenuWindow(object):
  53.    
  54.     def __init__(self):
  55.         self.mousePos = QtGui.QCursor().pos()
  56.         self.mayaMainWindowPtr = omu.MQtUtil.mainWindow()
  57.         self.mayaMainWindow= wrapInstance(long(self.mayaMainWindowPtr), QWidget)
  58.         self.windowsList = []
  59.  
  60.     def menuLikeWindow(self, windowName):
  61.        
  62.         self.windowName = QtGui.QMainWindow(parent = self.mayaMainWindow, flags=QtCore.Qt.FramelessWindowHint)
  63.         self.windowName.setWindowTitle(str(windowName))
  64.         self.windowName.setObjectName(str(windowName))
  65.         #self.windowName.setAttribute(QtCore.Qt.WA_TranslucentBackground)
  66.         #self.windowName.setStyleSheet("background:transparent;")
  67.         self.windowName.resize(80,80)
  68.  
  69.         if not self.windowName in self.windowsList:
  70.             self.windowsList.append(self.windowName)
  71.  
  72.         return self.windowName
  73.      
  74.     def createWindowsFunction(self):
  75.         buttonCreatorInstance = CustomButtom()
  76.         #create a window with its button
  77.         self.windowNorth = self.menuLikeWindow("windowNorth")
  78.         self.windowNorthButton = buttonCreatorInstance.buttonCreator(self.windowNorth, "buttonWindNorth",
  79.                                                                      self.windowsList)
  80.         #self.windowNorthButton.setMouse
  81.    
  82.  
  83.         #position windows based on the windows len
  84.         angleIncrease = 360 / len(self.windowsList)
  85.         radius = 100
  86.         angle = -90
  87.         for i in self.windowsList:
  88.             x = radius * math.cos(math.radians(angle)) + self.mousePos.x()- 25
  89.             y = radius * math.sin(math.radians(angle)) + self.mousePos.y()- 25
  90.             i.move(x, y)
  91.             i.show()
  92.             angle += angleIncrease
Advertisement
Add Comment
Please, Sign In to add comment