def __init__(self, title, dock=False, rebuild=False, brand="studio.coop", tooltip="", parent=getMayaWindow()): super(CoopMayaUI, self).__init__(parent) # check if window exists if cmds.window(title, exists=True): if not rebuild: cmds.showWindow(title) return cmds.deleteUI(title, wnd=True) # delete old window # create window self.setWindowTitle(title) self.setObjectName(title) self.setWindowFlags(QtCore.Qt.Tool) # always on top (multiplatform) if cmds.about(mac=True): self.dpiS = 1 else: self.dpiS = cmds.mayaDpiSetting(systemDpi=True, q=True) / 96.0 # check if the ui is dockable if cmds.dockControl(title, query=True, exists=True): print "dock under this name exists" cmds.deleteUI("watercolorFX", ctl=True) cmds.deleteUI("watercolorFX", lay=True) if dock: cmds.dockControl(title, con=title, area='left', label=title) # default UI elements (keeping it simple) self.layout = QtWidgets.QVBoxLayout(self) # self -> apply to QDialog self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setSpacing(0) headerMargin = 10 * self.dpiS self.header = QtWidgets.QLabel(title) self.header.setAlignment(QtCore.Qt.AlignHCenter) self.header.setFont(fontHeader) self.header.setContentsMargins(headerMargin, headerMargin, headerMargin, headerMargin) self.brand = QtWidgets.QLabel(brand) self.brand.setAlignment(QtCore.Qt.AlignHCenter) self.brand.setToolTip(tooltip) self.brand.setStyleSheet( "background-color: rgb(40,40,40); color: rgb(180,180,180); border:solid black 1px" ) self.brand.setFont(fontFooter) self.buildUI() self.populateUI() if not dock: self.show() #parent.show() logger.debug("A coopMayaUI was successfully generated")
def _resize_font(self): '''重缩放maya字体大小 ''' scalemode = cmds.mayaDpiSetting(q = 1,mode = 1) if scalemode == 0: print (u"error:当前ui缩放模式不正确") return else: hudScale = cmds.mayaDpiSetting(q = 1,scaleValue = 1) font_size = int(15/hudScale) current_font_size= cmds.displayPref(q = 1,dfs = 1) if font_size != current_font_size: if font_size == 15: cmds.displayPref(dfs = 16) else: cmds.displayPref(dfs = font_size)
def get_dpi_scale(): """ Gets the dpi scale of the Maya window Returns: (float): DPI scaling factor of the Maya interface TODO: MacOS and Linux version """ if clib.get_local_os() == "win": return cmds.mayaDpiSetting(realScaleValue=True, q=True) return 1.0
def initializePlugin(plugin): """Loads the Bookmarks plugin. Python libraries are found in the `%*_ROOT%/shared` folder and the binaries in `%*_ROOT%/bin`. The environment is set by the installer and should point to the folder where bookmarks.exe resides. """ if INSTALL_ROOT not in os.environ: raise EnvironmentError( u'Is Bookmarks installed?\n(Environment variable `{}` is not set.)' .format(INSTALL_ROOT)) # Add the `shared` folder to the python path shared = u'{}{}{}'.format(os.environ[INSTALL_ROOT], os.path.sep, u'shared') sys.path.insert(0, os.path.abspath(os.path.normpath(shared))) # Add the `bin` folder to the current path envrionment bin = u'{}{}{}'.format(os.environ[INSTALL_ROOT], os.path.sep, u'bin') path = u'{};{}'.format(os.path.abspath(os.path.normpath(bin)), os.environ['PATH']) os.environ['PATH'] = path try: package = __import__(pkg_name) __import__('{}.common'.format(pkg_name)) __import__('{}.maya'.format(pkg_name)) __import__('{}.maya.widget'.format(pkg_name)) except: raise pluginFn = OpenMaya.MFnPlugin(plugin, vendor=u'Gergely Wootsch', version=package.__version__) try: # Initiate the font_db. This will load the used custom fonts to Maya. package.common.font_db = package.common.FontDatabase() # Let Bookmarks know we're not launching it in standalone mode package.common.STANDALONE = False # If Maya has any UI scaling set scale Bookmark's interface accordingly package.common.UI_SCALE = cmds.mayaDpiSetting(scaleValue=True, query=True) # Load Bookmarks package.maya.widget.maya_button = package.maya.widget.MayaBrowserButton( ) cmds.evalDeferred(package.maya.widget.maya_button.initialize) except Exception as e: raise Exception(e)
def apply_dpi_scaling(value, asfloat=False): if hasattr(cmds, 'mayaDpiSetting'): scale = cmds.mayaDpiSetting(q=True, realScaleValue=True) result = scale * value else: result = value if asfloat: return result else: return int(round(result))
def createMayaWindow(title, rebuild=False, brand='studio.coop', tooltip='introduction to the UI'): """ Creates a default Maya window Args: title (str): The title of the Maya window rebuild (bool): If the window is destroyed and rebuild with each call brand (str): The brand of your company tooltip (str): Help tooltip for the UI Returns: window (QDialog): the QDialog instance existed (bool): if the window existed before or not """ if cmds.window(title, exists=True): if not rebuild: cmds.showWindow(title) return None, True cmds.deleteUI(title, wnd=True) # delete old window mWindow = MayaUI() mWindow.setWindowTitle(title) mWindow.setObjectName(title) mWindow.setWindowFlags(QtCore.Qt.Tool) # always on top (multiplatform) if cmds.about(mac=True): mWindow.dpiS = 1 else: mWindow.dpiS = cmds.mayaDpiSetting(systemDpi=True, q=True) / 96.0 # Default UI elements (keeping it simple) mWindow.header = QtWidgets.QLabel(title) mWindow.header.setAlignment(QtCore.Qt.AlignHCenter) mWindow.header.setFont(fontHeader) mWindow.header.setContentsMargins(10, 10, 10, 10) mWindow.brand = QtWidgets.QLabel(brand) mWindow.brand.setToolTip(tooltip) mWindow.brand.setStyleSheet( "background-color: rgb(40,40,40); color: rgb(180,180,180); border:solid black 1px" ) mWindow.brand.setAlignment(QtCore.Qt.AlignHCenter) mWindow.brand.setGeometry(10, 10, 20, 20) mWindow.brand.setFont(fontFooter) logger.debug("Window successfully created") return mWindow, False
def initializePlugin(plugin): """Loads the Bookmarks plugin. Python libraries are found in the `%BOOKMARKS_ROOT%/shared` folder and the binaries are in `%BOOKMARKS_ROOT%/bin`. The environment is set by the installer normally and should point to the folder where bookmarks.exe resides. """ k = 'BOOKMARKS_ROOT' if k not in os.environ: raise EnvironmentError( u'Is Bookmarks installed?\n(Environment variable `{}` is not set.)'.format(k)) shared = u'{}{}{}'.format(os.environ[k], os.path.sep, u'shared') bin = u'{}{}{}'.format(os.environ[k], os.path.sep, u'bin') sys.path.insert(0, os.path.abspath(os.path.normpath(shared))) path = u'{};{}'.format( os.path.abspath(os.path.normpath(bin)), os.environ['PATH']) os.environ['PATH'] = path import bookmarks pluginFn = OpenMaya.MFnPlugin( plugin, vendor=u'Gergely Wootsch', version=bookmarks.__version__) try: import bookmarks.common as common # Must initiate the font_db manually here. common.font_db = common.FontDatabase() common.STANDALONE = False # If Maya has any UI scaling, this will scale Bookmark's interface accordingly common.UI_SCALE = cmds.mayaDpiSetting(scaleValue=True, query=True) import bookmarks.maya.widget as widget widget.maya_button = widget.MayaBrowserButton() cmds.evalDeferred(widget.maya_button.initialize) except ImportError as e: raise ImportError(e) except Exception as e: raise Exception(e)
def apply_dpi_scaling(value): if hasattr(cmds, 'mayaDpiSetting'): scale = cmds.mayaDpiSetting(q=True, realScaleValue=True) return int(scale * value) else: return int(value)
logger = logging.getLogger("coopQt") # create a logger for this file logger.setLevel(logging.DEBUG) # defines the logging level (INFO for releases) # STYLES fontHeader = QtGui.QFont('MS Shell dlg 2', 15) fontFooter = QtGui.QFont('MS Shell dlg 2', 8) # button.setStyleSheet("background-color: rgb(0,210,255); color: rgb(0,0,0);") # imagePath = cmds.internalVar(upd = True) + 'icons/background.png') # button.setStyleSheet("background-image: url(" + imagePath + "); border:solid black 1px;") # self.setStyleSheet("QLabel { color: rgb(50, 50, 50); font-size: 11px; background-color: rgba(188, 188, 188, 50); border: 1px solid rgba(188, 188, 188, 250); } QSpinBox { color: rgb(50, 50, 50); font-size: 11px; background-color: rgba(255, 188, 20, 50); }") PPI = 1 if cmds.about(mac=True): PPI = 1 else: PPI = cmds.mayaDpiSetting(systemDpi=True, q=True) / 96.0 # WINDOW def getMayaWindow(): """ Get the pointer to a maya window and wrap the instance as a QWidget Returns: Maya Window as a QWidget instance """ ptr = omUI.MQtUtil.mainWindow() # pointer to main window return wrapInstance(long(ptr), QtWidgets.QWidget) # wrapper def getDock(name=''): """
'undoAndRepeatPartial', 'undoPartial', ] LOG = logging.getLogger(__name__) ICON_DIR = os.path.join(os.path.dirname(__file__), 'icons') # mel command that will execute the last repeatable func _REPEAT_COMMAND = 'python("{0}._repeatLastFunc()")'.format(__name__) # reference to the last repeatable func _REPEATABLE_FUNC = None _DPI_SCALE = 1.0 if hasattr(cmds, "mayaDpiSetting"): _DPI_SCALE = cmds.mayaDpiSetting(q=True, realScaleValue=True) def _repeatLastFunc(): """ Rerun the last repeatable function. """ if _REPEATABLE_FUNC is not None: _REPEATABLE_FUNC() def _softUpdateWrapper(wrapper, wrapped): """ Update a wrapper function to look like the wrapped function. Like functools.update_wrapper, but doesn't fail when attributes are not found.
import maya.cmds as cmds import maya.mel as mel from maya import OpenMayaUI as omui from PySide2.QtCore import Qt from PySide2.QtGui import QMouseEvent, QPixmap from shiboken2 import wrapInstance import maya.app.renderSetup.common.utils as commonUtils import maya.app.renderSetup.model.plug as plug kExpandedStateString = "expandedState" _DPI_SCALE = 1.0 if not hasattr( cmds, "mayaDpiSetting") else cmds.mayaDpiSetting(query=True, realScaleValue=True) def dpiScale(value): return value * _DPI_SCALE def updateMouseEvent(event): # Handles one and two button mice CMD-click and Control-click events in # order to make it possible to right click and middle click with those mice. if cmds.about(mac=True): numMouseButtons = cmds.mouse(mouseButtonTrackingStatus=True) if numMouseButtons == 1: if event.modifiers() & Qt.MetaModifier: return QMouseEvent(event.type(), event.localPos(), event.windowPos(), event.screenPos(),