Hello all,

I am writing a UI for a tool I put together a while back and am gathering a 
table view with a list of objects in one column and their parents in the other.

My QtableWidget view is giving me some very strange behaviour when selecting my 
items. The further down the list you get when you select the objects in column 
0 the worse the return results get for example:

My table view looks essentially like this currently:

Root             Master parent
anim_door        parent_car_02
car_test         World
Car_test_01      World
anim_door_left   parent_car_test_02
anim_door_02     parent_car_02
car_test_02      World
Car_test_03      World
anim_door_right  parent_car_test_02


I have a selection changed signal and am trying to get the Root and the parent 
using the following code:

def selectionChanged(self):             
    selectedItems = self.table.selectedItems()

    for selected in selectedItems:
        print selected.text()
        #qIndex = self.table.indexFromItem(selected)
        print"Root: ", self.table.item(selected.row(),selected.row()).text()
        print "Parent: ", self.table.item(1,selected.row()).text()


Everything is working as far as on selection changed goes but the results I am 
getting are very odd. For example if I select row 7 values I will get:
Root: World
Parent: World

If I select row 0 I will get:
Root: anim_door
Parent: car_test

Selection of row 4:
Root: Car_test_01
Parent: Anim_door_left

I am not sure why I am getting these values. Could it have something do do with 
my initialisation or perhaps my selection model?

Selection model:
self.tableModel = self.table.selectionModel()
self.tableModel.selectionChanged.connect(self.selectionChanged)


def initTable(self):
        itemsInScene = pm.ls(dag=True)
        for item in itemsInScene:
                # If the item is question has no attribute it errors hence the 
try except 1
                try:
                        # If isRoot exists then add it to the list
                        if pm.getAttr(item.isRoot):
                                
self.dictOfRoots.update({str(item.nodeName()):str(self.splitName(item, 0))})
                except:
                        pass
        rowNum = 0
        self.table.setRowCount(len(self.dictOfRoots))
        for key in sorted(self.dictOfRoots):
                columnNum = 0
                rootName = QtGui.QTableWidgetItem(str(key))
                rootParent = 
QtGui.QTableWidgetItem(str(self.dictOfRoots.get(key)))
                rootParent.setFlags(QtCore.Qt.ItemIsEnabled)

                if rootParent.text() == rootName.text():
                        rootParent = QtGui.QTableWidgetItem(str("World"))

                self.table.setItem(rowNum, columnNum, rootName)
                self.table.setItem(rowNum, columnNum+1, rootParent)
                rowNum += 1

Any help would be appreciated. Apologies for the lack of code trags, I am  not 
sure where to find them or if this group supports them

Cheers!

Ben

-- 
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/489379a3-3cff-49dd-a2a7-6d1af00291f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to