批量文件渲染
import sys from PySide2.QtWidgets import QApplication, QWidget, QPushButton, QFileDialog, \ QTableWidget, QTableWidgetItem, QHBoxLayout, QVBoxLayout, QHeaderView from PySide2.QtCore import QFileInfo import subprocess class RenderDialog(QWidget): def __init__(self): super(RenderDialog, self).__init__() self.setWindowTitle("Maya Render List") self.setGeometry(800, 600, 600, 600) self.initUI() self.show() def initUI(self): self.file_list = [] self.table = QTableWidget() self.setTableHeader() # Buttons self.add_button = QPushButton("Add..") self.clear_button = QPushButton("Clear") self.cook_button = QPushButton("Start Render") self.quit_button = QPushButton("Quit") self.add_button.setShortcut("Ctrl+A") hbox = QHBoxLayout() hbox.addWidget(self.add_button) hbox.addWidget(self.clear_button) hbox.addWidget(self.cook_button) hbox.addWidget(self.quit_button) vbox = QVBoxLayout() vbox.addWidget(self.table) vbox.addLayout(hbox) self.setLayout(vbox) # Signal self.add_button.clicked.connect(self.getFileData) self.clear_button.clicked.connect(self.clearTable) self.cook_button.clicked.connect(self.cookData) self.quit_button.clicked.connect(self.close) def setTableHeader(self): header_labels = ["File Name", "Format", "File Size", "File Path"] self.table.setColumnCount(len(header_labels)) self.table.setHorizontalHeaderLabels(header_labels) self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) def getFileData(self): files = QFileDialog.getOpenFileNames(self, "Select files", "E:/", "Maya Files(*.ma *.mb)") self.file_list = files[0] self.fillTable(self.setData(self.file_list)) def setData(self, fl): f_list = [] for file in fl: f = QFileInfo(file) file_dict = {'File Name': f.baseName(), \ 'Format': f.suffix(), \ 'File Size': f.size(), \ 'File Path': f.absolutePath()} f_list.append(file_dict) return f_list def fillTable(self, f_info): self.table.setRowCount(len(f_info)) for i in range(0, len(f_info)): self.table.setItem(i, 0, QTableWidgetItem(f_info[i]['File Name'])) self.table.setItem(i, 1, QTableWidgetItem(f_info[i]['Format'])) self.table.setItem(i, 2, QTableWidgetItem(str(f_info[i]['File Size']))) self.table.setItem(i, 3, QTableWidgetItem(f_info[i]['File Path'])) def clearTable(self): self.table.setRowCount(0) def cookData(self): for i in range(0, len(self.file_list)): ret = subprocess.run(["C:/Program Files/Autodesk/Maya2019/bin/Render.exe" , \ "-rd", \ "D:/img", \ self.file_list[i]], \ stdout=subprocess.PIPE, stderr=subprocess.PIPE) if __name__ == "__main__": app = QApplication([]) renderDialog = RenderDialog() sys.exit(app.exec_())