def _reconnect_matplotlib_keys(self): """ Reconnect the previously disconnected matplotlib keys """ if self.figure is not None and hasattr(self,'_mpl_key_callbacks'): self.figure.canvas.callbacks.callbacks['key_press_event'].update(self._mpl_key_callbacks) elif self.figure is not None: mpl_keypress_handler = self.figure.canvas.manager.key_press_handler_id bmp = BoundMethodProxy(self.figure.canvas.manager.key_press) self.figure.canvas.callbacks.callbacks['key_press_event'].update({mpl_keypress_handler: bmp})
def _disconnect_matplotlib_keys(self): """ Disconnected the matplotlib key-press callbacks """ if self.figure is not None: cbs = self.figure.canvas.callbacks.callbacks # this may cause problems since the dict of key press events is a # dict, i.e. not ordered, and we want to pop the first one... mpl_keypress_handler = self.figure.canvas.manager.key_press_handler_id try: self._mpl_key_callbacks = {mpl_keypress_handler: cbs['key_press_event'].pop(mpl_keypress_handler)} except KeyError: bmp = BoundMethodProxy(self.figure.canvas.manager.key_press) self._mpl_key_callbacks = {mpl_keypress_handler: bmp}