self.dirModel.setNameFilters(['*.xml', '*.txt', '*.mel'])
self.dirModel.setNameFilterDisables(False)
--
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/f2730d5e-9cdf-4041-b9dd-8c2bfa984efd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Great example, Justin.
I was about to post this, which is a more complex example.
>>> proxy = ProxyModel(original_model)
>>> proxy.add_exclusion("hasCompatible", False)
Where hasCompatible is a “role” and False is the value of this role used to determine whether or not to exclude it.
It also does inclusion, as in, only matching items are included. Combined they enable excluding within a subset of included items.
>>> proxy.add_inclusion("itemType", "plugin")
It’s used like this.
Include

Exclude

Hope it helps!
@Marcus...Tell me, below code is going in right direction or not ??
class customProxyModel(QtGui.QSortFilterProxyModel): def __init__(self, parent=None): super(customProxyModel, self).__init__(parent) self._includes = {'fileName':[], 'fileType':[], 'fileSize':[], 'fileDate':[]} self._excludes = {'fileName':[], 'fileType':[], 'fileSize':[], 'fileDate':[]}
def add_exclusion(self, role, value): self._add_rule(self._excludes, role, value) def remove_exclusion(self, role, value=None): self._remove_rule(self._excludes, role, value) def set_exclusion(self, rules): self._set_rules(self._excludes, rules) def clear_exclusion(self): self._clear_group(self._excludes)
def add_inclusion(self, role, value): self._add_rule(self._includes, role, value) def add_inclusion(self, role, value): self._remove_rule(self._includes, role, value) def set_inclusion(self, rules): self._set_rules(self._includes, rules) def clear_inclusion(self): self._clear_group(self._includes)
def _add_rule(self, group, role, value): group[role].append(value) self.invalidate() def _remove_rule(self, group, role, value): group[role].remove(value) self.invalidate() def _set_rules(self, group, rules): group.clear() for rule in rules: self._add_rule(group, *rule) self.invalidate() def _clear_group(self, group): group.clear() self.invalidate()
def filterAcceptsRow(self, srcRow, srcParent): idx = self.sourceModel().index(srcRow, 0, srcParent) filePath = self.sourceModel().filePath(idx) fileDate = self.sourceModel().fileInfo(idx).lastModified() fileSize = self.sourceModel().fileInfo(idx).size() fileLongName = idx.data()
for exc in self._excludes: if fileLongName.endswith(exc): return False
for fileKey, fileValue in self._excludes.items(): for value in fileValue: if fileKey == 'fileName': if fileLongName.endswith(fileLongName.endswith(value)): return False elif fileKey == 'fileType': if fileLongName.endswith(fileLongName.endswith(value)): return False elif fileKey == 'fileSize': if fileLongName.endswith(fileLongName.endswith(value)): return False elif fileKey == 'fileDate': if fileLongName.endswith(fileLongName.endswith(value)): return False
for fileKey, fileValue in self._includes.items(): for value in fileValue: if fileKey == 'fileName': if fileLongName.endswith(fileLongName.endswith(value)): return True elif fileKey == 'fileType': if fileLongName.endswith(fileLongName.endswith(value)): return True elif fileKey == 'fileSize': if fileLongName.endswith(fileLongName.endswith(value)): return True elif fileKey == 'fileDate': if fileLongName.endswith(fileLongName.endswith(value)): return True return Truename = idx.data()
for exc in self._excludes:
if name.endswith(exc):
return FalsefileType = self.sourceModel().fileInfo(idx).suffix()
for exc in self._excludes:
if exc == fileType: return False
Sure you can do it like that. It will work fine for testing extensions in 99% of the cases. The 1% edge case is where you for some reason ever put another proxy model in between this one and the source model and this code breaks because you are depending on the source model being a specific derived type with a method fileInfo().
--
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/a56baa41-72fc-4be7-9cb6-6c38d0e175dc%40googlegroups.com.
fileType = self.sourceModel().fileInfo(idx).suffix()
return fileType not in self._excludes
Sure you can do it like that. It will work fine for testing extensions in 99% of the cases. The 1% edge case is where you for some reason ever put another proxy model in between this one and the source model and this code breaks because you are depending on the source model being a specific derived type with a method fileInfo().
On Fri, Dec 2, 2016, 7:01 PM Ruchit Bhatt <ruchitinn...@gmail.com> wrote:
@JustinInstead ofname = idx.data()
for exc in self._excludes:
if name.endswith(exc):
return FalseBelow one is simple & perfect in my case, wht do you think ??fileType = self.sourceModel().fileInfo(idx).suffix()
for exc in self._excludes:
if exc == fileType:return False
--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/a56baa41-72fc-4be7-9cb6-6c38d0e175dc%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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1F_ghRk9txA8gtSjyZ-6jaVdkjuggCjDQrEin2iOVKiw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
An alternative to fetching the object and accessing properties of this object, you could use the “role” functionality of the model.
return idx.data(FileTypeRole) not in self._excludes
Each index carries a method called data which is shorthand for model.data(index, role). In this case, this would call data on the proxy model, where you either forward it to the original model, or handle it explicitly.
FileTypeRole = QtCore.Qt.UserRole + 1
def data(self, index, role):
if role == FileTypeRole:
return ".ma"
The benefit being that you avoid the trap Justin mentioned of some day switching out the underlying object, or wanting to use the same proxy in other programs where exact objects differ. In this case, you may redirect differences in the model.
Might I also suggest more pythonic and performant code:fileType = self.sourceModel().fileInfo(idx).suffix()
returnfileType not inself._excludes
On Fri, Dec 2, 2016 at 4:21 PM, Justin Israel <justin...@gmail.com> wrote:
Sure you can do it like that. It will work fine for testing extensions in 99% of the cases. The 1% edge case is where you for some reason ever put another proxy model in between this one and the source model and this code breaks because you are depending on the source model being a specific derived type with a method fileInfo().
On Fri, Dec 2, 2016, 7:01 PM Ruchit Bhatt <ruchitinn...@gmail.com> wrote:
@JustinInstead ofname = idx.data()
for exc in self._excludes:
if name.endswith(exc):
return FalseBelow one is simple & perfect in my case, wht do you think ??fileType = self.sourceModel().fileInfo(idx).suffix()
for exc in self._excludes:
if exc == fileType:return False
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/a56baa41-72fc-4be7-9cb6-6c38d0e175dc%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_maya+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1F_ghRk9txA8gtSjyZ-6jaVdkjuggCjDQrEin2iOVKiw%40mail.gmail.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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMTxE2hJMgiNg_9ae9SqDxd9GxYwH7gCVGV%2BcEL%3Dx%3Dao%3DQ%40mail.gmail.com.
@Marcus & Justin
--
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/98c937f3-4cac-463e-a62e-bb37999e5d72%40googlegroups.com.
print self.proxyModel.rowCount() #works fine but its not recursive print self.proxyModel.rowCount(parent=QtCore.QModelIndex()) #Gives errorI triedprint self.proxyModel.rowCount() #works fine but its not recursive
model = tree.model()
root = model.index(0,0)
for row in xrange(model.rowCount(root)):
print model.index(row, 0, root).data()
andprint self.proxyModel.rowCount(parent=QtCore.QModelIndex()) #Gives error
root = model.index(0,0)
how you are able to use parent outside class ??
--
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/cb3a247a-df03-4a17-826a-987085855d3e%40googlegroups.com.
On Tue, Dec 6, 2016 at 8:31 PM Ruchit Bhatt <ruchitinn...@gmail.com> wrote:I triedprint self.proxyModel.rowCount() #works fine but its not recursiveI'm not sure what you expect the results to be. What kind of recursive value do you expect? A total of all row count of all hierarchies in the tree?Model.rowCount() gives you the row count of the root of the model, which if you are getting 1 means an invisible root item.If you wanted to print the first tier of visible items, it would be something like this:model = tree.model() root = model.index(0,0) for row in xrange(model.rowCount(root)): print model.index(row, 0, root).data()
for row in xrange(model.rowCount(root)):
print root.child(row, 0).data()
def fileListFn(self, srcRow, srcParent):
idx = self.sourceModel().index(srcRow, 0, srcParent)
filePath = self.sourceModel().filePath(idx)
if os.path.isfile(filePath):
print filePath--
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/f6a21762-a6f1-4715-b920-34c51c502f73%40googlegroups.com.