Skip to content

Instantly share code, notes, and snippets.

@takavfx
Last active July 22, 2016 09:26
Show Gist options
  • Save takavfx/41546d2a97ba561ce8b47c977ad0a9c2 to your computer and use it in GitHub Desktop.
Save takavfx/41546d2a97ba561ce8b47c977ad0a9c2 to your computer and use it in GitHub Desktop.
MayaでPySideを使ったWindowを作るときのおまじないてきなやつ。
# -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
## Description
"""
Template for creating window on Maya with PySide.
"""
#----------------------------------------------------------------------------
__author__ = 'name [[email protected]]'
__version__ = "0.0.0"
## Python Modules
import os
import sys
import traceback
import time
from functools import partial
## Maya Modules
import pymel.core as pm
import maya.OpenMayaUI as OpenMayaUI
import maya.cmds as cmds
## PySide Modules
from PySide import QtCore, QtGui
from PySide.QtUiTools import QUiLoader
if '2013' in cmds.about(version=True):
from PySide import shiboken
wrapInstance = shiboken.wrapInstance
else:
from shiboken import wrapInstance
CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
class mainWindow(QtGui.QMainWindow):
"""docstring for mainWindow"""
objectName = 'tool_name'
windowTitle = u'Tool Name v' + __version__
windowWidth = 480
windowHeight = 300
UIPATH = os.path.join(CURRENT_DIR, "ui/gui.ui")
def __init__(self, parent=None):
super(mainWindow, self).__init__(parent)
self.checkUI()
## Load UI file
loader = QUiLoader()
self.UI = loader.load(self.UIPATH)
self.setObjectName(self.objectName)
self.setWindowTitle(self.windowTitle)
self.setCentralWidget(self.UI)
self.initialize()
self.resize(self.windowWidth, self.windowHeight)
def checkUI(self):
if cmds.window(self.objectName, exists=True):
cmds.deleteUI(self.objectName)
def initialize(self):
self.initGui()
self.setSignals()
def initGui(self):
pass
def setSignals(self):
pass
def main():
try:
parent = OpenMayaUI.MQtUtil.mainWindow()
parent = wrapInstance(long(parent), QtGui.QWidget)
ui = mainWindow(parent)
ui.show()
ui.resize(ui._defWidth, ui._defHeight)
ui.windowSizeChange()
except:
errorType, errorValue, traceback_ = sys.exc_info()
tbList = traceback.format_tb(traceback_)
print '[errorType]', errorType
print '[errorValue]', errorValue
for tb in tbList:
print '\t', tb
finally:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment