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?
-Harshad
On Tuesday, June 16, 2015 at 4:16:35 AM UTC+5:30, Justin Israel wrote:
>
> Hey,
>
> I'm not clear on why you have to keep your own independent newList of all
> the QListWidgetItems. Why not just pull them from the list widget as you do
> for the old ones? Then you can be sure you aren't holding on to stale
> objects when you want to access the text values.
>
> Justin
>
>
> On Tue, Jun 16, 2015 at 10:33 AM crazygamer <[email protected]
> <javascript:>> wrote:
>
>> Hi,
>> Am writing a renaming tool for maya. Its almost done but Im stuck on a
>> issue.
>>
>> I'm following Rob's book "Practical Maya Programming with Python". So I'm
>> keeping the Qt(PySide) code seperate from my maya code.
>>
>> Here's a quick laydown:
>>
>> #The window contains two list widgets (old names, new names) and two
>> buttons (load objects, rename objects). Old names list is not editable.
>> # The UI is made with Qt Designer and converted to python using pysideuic.
>>
>> # The way its supposed to work:
>> 1. Click "Load Objects" button to load selected objects(names) on both
>> list widgets.
>> 2. User edits the text on the "new names" list widget.
>> 3. Click the "Rename Objects" button to rename objects on the "old names"
>> widget with the naming from the "new names" widget.
>>
>> It works the first time. After that, I get this error:
>>
>> RuntimeError: Internal C++ object (PySide.QtGui.QListWidgetItem) already
>> deleted.
>>
>>
>> I create the QListWidgetItem in the loop as I want the "new names" list
>> to be editable. I can
>> understand qt/python clearing it as garbage collection. How can I create
>> the QListWidgetItem properly so it doesn't get cleared on refresh.
>>
>> Can someone help me understand and write this efficiently so I can keep
>> the list editable and
>> refresh/recreate the QListWidgetItem on each object load. What I've
>> written is quite crude.
>>
>> The ui file(converted to python) is attached with this post.
>> Here's the extracted code: (It also contains a test function so you can
>> test-run it with mayapy on a console)
>> http://pastebin.ubuntu.com/11722053/
>>
>> --
>> 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/0d82af77-2068-4572-bef3-d20fecade05b%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/python_inside_maya/0d82af77-2068-4572-bef3-d20fecade05b%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/4814baa4-e9cb-4eb6-9ab5-b5e31dff8d1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.