Hi
I have following class.
The toggle() function will show\hide a SphereLight
It works fine when called from the UI.Button click
It does not work when called from inside the thread callback ‘my_callback’. When called from the timer callback Omniverse Code hangs. How do I get the callback to Toggle the SpereLight ?
class C2HelloWorldExtension(omni.ext.IExt):
def on_startup(self, ext_id):
print("[c2.hello.world] c2 hello world startup")
self.mode=0
self._window = ui.Window("Sphere Light Tests", width=500, height=300)
with self._window.frame:
with ui.VStack():
def setLightViaStage(mode):
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/SphereLight")
attribute = prim.GetAttribute("visibility")
attribute.Set("invisible" if mode == 0 else "inherited")
def toggle():
self.mode = self.mode ^ 1
setLightViaStage(self.mode)
def my_callback():
toggle()
start_timer()
def start_timer():
self.timer = threading.Timer(1, my_callback)
self.timer.start()
with ui.HStack():
ui.Button("Button Toggle", clicked_fn=toggle)
ui.Button("Thread Toggle", clicked_fn=start_timer)
def on_shutdown(self):
print("[c2.hello.world] c2 hello world shutdown")
thanks