Technicallywhat you have commented out in your Node.setName() could work
just fine if you want manage your maya calls directly from the Node objects:

class Node(object):
   ....
   def setName(self, name):
        print self._name, name
        cmds.rename(self._name, name)
        self._name=name


To me, it seems appropriate to do it from the model/items since what you
are modeling is the SceneGraph and you have the most context between the
model and the data you are representing. The alternative is to emit the
signals from your model and handle them in some other slot:

def setData(self, index, value, role=QtCore.Qt.EditRole):
    if index.isValid():

        if role ==QtCore.Qt.EditRole:

            node = index.internalPointer()
            oldName = node.name()
            node.setName(value)

            self.dataChanged.emit(index, index)
            self.nameChanged.emit(node, oldName, value)

            return True

    return False


# some other function or method as a slot
def nodeNameChanged(node, oldName, newName):
print node, "name was changed from", oldName, "to", newName
cmds.rename(oldName, newName)

myModel = SceneGraphModel()
myModel.nameChanged.connect(nodeNameChanged)


It might be much cleaner though to go with the first and keep all the
SceneGraph <=> Model logic together, so that you can have multiple views
and not have to duplicate any logic.


On Mon, Oct 14, 2013 at 8:53 PM, Bay <gannboonb...@gmail.com> wrote:

> currently I'm doing the PyQT Model View Programming Tutorial by Yasin
> Uludag. As I'm new to PyQT I'm still unfamilar with how to get information
> out of pyqt and back into Maya again. Currently I'm doing the Treeview part
> of the tutorial trying to figure out how to interpret a name change in the
> menu into an actual rename for the object.This is the setData method for
> the model class
>
> def setData(self, index, value, role=QtCore.Qt.EditRole):
>
>         if index.isValid():
>
>             if role ==QtCore.Qt.EditRole:
>
>                 node = index.internalPointer()
>                 node.setName(value)
>
>
>                 return True
>         return False
>
> and this is the setName method
>
> def name(self):
>     return self._name
>
> How do I convert the value in node.setName(value) into something that Maya
> could read so that I could use it for a cmds.rename? Attached is also the
> full script in case that information is needed.
>
> Thanks for any suggestions given.
>
> --
> 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_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/e2f648f4-8910-4309-8d64-6d31f9c09bfe%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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3nxmUSfgirxYy3pMu7%2BDL99h2pSpb37j-E0Vud7LLGjA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to