Jump to content

What's the best way to show up a GUI from my menu entry and interact with a C++ lib in the GUI?


C_Q

Recommended Posts

I got a request to insert an entry into the Windows menu of Houdini, when this menu entry is clicked, it should show a GUI, with some input controls to let user input something as parameters, and a button to call the APIs provided by our own C++ lib. After the button is clicked, the status of the C++ lib should be updated on the GUI.

What I got currently is I customized a MainMenuCommon.xml and inserted my own menu entry under the Windows menu. 

Then I tried defining a dialog using Houdini's UI script and then using the builduicode.exe tool to generate a pair of .c/h file in hoping that I can interact with the C++ lib in the callbacks of the UI elements, but I don't know how to show this UI from my added menu entry. Is this the correct way to do the task, or is there any better ways?

Any suggestions/comments is welcome! 

Thanks!

Link to comment
Share on other sites

I have made it work in this way:

1. define a command in c++, say my_cmd; in the command, open up the dialog I defined
2. install the command in CMDextendLibrary
3. make a .py file to call the command, the py file is quite simple
hou.hscript('my_cmd')
4. execute the .py file in my inserted menu entry

Although it worked, as I still new to Houdini, I'm not sure if this is the recommended way in Houdini, or is there any better ways?
Thanks for any inputs!

Edited by C_Q
Link to comment
Share on other sites

  • 4 weeks later...
On 2/20/2019 at 2:05 AM, Stalkerx777 said:

I've done something similar recently. You've picked the right way - by implementing an HScript command.

The UI part is much simpler to implement with Qt though. 

Hi Alex,

Thank you very much for your response!

For the UI part, if I use Qt, or PySide, how can I communicate with the C++ lib then? Do I have to wrap the C++ lib for Python scripts?

 

Link to comment
Share on other sites

If you're using Qt it would be native c++ application (I assume we are talking about the Framework and not the wrapper library). You could then launch it as standalone Qt Application from your menu.

A guess from my side would be, if your own library is kind of simple, to use the ctypes python module which allows you to directly load a dynamic library into the RAM and use it in your python code. I haven't tested it in anyway and it could be a hassle getting this to work.

Another option is to use e.g boost python which let's your write simple c++ code to wrap your library functions in python code.

 

Link to comment
Share on other sites

On 3/19/2019 at 6:20 AM, Yannci said:

If you're using Qt it would be native c++ application (I assume we are talking about the Framework and not the wrapper library). You could then launch it as standalone Qt Application from your menu.

A guess from my side would be, if your own library is kind of simple, to use the ctypes python module which allows you to directly load a dynamic library into the RAM and use it in your python code. I haven't tested it in anyway and it could be a hassle getting this to work.

Another option is to use e.g boost python which let's your write simple c++ code to wrap your library functions in python code.

 

Thank you Yannci! Your second suggestion is worth trying. The side effect is that as the C++ lib upgrades I will have to update an additional wrapper. But it seems a doable way. 

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