Add keyboard event callback for Python passive viewer.

Fixes #766
Fixes #846

PiperOrigin-RevId: 549449372
Change-Id: I37d17f1162c66d0e8482d402aae22d9a16b59deb
This commit is contained in:
Saran Tunyasuvunakool
2023-07-19 15:53:51 -07:00
committed by Copybara-Service
parent f7847ba73e
commit 06b70832ce
7 changed files with 92 additions and 13 deletions
+5 -4
View File
@@ -115,12 +115,12 @@ class _MjPythonImpl(mujoco.viewer._MjPythonBase):
self._termination = self.__class__.NOT_TERMINATED
self._busy = False
def launch_on_ui_thread(self, model, data, handle_return):
def launch_on_ui_thread(self, model, data, handle_return, key_callback):
with self._cond:
if self._busy or self._task is not None:
raise RuntimeError('another MuJoCo viewer is already open')
else:
self._task = (model, data, handle_return)
self._task = (model, data, handle_return, key_callback)
self._cond.notify()
def terminate(self):
@@ -294,10 +294,11 @@ while True:
break
# Otherwise, launch the viewer.
model, data, handle_return = task
model, data, handle_return, key_callback = task
ctypes.CDLL(None).mjpython_show_dock_icon()
mujoco.viewer._launch_internal(
model, data, run_physics_thread=False, handle_return=handle_return)
model, data, run_physics_thread=False, handle_return=handle_return,
key_callback=key_callback)
ctypes.CDLL(None).mjpython_hide_dock_icon()
finally: