简体   繁体   English

如何在我的PySide(Maya)脚本中解决“非序列迭代”问题

[英]How to fix “iteration over non-sequence” in my PySide(Maya) script

I am trying to make PySide Ui in Maya looking at different examples of codes, but mine doesn't work, Problem is that I am getting 我正在尝试让Maya的PySide Ui查看不同的代码示例,但是我的代码不起作用,问题是我得到了

#Traceback (most recent call last):
#   File "maya console", line 69, in <module>
#   File "maya console", line 32, in create
#   File "maya console", line 61, in __init__
#   File "maya console", line 65, in set_items
# TypeError: iteration over non-sequence # 

I read few topics about this error and seems to be a problem when people try to iterate thru instance, but since my knowledge in Object-Oriented programming still lacking , I am confused why is it happening in my script. 我读到的有关此错误的主题很少,当人们尝试遍历实例时似乎是一个问题,但是由于我仍然缺乏对面向对象编程的了解,因此我很困惑为什么它会在脚本中发生。

 from PySide2 import QtGui, QtCore, QtWidgets from shiboken2 import wrapInstance import maya.OpenMaya as om import maya.OpenMayaUI as omui import maya.cmds as cmds import os, functools def getMayaWindow(): pointer = omui.MQtUtil.mainWindow() if pointer is not None: return wrapInstance(long(pointer), QtWidgets.QWidget) class testUi(): def __init__(self): self.window = 'vl_test' self.title = 'Test Remastered' self.size = (1000, 650) def create(self): if cmds.window(self.window, exists=True): cmds.deleteUI(self.window, window=True) self.parentWindow = getMayaWindow() self.mainWindow = QtWidgets.QMainWindow(self.parentWindow) self.mainWindow.setObjectName(self.window) self.mainWindow.setWindowTitle(self.title) self.mainWidget = QtWidgets.QWidget() self.mainWindow.setCentralWidget(self.mainWidget) self.mainLayout = QtWidgets.QFormLayout(self.mainWidget) testIk = test(self) self.mainLayout.addWidget(testIk) self.mainButton = QtWidgets.QPushButton() self.mainLayout.addWidget(self.mainButton) self.mainButton.clicked.connect(partial(self.load_selected)) self.mainWindow.show() class test(): def __init__(self, maya_transform_nodes=[]): qWid = QtWidgets.QWidget() self.setMinW = qWid.setMinimumWidth(300) self.setMinH = qWid.setMinimumHeight(300) self.sss = qWid.setStyleSheet("border:1px solid rgb(0, 255, 0);") self.items = [] self.transform_move = QtGui.QTransform() self.transform_scale = QtGui.QTransform() self.prev_mouse_pos = QtCore.QPoint(0, 0) self.color = QtGui.QColor(0, 255, 50, 50) self.clicked_color = QtGui.QColor(0, 255, 50, 150) self.right_clicked_color = QtGui.QColor(255, 0, 0, 150) if maya_transform_nodes: self.set_items(maya_transform_nodes) def set_items(self, maya_transform_nodes): for path in maya_transform_nodes: print path v = testUi() v.create() 

Expected result would be - I get window , with button which doesn't function and small widget which I wrote in test(). 预期的结果是-我得到window,其中按钮不起作用,并且是在test()中编写的小部件。

In testUi.create you have: testUi.create您具有:

testIk = test(self)

But self is just the class instance of testUi . 但是self只是testUi的类实例。 It is a class, not a list. 它是一个类,而不是列表。 But it is being passed as maya_transform_nodes in test , which expects a list or other iterable. 但是,它正在为通过maya_transform_nodestest ,这需要一个列表或其他迭代。 So either pass it a list (or other iterable), or remove the argument and let it default to [] . 因此,可以将其传递给列表(或其他可迭代),或删除参数并将其默认设置为[]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM