An alternative to fetching the object and accessing properties of this
object, you could use the “role” functionality of the model.

   - Reference <https://doc.qt.io/qt-4.8/model-view-programming.html>
   (search for “role”)

return idx.data(FileTypeRole) not in self._excludes

Each index carries a method called data which is shorthand for
model.data(index,
role) <https://doc.qt.io/qt-5/qabstractitemmodel.html#data>. 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.
​

On 2 December 2016 at 08:42, Alok Gandhi <alok.gandhi2...@gmail.com> wrote:

> Might I also suggest more pythonic and performant code:
> fileType = self.sourceModel().fileInfo(idx).suffix()
> return fileType not in self._excludes
>
> On Fri, Dec 2, 2016 at 4:21 PM, Justin Israel <justinisr...@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 <ruchitinnewfush...@gmail.com>
>> wrote:
>>
>>> @Justin
>>>
>>> Instead of
>>> name = idx.data()
>>>
>>> for exc in self._excludes:
>>>     if name.endswith(exc):
>>>         return False
>>>
>>> Below 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/python_inside_maya/a56baa41-72fc-4be7-9cb6-6c38d0e175dc%
>>> 40googlegroups.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/a56baa41-72fc-4be7-9cb6-6c38d0e175dc%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 python_inside_maya+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/python_inside_maya/CAPGFgA1F_ghRk9txA8gtSjyZ-6jaVdkjuggC
>> jDQrEin2iOVKiw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1F_ghRk9txA8gtSjyZ-6jaVdkjuggCjDQrEin2iOVKiw%40mail.gmail.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 python_inside_maya+unsubscr...@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
> <https://groups.google.com/d/msgid/python_inside_maya/CAPaTLMTxE2hJMgiNg_9ae9SqDxd9GxYwH7gCVGV%2BcEL%3Dx%3Dao%3DQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Marcus Ottosson*
konstrukt...@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_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAXNvypxE5%2B7_VQXNimteD_3OuWq7d0ciz5gETj7Wv5FQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to