I wan to write a string to a textfield. In extension this string will come from a external source but for now i just want to make this work.
- I’m getting no errors in VS Code or warnings
- If i replace the ui.SimpleStringModel(“This is a test”) with ui.CheckBox( width=20 , height=20) and instead of .as_string i write .model it will print true or fale. Like in the documentation.
I can’t figure out what i’m doing wrong.
returnmystring = ui.SimpleStringModel("This is a test")
ui.Spacer(width=30)
cb_stringfield = ui.StringField(model=returnmystring.as_string, width=80, height=20)
new_style = { "font_size" : 24 ,
"color" : 0xFF00b976 }
cb_stringfield.set_style(new_style)
Error in Omniverse Code
2024-03-27 16:43:09 [Error] [carb.scripting-python.plugin] TypeError: 'str' object is not callable
2024-03-27 16:43:09 [Error] [carb.scripting-python.plugin]
2024-03-27 16:43:09 [Error] [carb.scripting-python.plugin] At:
2024-03-27 16:43:09 [Error] [carb.scripting-python.plugin] d:/nvidia/myextensions/curiousxr-exts-avatar/exts/curiousxr.avatar.extension/curiousxr/avatar/extension/extension.py(149): on_startup
2024-03-27 16:43:09 [Error] [carb.scripting-python.plugin] d:\nvidia/librarypath/code-2023.1.1/kit/kernel/py\omni\ext\_impl\_internal.py(163): _startup_ext
2024-03-27 16:43:09 [Error] [carb.scripting-python.plugin] d:\nvidia/librarypath/code-2023.1.1/kit/kernel/py\carb\profiler\__init__.py(85): wrapper
2024-03-27 16:43:09 [Error] [carb.scripting-python.plugin] d:\nvidia/librarypath/code-2023.1.1/kit/kernel/py\omni\ext\_impl\_internal.py(223): startup
2024-03-27 16:43:09 [Error] [carb.scripting-python.plugin] d:\nvidia/librarypath/code-2023.1.1/kit/kernel/py\omni\ext\_impl\_internal.py(323): startup_extension
2024-03-27 16:43:09 [Error] [carb.scripting-python.plugin] PythonExtension.cpp::startup()(2): <module>
2024-03-27 16:43:09 [Error] [carb.scripting-python.plugin]
2024-03-27 16:43:09 [Error] [omni.ext.plugin] [ext: curiousxr.avatar.extension-1.0.0] Failed to startup python extension.
Got the example to work
with ui.VStack():
self.string_model = ui.SimpleStringModel()
ui.StringField(model=self.string_model, width=250, height=25)
self.string_model.as_string = "Enter Question Here"
self.val_changed_id = self.string_model.subscribe_end_edit_fn(self.on_end_edit_string)
with ui.VStack():
self.string_model_result = ui.SimpleStringModel()
ui.StringField(model=self.string_model_result, width=250, height=25)
self.string_model_result.as_string = "Characters in StringField: 0"
def on_end_edit_string(self, item_model):
string_field_val = item_model.as_string
str_len = len(string_field_val)
self.string_model_result.as_string = "Characters in StringField: " + str(str_len)
string_field_as_string = string_field_val
return string_field_as_string
After some tinkering
Now i just need to figure out how to
- make it multiline
- have the text for questions and replies wrap when it reaches the end of the UI box