Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt4 import QtCore,QtGui
- from functools import partial
- import sys,os,subprocess,pickle
- import Render
- import ast,datetime
- class Window(QtGui.QWidget):
- renderer={
- 'Mental Ray':'mr',
- 'Maya Software':'sw',
- 'Maya Vecter':'vr',
- 'Maya Hardware 2.0':'mayaHardware2',
- 'Maya Hardware':'mayaHardware'
- }
- browsBtnSig=QtCore.pyqtSignal(int)
- def __init__(self,*args,**kwargs):
- super(Window,self).__init__(*args,**kwargs)
- self.setWindowTitle("Snowball Batch Render")
- self.resize(500,400)
- self.setMinimumSize(400,300)
- self.setMaximumSize(600,400)
- self.setWindowIcon(QtGui.QIcon('images/Snowball-icon.png'))
- self.accessAction = Render.Actions()
- self.settingsDir=os.path.join(os.path.split(__file__)[0],"settings")
- self.maSetfile=os.path.join(self.settingsDir,"mayaSettings.txt")
- if os.path.isfile(self.maSetfile):
- self.items = self.readSettingFile()
- else:
- self.items={
- 'Maya Executable':'',
- 'Render':'',
- 'Mayapy Interpreter':'',
- 'imgcvt':'',
- 'IMConvert':''}
- self.createUI()
- def initializeSetting(self):
- if os.path.isfile(self.maSetfile):
- if str(self.appExeCB.currentText())=='Maya Executable':
- self.appExeEdt.setText(self.items['Maya Executable'])
- def appExeCBSelChange(self):
- """
- Sets the path of selected items to self.appExeEdt(QLineEdit)
- """
- self.appExeEdt.setText(self.items[str(self.appExeCB.currentText())])
- def getSelectedRendertype(self):
- if self.mayachkBox.checkState() == QtCore.Qt.Checked:
- self.label.setText("Maya Scene File")
- self.rndCB.setEnabled(True)
- self.camlbl.setText("Select Camera")
- elif self.nukechkBox.checkState() == QtCore.Qt.Checked:
- self.label.setText("Nuke Script File")
- self.rndCB.setEnabled(False)
- self.camlbl.setText("Write node")
- def createUI(self):
- quitAction=QtGui.QAction('&Exit',self)
- quitAction.triggered.connect(self.close)
- fileMenu=QtGui.QMenuBar()
- phile=fileMenu.addMenu('&File')
- help=fileMenu.addMenu('&Help')
- phile.addAction(quitAction)
- #add my checkboxes to select render type task
- self.mayachkBox=QtGui.QCheckBox()
- self.mayachkBox.setCheckState(QtCore.Qt.Checked)
- self.mayachkBox.stateChanged.connect(self.getSelectedRendertype)
- mayaIcon=QtGui.QPixmap("images/Maya_Icon.png")
- self.mayachkBox.setIcon(QtGui.QIcon(mayaIcon))
- self.mayachkBox.setIconSize(QtCore.QSize(25,25))
- self.nukechkBox=QtGui.QCheckBox()
- nukeIcon= QtGui.QPixmap("images/nuke_icon.png")
- self.nukechkBox.setIcon(QtGui.QIcon(nukeIcon))
- self.nukechkBox.stateChanged.connect(self.getSelectedRendertype)
- self.nukechkBox.setIconSize(QtCore.QSize(25,25))
- chkboxLayout=QtGui.QHBoxLayout()
- chkboxLayout.addStretch(1)
- chkboxLayout.addWidget(self.mayachkBox)
- chkboxLayout.addWidget(self.nukechkBox)
- chkboxLayout.addStretch(1)
- #make button exclusive
- self.chkBoxGrp=QtGui.QButtonGroup()
- self.chkBoxGrp.setExclusive(True)
- # add checkBoxes to exclusive groups
- self.chkBoxGrp.addButton(self.mayachkBox)
- self.chkBoxGrp.addButton(self.nukechkBox)
- # initialize tab widget
- tab_widget = QtGui.QTabWidget()
- # Everything will go inside the below QWidgets
- tab1 = QtGui.QWidget()
- tab2 = QtGui.QWidget()
- tab3 = QtGui.QWidget()
- p1_vertical = QtGui.QVBoxLayout(tab1)
- p2_vertical = QtGui.QVBoxLayout(tab2)
- self.p3_vertical = QtGui.QVBoxLayout(tab3)
- tab_widget.addTab(tab1, "Render Setup")
- tab_widget.addTab(tab2, "Task Queue")
- tab_widget.addTab(tab3, "Settings")
- gridLayout = QtGui.QGridLayout()
- self.label=QtGui.QLabel("Maya Scene File")
- gridLayout.addWidget(self.label,0,0)
- self.scnFilePath=QtGui.QLineEdit()
- self.scnFilePath.setToolTip("Enter scene file name")
- gridLayout.addWidget(self.scnFilePath,0,1)
- self.browseBtn=QtGui.QPushButton("Browse")
- self.browseBtn.setObjectName('browsbtn')
- gridLayout.addWidget(self.browseBtn,0,2)
- dirlabel=QtGui.QLabel("Render Directory")
- gridLayout.addWidget(dirlabel,1,0)
- self.renDir=QtGui.QLineEdit()
- self.renDir.setToolTip("Specify the directory you want render to go")
- gridLayout.addWidget(self.renDir,1,1)
- self.rdBtn=QtGui.QPushButton("Browse")
- gridLayout.addWidget(self.rdBtn,1,2)
- gridLayout2=QtGui.QGridLayout()
- gridLayout2.setSpacing(1)
- #First Row
- sfLbl=QtGui.QLabel("Start Frame")
- gridLayout2.addWidget(sfLbl,0,0)
- self.sfEdt=QtGui.QLineEdit()
- gridLayout2.addWidget(self.sfEdt,0,1)
- eflbl=QtGui.QLabel("End Frame")
- gridLayout2.addWidget(eflbl,0,2)
- self.efEdt=QtGui.QLineEdit()
- gridLayout2.addWidget(self.efEdt,0,3)
- byfrlbl=QtGui.QLabel("Interval")
- gridLayout2.addWidget(byfrlbl,0,4)
- self.byfrEdt=QtGui.QLineEdit()
- gridLayout2.addWidget(self.byfrEdt,0,5)
- rndlbl=QtGui.QLabel("Renderer")
- #Second Row
- gridLayout2.addWidget(rndlbl,1,0)
- self.rndCB=QtGui.QComboBox()
- self.rndCB.addItems(self.renderer.keys())
- self.rndCB.setCurrentIndex(self.renderer.keys().index('Maya Software'))
- gridLayout2.addWidget(self.rndCB,1,1)
- self.camlbl=QtGui.QLabel("Select Camera")
- self.camlbl.setFixedWidth(70)
- gridLayout2.addWidget(self.camlbl,1,2)
- self.camCB=QtGui.QComboBox()
- gridLayout2.addWidget(self.camCB,1,3)
- fmtlbl=QtGui.QLabel("Format")
- gridLayout2.addWidget(fmtlbl,1,4)
- self.fmtCB=QtGui.QComboBox()
- self.fmtCB.addItems(self.accessAction.readImageFormats().values())
- gridLayout2.addWidget(self.fmtCB,1,5)
- #Create a validator for each frame number text box
- self.sfEdt.setValidator(QtGui.QIntValidator())
- self.efEdt.setValidator(QtGui.QIntValidator())
- self.byfrEdt.setValidator(QtGui.QIntValidator())
- hbox=QtGui.QHBoxLayout()
- rgbchkBox=QtGui.QCheckBox("RGB")
- rgbchkBox.setCheckState(QtCore.Qt.Checked)
- alpchkBox=QtGui.QCheckBox("Alpha")
- depchkBox=QtGui.QCheckBox("Z-Depth")
- addCmdlbl=QtGui.QLabel("Additional Commands")
- addCmdEdt=QtGui.QLineEdit()
- hLine=QtGui.QFrame(self)
- hLine.setFrameShape(QtGui.QFrame.HLine)
- hLine.setFrameShadow(QtGui.QFrame.Raised)
- nxtbtnbox=QtGui.QHBoxLayout()
- ## Render Buttons
- self.bgnBatRndBtn=QtGui.QPushButton("Render Current")
- addTaskBtn=QtGui.QPushButton("Add to Render Queue")
- nxtbtnbox.addWidget(self.bgnBatRndBtn)
- nxtbtnbox.addWidget(addTaskBtn)
- hbox.addWidget(rgbchkBox)
- hbox.addWidget(alpchkBox)
- hbox.addWidget(depchkBox)
- hbox.addStretch(1)
- hbox.addWidget(addCmdlbl)
- hbox.addWidget(addCmdEdt)
- #add status bar
- self.statusbar=QtGui.QStatusBar()
- self.statusbar.showMessage("Ready")
- # assign signals to slots
- scnFile=partial(self.showFileDialog,"scnFile")
- self.browseBtn.clicked.connect(scnFile)
- rndPath=partial(self.showFileDialog,"rdPath")
- self.rdBtn.clicked.connect(rndPath)
- self.scnFilePath.textChanged.connect(self.execMayapy)
- self.bgnBatRndBtn.clicked.connect(self.writeBatFile)
- # add layouts that contain inside of tab1 widgets
- p1_vertical.addLayout(gridLayout)
- p1_vertical.addLayout(gridLayout2)
- p1_vertical.addLayout(hbox)
- p1_vertical.addWidget(hLine)
- p1_vertical.addLayout(nxtbtnbox)
- self.settingTabContent()
- vbox = QtGui.QVBoxLayout()
- vbox.setMargin(0)
- vbox.addWidget(fileMenu)
- vbox.addLayout(chkboxLayout)
- vbox.addWidget(tab_widget)
- vbox.addWidget(self.statusbar)
- self.setLayout(vbox)
- def makebatFileTasks(self):
- pass
- def writeBatFile(self):
- now = datetime.datetime.now()
- buildCrntTime=str(now.hour) +"_" + str(now.minute)
- selected=str(self.scnFilePath.text())
- quikBatNam=os.path.basename(selected).split(".")[0]+"_"+buildCrntTime+".bat"
- self.batfiletoSave=os.path.join(os.path.split(selected)[0],quikBatNam)
- try:
- writeBat=open(self.batfiletoSave,'w')
- except: pass
- finally: writeBat.close()
- def execMayapy(self):
- ## call to readMayaFile.py using mayapy.exe interpreter
- fileToOpen=str(self.scnFilePath.text())
- fileName=os.path.join(os.path.split(__file__)[0],"readMayaFile.py "+fileToOpen)
- test="mayapy "+ fileName
- process = subprocess.Popen(test, shell=True, stdout=subprocess.PIPE)
- process.wait()
- if process.returncode==0: # 0 = success, optional check
- print "Success Reading: %s" % os.path.basename(fileToOpen)
- # read the result to a string
- self.objRead = ast.literal_eval(process.stdout.read())
- print self.objRead
- self.fillInputs()
- else: print "Unable to read maya scene file: %s" % os.path.basename(fileToOpen)
- def fillInputs(self):
- self.camCB.clear()
- self.camCB.addItems(self.objRead['camsLst'])
- self.sfEdt.setText(str(self.objRead['startFrame']))
- self.efEdt.setText(str(self.objRead['endFrame']))
- self.byfrEdt.setText(str(self.objRead['stepByFrame']))
- ## Select the default renderer
- if str(self.objRead['defaultRenderer'])=='mayaSoftware':
- self.rndCB.setCurrentIndex(self.renderer.keys().index('Maya Software'))
- elif str(self.objRead['defaultRenderer'])=='mayaHardware':
- self.rndCB.setCurrentIndex(self.renderer.keys().index('Maya Hardware'))
- elif str(self.objRead['defaultRenderer'])=='mentalRay':
- self.rndCB.setCurrentIndex(self.renderer.keys().index('Mental Ray'))
- elif str(self.objRead['defaultRenderer'])=='mayaVector':
- self.rndCB.setCurrentIndex(self.renderer.keys().index('Maya Vecter'))
- elif str(self.objRead['defaultRenderer'])=='mayaHardware2':
- self.rndCB.setCurrentIndex(self.renderer.keys().index('Maya Hardware 2.0'))
- else: self.rndCB.setCurrentIndex(self.renderer.keys().index(str(self.objRead['defaultRenderer'])))
- def showFileDialog(self,*args):
- directory=os.path.expanduser('~')
- fileFilters="Maya Ascii/Binary(*.ma *.mb);; Maya Ascii(*.ma);; Maya Binary( *.mb )"
- if args[0]=="scnFile":
- fname=str(QtGui.QFileDialog.getOpenFileName(self,'Open File',directory,self.tr(fileFilters)))
- if os.path.isfile(fname):
- fname=os.path.normpath(fname)
- if args[1]=="appFile":
- self.appExeEdt.setText(fname)
- else:
- self.scnFilePath.setText(fname)
- elif args[0]=="rdPath":
- selectedDir=str(QtGui.QFileDialog.getExistingDirectory(self,"Select Render Directory",directory))
- if not selectedDir:
- print "No directory selected"
- else:
- selectedDir=os.path.normpath(selectedDir)
- self.renDir.setText(selectedDir)
- def updateAppPaths(self):
- appSel = str(self.appExeEdt.text())
- if os.path.isfile(appSel):
- if os.path.split(appSel)[-1]=="maya.exe":
- self.items['Maya Executable']=appSel
- else:
- appSel=os.path.join(os.path.split(appSel)[0],"maya.exe")
- if os.path.isfile(appSel):
- self.items['Maya Executable']=appSel
- mayapy=os.path.join(os.path.split(appSel)[0],"mayapy.exe")
- if os.path.isfile(mayapy):
- self.items['Mayapy Interpreter']=mayapy
- imgcvt=os.path.join(os.path.split(appSel)[0],"imgcvt.exe")
- if os.path.isfile(imgcvt):
- self.items['imgcvt']=imgcvt
- IMConvert=os.path.join(os.path.split(appSel)[0],"imconvert.exe")
- if os.path.isfile(IMConvert):
- self.items['IMConvert']=IMConvert
- Render=os.path.join(os.path.split(appSel)[0],"render.exe")
- if os.path.isfile(Render):
- self.items['Render']=Render
- def savSettingFile(self):
- """Saves Maya Application paths to setting file on disk"""
- try:
- if not os.path.isdir(self.settingsDir):
- os.makedirs(self.settingsDir)
- output_phile=open(self.maSetfile,"w")
- pickle.dump(self.items,output_phile,1)
- except Exception as e:
- print e
- finally:
- output_phile.close()
- def readSettingFile(self):
- """ Read the setting file that contains the Maya Application paths"""
- try:
- read_phile=open(self.maSetfile,"r")
- self.items=pickle.load(read_phile)
- except Exception as e:
- print e
- finally:
- read_phile.close()
- return self.items
- def settingTabContent(self):
- """
- Content of the settings tab and signal to slot conntections
- """
- p3_HBox=QtGui.QHBoxLayout()
- self.appExeCB=QtGui.QComboBox()
- self.appExeCB.addItems(self.items.keys())
- self.appExeCB.setCurrentIndex(self.items.keys().index('Maya Executable'))
- self.appExeEdt=QtGui.QLineEdit()
- self.brwBtn=QtGui.QPushButton("Browse")
- p3_HBox.addWidget(self.appExeCB)
- p3_HBox.addWidget(self.appExeEdt)
- p3_HBox.addWidget(self.brwBtn)
- p3_HBox2=QtGui.QHBoxLayout()
- self.pylbl=QtGui.QLabel("Python Script")
- self.pyEdt=QtGui.QLineEdit()
- self.pybrwBtn=QtGui.QPushButton("Browse")
- p3_HBox3=QtGui.QHBoxLayout()
- self.savSetBtn=QtGui.QPushButton("Save Settings")
- p3_HBox3.addStretch(1)
- p3_HBox3.addWidget(self.savSetBtn)
- p3_HBox2.addStretch(1)
- #Connect buttons to slots
- self.appFiles=partial(self.showFileDialog,"scnFile","appFile")
- self.brwBtn.clicked.connect(self.appFiles)
- self.appExeEdt.textChanged.connect(self.updateAppPaths)
- self.appExeCB.currentIndexChanged.connect(self.appExeCBSelChange)
- #Save maya application paths (self.items) to a file on disk
- self.savSetBtn.clicked.connect(self.savSettingFile)
- [p3_HBox2.addWidget(each) for each in [self.pylbl,self.pyEdt,self.pybrwBtn]]
- self.pyEdt.setFixedWidth(261)
- self.p3_vertical.addLayout(p3_HBox)
- self.p3_vertical.addLayout(p3_HBox2)
- self.p3_vertical.addStretch(1)
- self.p3_vertical.addLayout(p3_HBox3)
- self.initializeSetting()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement