Hello Justin,
I am having some solid trouble with my recursive function trying to add
QTreeWidgetItems to the tree hierarchy. The loop continues on and then gets
to a certain point and this error pops up when I try to access a
recursedItem in the list.
RuntimeError: underlying C/C++ object has been deleted
Could this have something to do with the design issues you were talking
about? I have done some digging and read that python wrappers are left
behind or I havent called my init function somewhere?
Here is my function:
def setupModelTree(self):
import UnitManager.scripts.read_model_file as readModel
treeObjects = readModel.testRead()
addedToList = []
recurseRoots = []
recurseInnerRoots = []
recurseNo = -1
# 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_"):
rootName = name
rootItem = QtGui.QTreeWidgetItem([name])
recurseRoots.append(rootItem)
self.modelTree.addTopLevelItem(rootItem)
del treeObjects[name] # Remove the RP from the
dictionary
addedToList.append(name)
break
def recurseAddChildren(dict, iterList, recursiveItems):
newlyAdded = []
recurseInnerRoots = []
# Iterating through through last added items layer
for 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 line
toDelete.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"
break
else:
print "Adding first layer"
for name in dict:
parent = [item for item in
iterList if item == dict.get(name)]
# If the parent exists
if parent:
childToAdd =
QtGui.QTreeWidgetItem([name])
recursedItem.addChild(childToAdd)
newlyAdded.append(name)
recurseInnerRoots.append(childToAdd)
dict = self.deleteDictElements(dict, newlyAdded)
# KEEP OUTSIDE MAIN LOOP
if len(dict) > 0:
recurseAddChildren(dict,
newlyAdded,recurseInnerRoots)
recurseAddChildren(treeObjects, addedToList, recurseRoots)
print "Model panel set up"
On Thursday, 5 March 2015 11:08:53 UTC+1, Justin Israel wrote:
>
> Generally I would say it is a questionable design if you have child
> classes that make assumptions about the members of the parent. It means
> that your child class can only be used with that specific parent class that
> will have the expected attributes. If your child class needs to trigger
> behavior in the parent, a better design would be to have your child class
> emit signals. This should give you a cleaner separation between the two
> widgets. It then becomes the responsibility of your parent window to
> connect to the signals of interest, and perform the required actions as it
> is notified.
>
>
> On Thu, Mar 5, 2015 at 10:27 PM Benjam901 <[email protected]
> <javascript:>> wrote:
>
>> 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:
>>
>>> 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
>>>
>>>
>>>
>>>
>> --
>> 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 [email protected] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/065722da-82df-4108-92d5-6c76844d0696%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/python_inside_maya/065722da-82df-4108-92d5-6c76844d0696%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/bb4a178c-06a0-4f08-9aba-6e028573ebd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.