class MainWindowSetup(QtGui.QMainWindow):def __init__(self):QtGui.QMainWindow.__init__(self)self.uiMainWindow = Ui_MainWindow()self.uiMainWindow.setupUi(self)self.uiModelWindow = ModelWindow()class ModelWindow(QtGui.QTreeWidget):def __init__(self):print "!! Initialised model window"QtGui.QTreeWidget.__init__(self)self.modelTree = self.uiMainWindow.uiModelTree # This is where I get the errorThanks for any help!Cheers,Ben
self.modelTree = self.uiMainWindow.uiModelTree # This is where I get the error
self
is referring to your instance of ModelWindow
, but you store uiMainWindow
in the instance of MainWindowSetup
.
If you want to access that, you’ll need to pass a handle to it. It’s typically done using a parent, but you aren’t including the parent in your __init__
method.
Try something like this.
class MainWindowSetup(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.uiMainWindow = Ui_MainWindow()
self.uiMainWindow.setupUi(self)
self.uiModelWindow = ModelWindow(self)
class ModelWindow(QtGui.QTreeWidget):
def __init__(self, parent):
print "!! Initialised model window"
QtGui.QTreeWidget.__init__(self, parent)
self.modelTree = parent.uiMainWindow.uiModelTree # This is where I get the error
Hello again Marcus,I was wondering why intellisense does not pick up on the internal variables and buttons etc. do I need to add another handle?Cheers,
Ben
On Thursday, 5 March 2015 09:29:23 UTC+1, Marcus Ottosson wrote:
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/065722da-82df-4108-92d5-6c76844d0696%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def setupModelTree(self):import UnitManager.scripts.read_model_file as readModeltreeObjects = readModel.testRead()addedToList = []recurseRoots = []recurseInnerRoots = []recurseNo = -1# Iterate through the dictionary returned by the read model file functionfor name in treeObjects:# Get the root point and add it to the root of the treeif name.startswith("rp_"):rootName = namerootItem = QtGui.QTreeWidgetItem([name])recurseRoots.append(rootItem)self.modelTree.addTopLevelItem(rootItem)del treeObjects[name] # Remove the RP from the dictionaryaddedToList.append(name)breakdef recurseAddChildren(dict, iterList, recursiveItems):newlyAdded = []recurseInnerRoots = []# Iterating through through last added items layerfor recursedItem in recursiveItems:addChildren = []toDelete = []""" @type recursedItem: QtGui.QTreeWidget.QTreeWidget """if iterList[0] != rootName:for d in dict:if dict.get(d) == recursedItem.text(0): # Error linetoDelete.append(d)addChildren.append(QtGui.QTreeWidgetItem([d]))self.deleteDictElements(dict, toDelete)for toBeAdded in addChildren:childItem = QtGui.QTreeWidgetItem(toBeAdded)recursedItem.addChild(childItem)newlyAdded.append(toBeAdded.text(0))recurseInnerRoots.append(childItem)self.deleteDictElements(dict, toBeAdded.text(0))if len(iterList) < 1:print "errored"breakelse:print "Adding first layer"for name in dict:parent = [item for item in iterList if item == dict.get(name)]# If the parent existsif parent:childToAdd = QtGui.QTreeWidgetItem([name])recursedItem.addChild(childToAdd)newlyAdded.append(name)recurseInnerRoots.append(childToAdd)dict = self.deleteDictElements(dict, newlyAdded)# KEEP OUTSIDE MAIN LOOPif len(dict) > 0:recurseAddChildren(dict, newlyAdded,recurseInnerRoots)recurseAddChildren(treeObjects, addedToList, recurseRoots)print "Model panel set up"
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
This would be an unrelated problem to the previously mentioned design issue. What it looks like to me is that you are a deleting recursedItem (TreeWidgetItem) but leaving a reference to it in your container and then calling text() again on it at a later recursion. Probably need to make sure that whatever you are deleting is no longer in the dict.
Also, I am not sure why this part doesn’t give you errors, but it seems like you are changing a dictionary size while looping over it:
# Iterate through the dictionary returned by the read model file function
for name in treeObjects:
# Get the root point and add it to the root of the tree
if name.startswith("rp_"
):
...
del treeObjects[name] # Remove the RP from the dictionary
Normally I would expect that to be an error, since if you plan to add and remove to a dict while looping over it, you should loop over a copy.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/bb4a178c-06a0-4f08-9aba-6e028573ebd0%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/_aEnlsC_60Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2c_fHfxS4bhbdGwggRq8P5rfDzkSE9-%2Be8L%2BeRY2Phzg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Right ya I missed the break. It would only error if it did another loop.
I'm not sure what is really going on here but it is accessing an item in your list that Qt has cleaned up for whatever reason. Could even be a child of an item that was deleted.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkUFYPGS1kuTm0Dra4ddR%2B%2B%2B6g4pmGkn8AcmLyMgSvgT%3Dw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1ZzsFxuM4dABc-1rHeofCfcdQtGnKiJTEbj5oa-0C91Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
for recursedItem in recursiveItems:addChildren = []toDelete = []
addMultiple = 0
if iterList[0] != rootName:
print "In inner loop", recursedItem.text(0)
for d in dict:if dict.get(d) == recursedItem.text(0):
print "We have a parent: ", recursedItem.text(0)
toDelete.append(d)addChildren.append(QtGui.QTreeWidgetItem([d]))self.deleteDictElements(dict, toDelete)for toBeAdded in addChildren:
print "Adding child item", toBeAdded.text(0), recursedItem.text(0)#childItem = QtGui.QTreeWidgetItem(toBeAdded)#recursedItem.addChild(childItem)recursedItem.addChild(toBeAdded)newlyAdded.append(toBeAdded.text(0))#recurseInnerRoots.append(childItem)recurseInnerRoots.append(toBeAdded)self.deleteDictElements(dict, toBeAdded.text(0))Thanks for the help, an epic Google group
I'm not totally certain, but it may specifically be related to creating that temporary item, and then creating a child by passing it to the constructor of the new item, but then passing that as a child of the recursive item. Something was deleting it from that faulty parent child logic. But I am glad you solved it!
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkV3OeN31HhsqEB7_5_eduXxkZfEiR_q6xFay2KUny9xnA%40mail.gmail.com.