I forgot to add a couple code comments that I think would be helpful:

# Break a path like "|root|one|two" into parts and reverse:
# ["|root", "|root|one", "|root|one|two"]
parts = [path.rsplit('|', i)[0] for i in xrange(path.count('|'))]
parts.reverse()

# Get the last name component of the path:
# "|root|one" -> "one"
name = part.rsplit('|', 1)[-1]



On Sat, Sep 15, 2018 at 4:59 PM Justin Israel <justinisr...@gmail.com>
wrote:

> On Sat, Sep 15, 2018 at 10:03 AM kiteh <kiteh.0...@gmail.com> wrote:
>
>> While I am not very adept in using PyQt yet, and this script that I have
>> currently have on hand, is taken from a tool (with edited functions here
>> and there).
>> I am wondering if you could advise, if it will be better for me to
>> re-write the whole thing?
>>
>> Truth be told, as mentioned, that I took the code from somewhere I am not
>> entirely understanding the script very well.
>> Even so, if I am do planning to rewrite where need to have some of the
>> features:
>>
>> * Populates the tree from a given list of strings - example.
>> "|ObjectA|ObjectB|ObjectC|..." such that the hierarchy is almost the same
>> as the ones in the Outliner where you can collapse them
>> * Appends icon towards each item based on their node type
>>
>> Will the above features be better/ easily implement using a QTreeWidget,
>> rather than a QTreeView?
>> (I mention QTreeWidget as there seems to be more information for some
>> other features I wanted, eg. for text/ cell color etc)
>>
>
> There wasn't anything hugely wrong with the existing code that warrants a
> total re-write. I was only pointing out a few adjustments that could be
> made.
> The thing is though, the current implementation that you shared doesn't
> really seem to benefit from having a custom model. It seems like a lot of
> work is being done just to replicate a tree structure on your own, and then
> provide it to the abstract model to serve to a tree view. Using an abstract
> model makes more sense when you already have an existing data structure or
> data source that you want to wrap. For instance, you could store basically
> nothing and show the dag just by doing api queries as needed, when the
> model asks what is at a certain level or under a certain parent. When you
> decide to do an abstract model, you have to correctly handle a bunch of
> method implementations. It can also be beneficial to use a custom model
> when you start hitting performance limitations of the item-based approach.
> Honestly you could just be using either a QTreeWidget, or a QTreeView +
> QStandardItemModel. Especially if you are starting out with Qt. They
> already provide the parent/child items that you are replicating.
> QTreeWidget is meant for a really easy interface to just adding items. If
> you end up needing more fine-grained control then you can do the view/model
> approach. The goal you want to achieve can be done with either one. I
> knocked together a quick example of how you can do this with QTreeWidget:
>
> https://pastebin.com/QPwJ3WYH
>
> It can just as easily be switched to view/model instead. I didn't do the
> part with the icons, but that is just a matter of calling item.setIcon(0,
> theIcon).
> Let me know if you have any questions about this code.
>
> 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/5d51a6af-23da-4c71-9946-bc641dfd0cdb%40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/5d51a6af-23da-4c71-9946-bc641dfd0cdb%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/msgid/python_inside_maya/CAPGFgA0-rDKyj-SM9Nki13OTT%3DKn4zDErvYLzfXtv7oddMVRjQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to