Jump to content

building a parameter menu as a background process


jonp

Recommended Posts

Greetings,

I have a scripted menu parameter that is built from a filtered, sometimes extremely long list of files.  When I select a node with this parameter, the first time I do it there is a very long pause where I cannot do anything in the UI.  Subsequent access is faster as I'm caching the results of the first lookup.  HOWEVER, the first pause is annoying enough.  It would be great if there was a way to build the menu contents as a background process somehow and just have the menu script read from a stored list somewhere that is continuously updated (with a caveat message in the menu saying that the list is still being built).

Any ideas on how to elegantly do this?

 

Cheers,

Jon

Link to comment
Share on other sites

Try threading:

import threading

node = kwargs['node']

if not node.cachedUserData('menu'):
    menu = ['', 'Loading items...\nReturn in 10 seconds...']
    node.setCachedUserData('menu', menu)

    def fetch_menu():
        # Simulate long operation.
        import time
        time.sleep(10)
        menu = ['item1', 'Label 1', 'item2', 'Label 2']

        try:
            node.setCachedUserData('menu', menu)
        except hou.ObjectWasDeleted:
            pass

    t = threading.Thread(target=fetch_menu)
    t.start()

return node.cachedUserData('menu')

To reset, just delete node and undo.

To update menu items automatically, add this under try statement:

parm = kwargs['parm']
group = node.parmTemplateGroup()
template = parm.parmTemplate()
template.setMenuItems(menu[0::2])
template.setMenuLabels(menu[1::2])
group.replace(parm.name(), template)
node.setParmTemplateGroup(group)

slow_menu.hipnc

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...