RuntimeError: Internal C++ object (PySide.QtGui.QListWidgetItem) already deleted.
--
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/0d82af77-2068-4572-bef3-d20fecade05b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
for obj in load_objs: obj = QtGui.QListWidgetItem(obj, parent=self.ui.preview_new_names_list) obj.setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.ui.preview_new_names_list.addItem(obj) self.newList.append(obj)
for index in xrange(self.ui.preview_new_names_list.count()): item = self.ui.preview_new_names_list.item(index) item.setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable)
loaded_objs = []
def load_objs(): selected_objs = pmc.selected() objs_to_process = [] for obj in selected_objs: obj_name = _get_short_name(obj) objs_to_process.append(obj_name) loaded_objs.append(obj) controller.objList.emit(objs_to_process)
def custom_rename(old_list, new_list): for i in range(len(old_list)): obj = pmc.PyNode(loaded_objs[i]) _do_rename(obj, new_list[i])
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Thanks Justin for the quick reply.I wanted the QListWidgetItems to be editable. Didn't know how to use the "setFlags" on the item, so I put each object as a QListWidgetItem, made it editable and added to the new list. I realize now it was not a good idea. Found another way to do that.I have replaced this code:
for obj in load_objs:obj = QtGui.QListWidgetItem(obj, parent=self.ui.preview_new_names_list)obj.setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable |QtCore.Qt.ItemIsEnabled)self.ui.preview_new_names_list.addItem(obj)self.newList.append(obj)With this:
for index in xrange(self.ui.preview_new_names_list.count()):item = self.ui.preview_new_names_list.item(index)item.setFlags(QtCore.Qt.ItemIsEditable |QtCore.Qt.ItemIsEnabled |QtCore.Qt.ItemIsSelectable)It works now. No more stale objects.
There was another train of thought while implementing this. I was trying to find out a way to store object info instead of just the text. I'm using PyMel. I want to retain the actual object while adding the name to the lists. (To avoid duplicate named objects)Is there a way I can handle duplicate named objects?Can i store the actual object(in this case a pymel transform node) with the list and give it a title?Currently I have it working by making another list which holds the actual objects when the objects are loaded in the lists by the "Load Objects" button.
loaded_objs = []def load_objs():selected_objs = pmc.selected()objs_to_process = []for obj in selected_objs:obj_name = _get_short_name(obj)objs_to_process.append(obj_name)loaded_objs.append(obj)controller.objList.emit(objs_to_process)def custom_rename(old_list, new_list):for i in range(len(old_list)):obj = pmc.PyNode(loaded_objs[i])_do_rename(obj, new_list[i])The short name of the objects get added to the list while the object is in the "loaded_objs" variable.(_do_rename is just a proc i made to rename objects with some error checking)
Is there a better way to do this?
class MayaItem(QtGui.QListWidgetItem):
USER_TYPE = QtGui.QListWidgetItem.UserType + 1
def __init__(self, mayaItem, parent=None):
super(MayaItem, self).__init__(parent, self.USER_TYPE)
self._mayaItem = mayaItem
def data(self, role):
if role == QtCore.Qt.DisplayRole:
return self._mayaItem.name()
return super(MayaItem, self).data(role)
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/0d82af77-2068-4572-bef3-d20fecade05b%40googlegroups.com.
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4814baa4-e9cb-4eb6-9ab5-b5e31dff8d1a%40googlegroups.com.
class CustomItem(QtGui.QListWidgetItem):
USER_TYPE = QtGui.QListWidgetItem.UserType + 1
def __init__(self, customitem, parent=None): super(CustomItem, self).__init__(parent, self.USER_TYPE) self.customItem = customitem
def data(self, role): if role == QtCore.Qt.DisplayRole:
return self.customItem.name() elif role == QtCore.Qt.EditRole: return self.customItem.name() return super(CustomItem, self).data(role)
def setData(self, role, value): if role == QtCore.Qt.EditRole: self.setText(value) print value #self.setData(QtCore.Qt.DisplayRole, value)
def setData(self, role, value): if role == QtCore.Qt.EditRole:
self.customItem.rename(value)
def objs_list(): from pymel.core import createNode #objs = [] objs = [createNode('polyCube'), createNode('polySphere'), createNode('polyCone'), createNode('polyCylinder')] return objs
def load_objs(): controller.objList.emit(objs_list())
--
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/9bb5346f-9fb7-4f86-afb3-e9ee45d3ac2d%40googlegroups.com.
text()/setText() are convenience calls to data()/setData() with the DisplayRole. So when we reimplement data/setData to handle the DisplayRole, we don't then want to call setText(). We want to completely handle storing our value. So I think you are working against yourself a bit in that logic.But because you said that you don't want to directly work on the items, and instead just perform an action when the button is clicked, this makes it even easier. You don't even need the data/setData approach. All you really need to do is let the QListWidgetItem continue doing its own default behavior, but carry the custom item. You can then loop over all items when the button is clicked and do the operation:
That example lets you edit the items in the list. When you click the button, it does the rename on the custom item.
item = self.ui.loaded_objs_list.item(index)No object matches name: <scriptname.CustomItem object at 0x0000002AA0534EC8>
class CustomItem(QtGui.QListWidgetItem):
USER_TYPE = QtGui.QListWidgetItem.UserType + 1
def __init__(self, customitem, parent=None): super(CustomItem, self).__init__(parent, self.USER_TYPE)
self.setItem(customitem)
def setItem(self, customitem): self.setText(customitem.name().split('|')[-1])
item = self.ui.loaded_objs_list.item(index).customItem
class CustomItem(QtGui.QListWidgetItem):
USER_TYPE = QtGui.QListWidgetItem.UserType + 1
def __init__(self, customitem, parent=None): super(CustomItem, self).__init__(parent, self.USER_TYPE) self.customItem = customitem
xx = CustomItem(obj)self.ui.loaded_objs_list.addItem(xx)xy = CustomItem(obj)self.ui.preview_new_names_list.addItem(xy)
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
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/9bb5346f-9fb7-4f86-afb3-e9ee45d3ac2d%40googlegroups.com.
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/30e7ef10-ec61-4bb2-8116-402d8a5c96b2%40googlegroups.com.