def refreshWidget(self, filePath, xmlTree, displayWidget, fileType):saveState = self.saveWidgetState(displayWidget)config.uiViewCleared = TruedisplayWidget.clear()config.uiViewCleared = Falseself.xmlI_O.setUpTree(filePath, xmlTree, displayWidget, fileType)self.loadWidgetState(displayWidget, saveState)def saveWidgetState(self, displayWidget):print displayWidget.selectionModel()expandedIndexes = {}it = QtGui.QTreeWidgetItemIterator(displayWidget)while it.value():itemIndex = displayWidget.indexFromItem(it.value(), 0)expandedItem = displayWidget.isItemExpanded(it.value())expandedIndexes.update({itemIndex: expandedItem})it += 1return expandedIndexesdef loadWidgetState(self, displayWidget, expandedIndexes):it = QtGui.QTreeWidgetItemIterator(displayWidget)while it.value():toExpand = [i for i in expandedIndexes if i == displayWidget.indexFromItem(it.value(),0)]print "toExpand", toExpandshouldExpand = expandedIndexes.get(toExpand[0])if shouldExpand == True:if not displayWidget.isItemExpanded(it.value()):print "to expand", it.value().text(0)displayWidget.expandItem(it.value())it += 1
Without fully understanding what you're up to, you may be better off with a QTreeView and QAbstractItemModel. The model would keep track of hierarchy, and your view simply represent it. Thus if you refresh the view, the data remains the same and if you change the data, the view updates accordingly.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/SR3v1N1zYuc/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAFRtmOD_M7Myk_4LXkgGn-QWtum53FjsAYQQVMg_ii5y1_eJvQ%40mail.gmail.com.
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/CAM2ybkUwuA5Z00taxccfLUnZaUeKBgjRbdqKpu-%2BGaNE7TDWLA%40mail.gmail.com.
Switching to a view/model is not going to change the outcome of the current approach. Clearing the data is still clearing the data. QTreeWidget is a subclass of QTreeView with a built in model. You could use QPersistentModelIndex, and get the model from the widget with model(), but if you clear it, then the index will invalidate anyways.
There are two approaches you could take. One would be to change how you handle updates to data and not respond by clearing the whole model, but rather to update data for what has actually changed, and add and remove items. It would be the same with a view/model, except you would be handling the changes from the model instead of the widget. Then persistent model indexes would also work.
Or you could continue dumping and rebuilding every time, but store some kind of unique reference as data on each item so that you can save it before clearing, and check for it when you restore. Maybe some kind of xml path. If there is no unique type of identifier that you can associate with each item in reference to the xml, then you probably don't have a choice but to be more granular with how you manage the changes to your data.
Justin
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4EF72B65-6EE8-4D48-9BAE-B7CF2644F877%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3K0eHy95GbUb_utvKCxiNyGOyjbbLM5GLNgR798-tynw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/51B61068-5567-47CE-BB5E-13EA899DEA54%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkXE9mJKTDeu9VAe4eE%2Bb%2BwtPV8KTL4sz6SFWpY%2BV6K-7w%40mail.gmail.com.