Hey Bay,
While its definitely helpful to have your full code in the event that
someone wants to review all of it,it would be ideal to include some concise
snippets in the actual question to establish some context. I had to kind of
scan your entire project to figure out what you were referring to and
reproduce it.
Steps to reproduce:
1. Create a sphere and select
2. Click "Add" in the qt window. Sphere entry pops into view.
3. Select entry and click "Remove". Maya crashes.
What I have found in playing with your code is that returning the
internalPointer, and accessing it from the calling view, produces the
crash. The way I normally handle returning the underlying object
represented by a QModelIndex is to use a custom role for the model and
access it through the data() attribute on the index.
## listbuild.py
class SceneGraphModel(QtCore.QAbstractItemModel):
NodeRole = QtCore.Qt.UserRole
...
def itemFromIndex( self, index ):
return index.data(self.NodeRole).toPyObject() if index.isValid()
else self._rootNode
...
def data(self, index, role):
if not index.isValid():
return None
node = index.internalPointer()
if role == QtCore.Qt.DisplayRole or role==QtCore.Qt.EditRole:
if index.column()==0:
return node.name()
else:
return node.typeInfo()
# Handle the NodeRole
elif role == self.NodeRole:
return node
## selectorGUI.py
class Selector( QtGui.QMainWindow ):
...
def remove_Object(self):
# Seems like you wanted just the first column
# so that you can retrieve the Node?
selModel = self.tree.selectionModel()
indices = selModel.selectedRows()
folders = []
shapes = []
for index in indices:
# Modified itemFromIndex will return the Node
# Alternatively, you could just do:
# node = index.data(self._model.NodeRole)
node = self._model.itemFromIndex(index)
print node.name()
Let me know if that is what you were after?
On Wed, Oct 23, 2013 at 7:12 AM, Bay <[email protected]> wrote:
> Hi all,
> a problem I'm having right now with my script is that when my
> gui takes in a series of selections decided by the user, I want to be able
> to select a row/rows from the GUI and remove it. Currently I'm just trying
> to get it to print out the information from the selection but it crashes
> everytime I do so. After some attempts to debug it, I noticed that
> everytime I send the information into the itemFromIndex method in my model
> I'm getting some huge number like 65536 which is the reason it has been
> crashing
>
> Could anyone tell me the likely reason that this may be so? Or
> possible mistakes I've made? Attached are the files.
>
> Thank you
> Gann Boon Bay
>
> --
> 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/934ce0cf-3e97-45fa-be70-1990757b8172%40googlegroups.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
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/CAPGFgA3QmKYt45tgCQqK1imgdnNAZebhsEyEbjV9_37RW-4LdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.