Jump to content

Button's callback script


Div

Recommended Posts

Hi,

I create by python script a node and few parms on it. Then the script creates a button that should be send back the parms values in order to process them, but I can't find a way to set up an "onpress" event to it. In the Help i only see examples and functions for digital asset, hdaModule(), to call functions from the embedded module in the asset, but this doesn't work for me, as the "GUI" (a floating parameter pane) and the button are created by a python script. I create the button using hou.ButtonParmTemplate(), and at it to my node using hou.node.addSpareParmTuple(). How can I set some kind of onPress() event on my button ?

Or is there a way to set the callback script for my button, i know it can be done using "editing parameter interface" but how about doing it by scripting ?

Thanks a lot.

Edited by Div
Link to comment
Share on other sites

You can add a callback to a parameter by setting specific tags on a ParmTemplate by using the setTags() function:

my_button = hou.ButtonParmTemplate("parm", "Label")
my_button.setTags({"script_callback": "print hou.pwd()", "script_callback_language": "python"})

Link to comment
Share on other sites

Thanks a lot Graham, you're definitely saving my hairs these days.

I've got now another problem : I need to make the button call a function which will be a export one ( writing files etc), the problem is where can i store this function ? I thought to set the button's callback function to 'hou.session.myFunction()' and to store myFunction() in the hou.session module, but i'm stuck now on the way to add by scripting the function to the module.

Edited by Div
Link to comment
Share on other sites

White using the hou.session module is a viable option, why not just keep your function in the same python module you use to create everything?

my_button.setTags({"script_callback": "import mymodule; mymodule.myfunction()", "script_callback_language": "python"})

Link to comment
Share on other sites

Because actually I didn't use any module, the shelf tool contain all the script. But you're right, I just have to create a module and import it to be able to use it both in the shelf tool and in my button's callback..... The only problem that appears to me is that to install my tool, the user will have to put 2 files in their respective directories (python module and shelf toolbar) instead of just putting the .shelf file in the toolbar directory, but that's not really a problem... I'll go for you solution, thanks again :D

Edited by Div
Link to comment
Share on other sites

  • 3 years later...

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...