예제 #1
0
    def _bind_key(self, key, func):
        """Setup the mapping from key to call the function.

        Parameters
        ----------
        func : function
            Must be callable.

        Raises
        ------
        ReadlineError
        """
        if not callable(func):
            print("Trying to bind non method to keystroke:%s,%s" % (key, func))
            raise ReadlineError(
                "Trying to bind non method to keystroke:%s,%s,%s,%s"
                % (key, func, type(func), type(self._bind_key))
            )
        keyinfo = make_KeyPress_from_keydescr(key.lower()).tuple()
        log(">>>%s -> %s<<<" % (keyinfo, func.__name__), logging.DEBUG)
        self.key_dispatch[keyinfo] = func