Trying to get into the Qt wagon

55 views
Skip to first unread message

Carlos Rico

unread,
Sep 10, 2018, 2:59:13 PM9/10/18
to python_in...@googlegroups.com
Hi guys, the thing is that as a starting project I would like to recreate a MEL tool I made with Python and PySide2. It is just a window that has buttons to open tools, that's all (you can see it in the video attached)

After googling here and there, getting some code from here and there as well and learning some of the basics I found myself trying to get something working but I feel like I am not on the right path.

And that is where you come into play guys. I just need some advice and guidance to focus in the task at hand instead of trying to rush over much documentation, if you will. I do not ask for code, just want to know where to invest my time.

The tool I want to create with PySide2 has to be able to read a json where the button's data is stored (title, command, tooltip, syntax(MEL/Python), ...)

I started getting info here and there and I got where you see in the Video(by the way the buttons work and open the tools).This is already reading the data from a json file. Collapsable "frameLayouts" from a snippet I came across, the famous I guess flowlayout PySide2 example, using a QCompleter in the filter field (does not filter anything for now), well, what you see in the video. So my question is, and sorry for the long post, what do I need to achive my goal?

Do I need a QListView, QListWidget, QItemDelegate, QCompleter? maybe there is something already created that may serve me as a starting point, I do not know, or maybe I need something else I do not know yet. Do I need to sub-class my own widgets? Do I need to use the model/view thingy? As always I am sure this can be done in many ways. I just need the easier one :)

I'll keep digging, It is just that sometimes you have to realize that the wheel was already invented.

Thanks in advance. And sorry if this is very vague and you need more information.

Carlos Rico Adega
-------------------------------------
LinkedIn
carlos....@gmail.com
ToolLibrary_demo.mp4

Justin Israel

unread,
Sep 10, 2018, 6:01:11 PM9/10/18
to python_in...@googlegroups.com
On Tue, Sep 11, 2018 at 6:59 AM Carlos Rico <carlos....@gmail.com> wrote:
Hi guys, the thing is that as a starting project I would like to recreate a MEL tool I made with Python and PySide2. It is just a window that has buttons to open tools, that's all (you can see it in the video attached)

After googling here and there, getting some code from here and there as well and learning some of the basics I found myself trying to get something working but I feel like I am not on the right path.

And that is where you come into play guys. I just need some advice and guidance to focus in the task at hand instead of trying to rush over much documentation, if you will. I do not ask for code, just want to know where to invest my time.

The tool I want to create with PySide2 has to be able to read a json where the button's data is stored (title, command, tooltip, syntax(MEL/Python), ...)

I started getting info here and there and I got where you see in the Video(by the way the buttons work and open the tools).This is already reading the data from a json file. Collapsable "frameLayouts" from a snippet I came across, the famous I guess flowlayout PySide2 example, using a QCompleter in the filter field (does not filter anything for now), well, what you see in the video. So my question is, and sorry for the long post, what do I need to achive my goal?

Do I need a QListView, QListWidget, QItemDelegate, QCompleter? maybe there is something already created that may serve me as a starting point, I do not know, or maybe I need something else I do not know yet. Do I need to sub-class my own widgets? Do I need to use the model/view thingy? As always I am sure this can be done in many ways. I just need the easier one :)


This is pretty vague and requires studying your video to understand the nature of your question. It would be great if you could directly outline a single specific goal, what you have so far, and what you want it to do. 

You have listed some of the building blocks needed for creating a list that can be filtered by text. You would also need a QSortFilterProxyModel between your model and view, to be driven by the state of your filter box. 
 
I'll keep digging, It is just that sometimes you have to realize that the wheel was already invented.

Thanks in advance. And sorry if this is very vague and you need more information.

Carlos Rico Adega
-------------------------------------
LinkedIn
carlos....@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/CAFzJ14VDu0V--%3DGcP9FYbmEh%2Br8zhsau9xce9_KCCYt8kEebbA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Carlos Rico

unread,
Sep 11, 2018, 3:34:14 PM9/11/18
to python_in...@googlegroups.com
Hi, thanks your insight on the task Justin and for the quick response. I will summarize what I would like the tool to be able to do.

1. Read the data for the buttons from an external file (json, yaml, ...) This data would contain the category of the tool, the label, the command to run, whether this command is MEL or python code to know how to run it, tooltip, context menus where needed. I guess a simple JSON might do the job.

2. Sort categories alphabetically and sort the buttons within each category (animation, rigging, ...)

3. Filter the buttons shown via a the QLineEdit. This QLineEdit has to provide autocompletion based on the data. Right click context menu with the recent filters used. I am using a QCompleter and getting the word list from the json file (tool labels) .

4. Adding, editing and removing tools. This is another UI to manage the data.

5. Collapsable categories as shown in the video. (snippet I found)

I am a bit worried about performance, that is one of the reasons I want to convert the MEL code to Python and PySide2. The thing is that there are already 1127 buttons and I really do not know how the python version would perform. Would it be fast?

I guess I need the ModelView approach. I'll keep reading the docs. I'll come back again to the forum when I have concrete questions.

Thank you.
Cheers!


Carlos Rico Adega
-------------------------------------
LinkedIn
carlos....@gmail.com

Justin Israel

unread,
Sep 11, 2018, 3:51:52 PM9/11/18
to python_in...@googlegroups.com


On Wed, Sep 12, 2018, 7:34 AM Carlos Rico <carlos....@gmail.com> wrote:
Hi, thanks your insight on the task Justin and for the quick response. I will summarize what I would like the tool to be able to do.

1. Read the data for the buttons from an external file (json, yaml, ...) This data would contain the category of the tool, the label, the command to run, whether this command is MEL or python code to know how to run it, tooltip, context menus where needed. I guess a simple JSON might do the job.

2. Sort categories alphabetically and sort the buttons within each category (animation, rigging, ...)

Your options are to either add the items to the model pre-sorted and keep adding new ones in a sorted order, and use Qsortfilterproxymodel only for the filtering. Or to also use Qsortfilterproxymodel also for its custom sort function. 


3. Filter the buttons shown via a the QLineEdit. This QLineEdit has to provide autocompletion based on the data. Right click context menu with the recent filters used. I am using a QCompleter and getting the word list from the json file (tool labels) .

4. Adding, editing and removing tools. This is another UI to manage the data.

5. Collapsable categories as shown in the video. (snippet I found)

I am a bit worried about performance, that is one of the reasons I want to convert the MEL code to Python and PySide2. The thing is that there are already 1127 buttons and I really do not know how the python version would perform. Would it be fast?

If you use a model/view approach, it should work fine since those 1127 buttons aren't all going to be triggering paint events at the same time. Only the visible widgets in the view will trigger any activity. Even though the bindings are in Python, effectively you are still creating C++ objects. The slowness comes from python code that gets executed frequently such as custom events or data logic. Or constantly constructing, destroying, or accessing python objects. 

Reply all
Reply to author
Forward
0 new messages