I have created an ui element with str_builder and assigned a “test” function to the on_clicked_fn parameter. This test function has a simple print to test. But nothing i have tried resulted in any prints. I tried the same function on a checkbox (adding the positional argument it needs) and it printed perfectly. Even when selecting a file using use_folder_picker nothing is printed.
Hi @DiscoFlower8890 - Can you please share the code that you have written? that will help diagnose the issue better.
Hi @rthaker
Here:
#for str_builder
def test_clicking():
print("You clicked the string box") #this print doesn't appear in console no matter what I try.
with ui.HStack(height=20):
dome_texture = str_builder(
label="HDRI texture path",
tooltip="Directory where the HDRI texture is stored. The path must not end in a slash.",
use_folder_picker=True,
item_filter_fn=lambda item: item.is_folder or item.path.endswith('.hdr'),
folder_dialog_title="Select Path",
folder_button_title="Select",
on_clicked_fn=test_clicking
)
#for cb_builder
def test_checkbox(state):
print(f"You clicked the checkbox: {state}") #this on the other hand gets printed perfectly.
with ui.HStack(height=20):
vegitation = ui_utils.cb_builder(label="Other vegitation:", on_clicked_fn=test_checkbox)
That should be enough as other parts of the extension work perfectly.
Hi @DiscoFlower8890 - The str_builder function is used to create a string input field with an optional folder picker button. The on_clicked_fn function is called when the folder picker button is clicked, not when the string input field is clicked or changed.
If you want to run a function when the string input field is changed, you might need to use a different function or method. For example, you might need to use a on_value_changed_fn function if one is available.
Here’s an example of how you might do it:
def test_change(value):
print(f"You changed the string box to: {value}")
with ui.HStack(height=20):
dome_texture = str_builder(
label=“HDRI texture path”,
tooltip=“Directory where the HDRI texture is stored. The path must not end in a slash.”,
use_folder_picker=True,
item_filter_fn=lambda item: item.is_folder or item.path.endswith(‘.hdr’),
folder_dialog_title=“Select Path”,
folder_button_title=“Select”,
on_value_changed_fn=test_change
)
In this code, test_change is called whenever the value of the string box is changed. Note that this is just an example and the actual code might look different depending on the specific functions and methods available in your UI library.
Hi @rthaker
Ah, that explains half the issue. But I’m not getting any prints in console even when pressing the folder picker button. (Neither picking a full path an hitting select nor clicking the button and closing)
Video of me spamming the folder picker button
And it seems str_builder doesnt have on_value_changed_fn parameter:
2023-07-18 06:41:28 [481,551ms] [Error] [carb.scripting-python.plugin] TypeError: str_builder() got an unexpected keyword argument 'on_value_changed_fn'
Hi @DiscoFlower8890 - It seems like the str_builder
function does not have an on_value_changed_fn
parameter, as the error message suggests. This means that the function does not support running a function when the value of the string box is changed.
As for the on_clicked_fn
not working when the folder picker button is clicked, it could be due to a number of reasons. Here are a few things you could try:
- Check if the
str_builder
function actually supports theon_clicked_fn
parameter. It’s possible that this parameter is not implemented or not working correctly. - Make sure that the
test_clicking
function is defined correctly and is in scope when thestr_builder
function is called. If the function is not in scope, it cannot be called. - Try using a different function for the
on_clicked_fn
parameter to see if the problem is with thetest_clicking
function or with thestr_builder
function. - Check if there are any errors or warnings in the console that could give you a hint about what’s going wrong.
If none of this works then let me know and I can help you connect with right developer.
Hi @rthaker - Yep that seems to be the case.
I tried all of the things you suggested and got these results:
- I used:
from omni.isaac.ui.ui_utils import str_builder
help(str_builder)
and got:
Help on function str_builder in module omni.isaac.ui.ui_utils:
str_builder(label='', type='stringfield', default_val=' ', tooltip='', on_clicked_fn=None, use_folder_picker=False, read_only=False, item_filter_fn=None, bookmark_label=None, bookmark_path=None, folder_dialog_title='Select Output Folder', folder_button_title='Select Folder')
Creates a Stylized Stringfield Widget
Args:
label (str, optional): Label to the left of the UI element. Defaults to "".
type (str, optional): Type of UI element. Defaults to "stringfield".
default_val (str, optional): Text to initialize in Stringfield. Defaults to " ".
tooltip (str, optional): Tooltip to display over the UI elements. Defaults to "".
use_folder_picker (bool, optional): Add a folder picker button to the right. Defaults to False.
read_only (bool, optional): Prevents editing. Defaults to False.
item_filter_fn (Callable, optional): filter function to pass to the FilePicker
bookmark_label (str, optional): bookmark label to pass to the FilePicker
bookmark_path (str, optional): bookmark path to pass to the FilePicker
Returns:
AbstractValueModel: model of Stringfield
on_clicked_fn is mentioned at the top, but not under the “Args”. Which is odd.
- It should be, same function in the same location worked as an
on_clicked_fn
for ancb_builder
- I have tried every function I have in the .py file (adding a print at the start) and nothing.
- Nothing appears in console when the extension is loaded. And nothing appears when I select something using the folder picker.
None of the suggestions worked. Looking at the help print it I’d guess that it’s not implemented properly.
@DiscoFlower8890 There is a newer set of UI utils that is generally much easier to use and manage. Check out the docs for UI tools here: UI Element Wrappers scrolling down to see the newer UI tools (looking for StringField()).
P.S. You can see a demonstration of an extension using all the new UI wrappers here: UI Component Library, but you’d have to download the extension as described in the linked tutorial to see the code.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.