MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / bind

Method bind

dm_control/viewer/user_input.py:229–246  ·  view source on GitHub ↗

Binds a key combination to a callback. Args: callback: An argument-less callable. key_binding: A integer with a key code, a tuple (keycode, modifier) or one of the actions Exclusive|DoubleClick|Range carrying the key combination.

(self, callback, key_binding)

Source from the content-addressed store, hash-verified

227 self._active_exclusive = _NO_EXCLUSIVE_KEY
228
229 def bind(self, callback, key_binding):
230 """Binds a key combination to a callback.
231
232 Args:
233 callback: An argument-less callable.
234 key_binding: A integer with a key code, a tuple (keycode, modifier) or one
235 of the actions Exclusive|DoubleClick|Range carrying the key combination.
236 """
237 def build_callback(index, callback):
238 def indexed_callback():
239 callback(index)
240 return indexed_callback
241
242 if isinstance(key_binding, Range):
243 for index, binding in enumerate(key_binding.collection):
244 self._add_binding(build_callback(index, callback), binding)
245 else:
246 self._add_binding(callback, key_binding)
247
248 def _add_binding(self, callback, key_binding):
249 key_combination = self._extract_key_combination(key_binding)

Callers 5

__init__Method · 0.45
initializeMethod · 0.45
test_bindingMethod · 0.45

Calls 1

_add_bindingMethod · 0.95

Tested by 3

test_bindingMethod · 0.36