def __init__(self, fig, gs, rows, cols, actions_arr):
"""
Constructs an ActionPanel assuming actions_arr is an array of
fully initialized actions.
Each action must have: key, name, func.
Each action can have: axis_pos, keyboard_binding, ps3_binding.
"""
assert len(actions_arr) <= rows*cols, 'Too many actions to put into gridspec.'
self._fig = fig
self._gs = gridspec.GridSpecFromSubplotSpec(rows, cols, subplot_spec=gs)
self._axarr = [plt.subplot(self._gs[i]) for i in range(len(actions_arr))]
# Read keyboard_bindings and ps3_bindings from config
self._actions = {action.key: action for action in actions_arr}
for key, action in self._actions.iteritems():
if key in config['keyboard_bindings']:
action.kb = config['keyboard_bindings'][key]
if key in config['ps3_bindings']:
action.pb = config['ps3_bindings'][key]
self._buttons = None
self._initialize_buttons()
self._cid = self._fig.canvas.mpl_connect('key_press_event', self.on_key_press)
if ROS_ENABLED:
self._ps3_count = 0
rospy.Subscriber(config['ps3_topic'], Joy, self.ps3_callback)
评论列表
文章目录