Re: [Maya-Python] Customized display of files/folders in a QTreeView that is using QFileSystemModel.

2019-06-14 Thread Justin Israel
If your model is read-only, then it will be a lot less work and you don't
need to implement insertRow().
I can try to put together a simplified example of my own implementation
when I get back to work. It's a grouping proxy model that is meant to take
a table model and create a tree model with a virtual parent item for a
configured attribute of the items. As an example, one could say "group on
'category'" and then you would go from this:

ford, car
mazda, car
apple, food
banana, food

to this:

car
ford
mazda
food
apple
banana

I tried a quick search to see if there are existing examples, and maybe
these will give you some more info:
https://github.com/mpaperno/maxLibQt/blob/master/src/itemmodels/GroupedItemsProxyModel.cpp
https://sourceforge.net/p/qadvanceditemviews/code/ci/default/tree/qaivlib/qgroupingproxymodel.cpp

Justin


On Fri, Jun 14, 2019 at 10:25 PM HarshadB  wrote:

> Hi Justin, Thank you for the insight. It helped to know that
> theoretically I am going in the right direction.
> I tried quite a bit of things these last few days, a bit of a struggle
> since I am a bit new to the syntax and structure of Qt.
>
> At this point, I am stuck on adding an extra row using the
> QSortFilterProxyModel.
> I have attached the example code I am using to work on: Example
> 
>
> If I can get a successful empty row inserted, that would be a good start.
>
> - Harshad
> On Monday, June 10, 2019 at 8:11:48 PM UTC+9, Justin Israel wrote:
>>
>>
>>
>> On Mon, Jun 10, 2019, 8:22 PM HarshadB  wrote:
>>
>>> Need some help and direction in understanding QSortFilterProxyModel. I
>>> am creating a tool in Maya using PySide2 (Qt.py).
>>>
>>> *GOAL:*
>>> I have already built a filebrowser QTreeView with a QFileSystemModel.
>>> Folders and files are both displayed.
>>> I have a filter for files with a certain extension on the source model.
>>> (Maybe move this filter to proxy model..)
>>>
>>> The files are in this format:
>>>
>>> name.0001.ext
>>> name.0002.ext
>>> name.0003.ext
>>>
>>>
>>> What I want to do is, show the versions of a file in a treeView like
>>> this:
>>>
>>> - name (not an actual folder, virtual row I want to insert)
>>> --name.0001.ext
>>> --name.0002.ext
>>> --name.0003.ext
>>>
>>>
>>> So the intention is that QTreeView will always display the files with
>>> the names w/o versions. The user has to expand the name to see the version
>>> files.
>>> Further on I will implement something that imports the latest file when
>>> the "name" is operated on.
>>>
>>> *HELP:*
>>> I believe I can subclass QSortFilterProxyModel to do this. Is this right?
>>> Can someone enlighten me on how to go about it?
>>>
>>> Another options is to subclass QAbstractItemModel. I have yet to look
>>> deep into this.
>>> I would prefer QSortFilterProxyModel (based on what I have read). But
>>> suggestions are welcome.
>>>
>>> I will attach some code if required. I will have to extract it from my
>>> tool code.
>>> Thank you.
>>>
>>
>> QSortFilterProxyModel is likely where you want to start subclassing. The
>> other option is a QAbstractProxyModel, but that will require you to
>> implement more of the methods, whereas the former is already usable.
>> I've got use cases similar to what you subscribe, but it is a private
>> code base so unfortunately I have nothing to share. But I can try to offer
>> some high level advise for now and maybe some more detailed information
>> once I get a chance to look over my code again. But basically you have to
>> implement things like rowCount() to create a virtual new parent tier
>> which is your name without the versions. And stuff like hadChildren(),
>> index(), mapToSource(), and mapFromSource(), so that you can tell the
>> view that your virtual names have children and how to map them to the real
>> source index in the source model.
>> The nice thing about using proxy models is that your source model remains
>> the same and you can have multiple views to the same source with different
>> proxies in between that transform the data in a non-destructive way.
>>
>> - 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_maya+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/df3e4b4a-69e1-432e-9fd9-0164463d8d57%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 

Re: [Maya-Python] Getting RuntimeError when trying to use confirmDialog

2019-06-14 Thread kiteh
Tried with the use of QMessageBox, and it is working fine.
Initially I had thought this would work as I am calling the confirmDialog 
in frameEditied() (being first) and importRef() would be called on later..

Adding on, I tried to create the same prompt_dialog() in script editor, 
wrote 2 lines of code, each calling this method with different strings, and 
was given 2 confirm dialogs and hence the confusion. 

-- 
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/32011f2f-336a-47b1-b43f-75f9d9f274c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Customized display of files/folders in a QTreeView that is using QFileSystemModel.

2019-06-14 Thread HarshadB
Hi Justin, Thank you for the insight. It helped to know that 
theoretically I am going in the right direction.
I tried quite a bit of things these last few days, a bit of a struggle 
since I am a bit new to the syntax and structure of Qt.

At this point, I am stuck on adding an extra row using the 
QSortFilterProxyModel.
I have attached the example code I am using to work on: Example 


If I can get a successful empty row inserted, that would be a good start.

- Harshad
On Monday, June 10, 2019 at 8:11:48 PM UTC+9, Justin Israel wrote:
>
>
>
> On Mon, Jun 10, 2019, 8:22 PM HarshadB > 
> wrote:
>
>> Need some help and direction in understanding QSortFilterProxyModel. I am 
>> creating a tool in Maya using PySide2 (Qt.py).
>>
>> *GOAL:*
>> I have already built a filebrowser QTreeView with a QFileSystemModel. 
>> Folders and files are both displayed.
>> I have a filter for files with a certain extension on the source model. 
>> (Maybe move this filter to proxy model..)
>>
>> The files are in this format:
>>
>> name.0001.ext
>> name.0002.ext
>> name.0003.ext
>>
>>
>> What I want to do is, show the versions of a file in a treeView like this:
>>
>> - name (not an actual folder, virtual row I want to insert)
>> --name.0001.ext
>> --name.0002.ext
>> --name.0003.ext
>>
>>
>> So the intention is that QTreeView will always display the files with the 
>> names w/o versions. The user has to expand the name to see the version 
>> files.
>> Further on I will implement something that imports the latest file when 
>> the "name" is operated on.
>>
>> *HELP:*
>> I believe I can subclass QSortFilterProxyModel to do this. Is this right?
>> Can someone enlighten me on how to go about it?
>>
>> Another options is to subclass QAbstractItemModel. I have yet to look 
>> deep into this.
>> I would prefer QSortFilterProxyModel (based on what I have read). But 
>> suggestions are welcome.
>>
>> I will attach some code if required. I will have to extract it from my 
>> tool code. 
>> Thank you.
>>
>
> QSortFilterProxyModel is likely where you want to start subclassing. The 
> other option is a QAbstractProxyModel, but that will require you to 
> implement more of the methods, whereas the former is already usable. 
> I've got use cases similar to what you subscribe, but it is a private code 
> base so unfortunately I have nothing to share. But I can try to offer some 
> high level advise for now and maybe some more detailed information once I 
> get a chance to look over my code again. But basically you have to 
> implement things like rowCount() to create a virtual new parent tier which 
> is your name without the versions. And stuff like hadChildren(), index(), 
> mapToSource(), and mapFromSource(), so that you can tell the view that your 
> virtual names have children and how to map them to the real source index in 
> the source model. 
> The nice thing about using proxy models is that your source model remains 
> the same and you can have multiple views to the same source with different 
> proxies in between that transform the data in a non-destructive way. 
>
> - 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_maya+unsubscr...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/python_inside_maya/df3e4b4a-69e1-432e-9fd9-0164463d8d57%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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/4afb7027-7593-4c92-aecb-60285c47eec4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.