0

I need to add a lot of images(iconTextButton) to a gridLayout.
At this time it takes to long for the user to wait till all images are loaded.

I want to add them while the user can interact with the layout.
How to achieve this kind of dynamic loading?

import maya.cmds as mc
import time

class dynamicLoad():
    def __init__(self):
        #-- Window
        self.window_name = 'win'
        if (mc.window(self.window_name, exists=True)):
                mc.deleteUI(self.window_name)
        self.window = mc.window(self.window_name)

        #-- Layout
        layout = mc.formLayout(w=200)
        self.gridview = mc.gridLayout(
                numberOfColumns=4,
                cellWidthHeight=(50, 50),
                allowEmptyCells=False,
                autoGrow=True,
            )
        mc.showWindow( self.window_name )

        #-- Load buttons
        self.create_buttons()

    def create_buttons(self):
        for i in range(5):
            self.load_button()

    def load_button(self):
        time.sleep(1) #-- Fake loading time
        mc.setParent( self.gridview )
        mc.iconTextButton( style='iconAndTextVertical', label='test')
dynamicLoad()
  • This can be tricky. If I understand it correctly, then your loadButtons display an image and the loading of the image takes so long? I fear with Maya builtin methods and python it can be quite tricky to load the images independently from the main thread. – haggi krey Jun 15 '21 at 13:35
  • That's exactly what I want to do, if its to complicated for Maya then I will build a system that loads a new array of buttons when scrolling. But that can still be annoying for the user I guess... So the 'Threaded' loading would be a better solution :) – Jim de Brouwer Jun 15 '21 at 13:41
  • Why not creating small fast loading icons? – haggi krey Jun 15 '21 at 14:17
  • They are small. 64px per icon. In a early test with ~50 icons it slows down already. And maya doesn’t let me scale up images in the interface. So I can’t use smaller ones. See this question: https://stackoverflow.com/questions/64632275/maya-python-scale-picture – Jim de Brouwer Jun 15 '21 at 16:07
  • 64px icons should be not take long. Even creating 50 icons should not take very long. Maybe it could help to first create the buttons and then show the window. – haggi krey Jun 15 '21 at 19:29
  • I would say you will hit the limitation from maya cmds api. You might be able to do so with PySide and some Threading. Still I agree with Haggi Key, 64px button even if they are 50 should not be really long and put self.create_buttons() before mc.showWindow( self.window_name ) might save some refreshing time – DrWeeny Jun 22 '21 at 14:19

0 Answers0