def create_context_menu(self, event, shape):
        '''
        Parameters
        ----------
        event : gtk.gdk.Event
            GTK mouse click event.
        shape : str
            Electrode shape identifier (e.g., `"electrode028"`).

        Returns
        -------
        gtk.Menu
            Context menu.


        .. versionchanged:: 0.13
            - Deprecate hard-coded commands (e.g., clear electrodes, clear
              routes).
            - Add anonymous global commands section at head of menu (i.e.,
              commands not specific to an electrode or route).
            - Add "Electrode" and "Route(s)" sub-menus.
        '''
        routes = self.df_routes.loc[self.df_routes.electrode_i == shape,
                                    'route_i'].astype(int).unique().tolist()

        def _connect_callback(menu_item, command_signal, group, command, data):
            callback_called = threading.Event()

            def _callback(signal, widget, *args):
                if callback_called.is_set():
                    return
                callback_called.set()

                _L().debug('`%s`: %s %s %s', signal, group, command, data)
                gtk.idle_add(self.emit, command_signal, group, command, data)
            menu_item.connect('activate', ft.partial(_callback, 'activate'))
            menu_item.connect('button-press-event',
                              ft.partial(_callback, 'button-press-event'))

            if group is not None:
                menu_item.set_tooltip_text(group)

        menu = gtk.Menu()

        # Add menu items/groups for registered global commands.
        if self.global_commands:
            data = {'event': event.copy()}
            command_signal = 'global-command'

            for group, commands in self.global_commands.iteritems():
                for command, title in commands.iteritems():
                    menu_item_j = gtk.MenuItem(title)
                    menu.append(menu_item_j)

                    _connect_callback(menu_item_j, command_signal, group,
                                      command, data)

        # Add menu items/groups for registered electrode commands.
        if self.electrode_commands:
            separator = gtk.SeparatorMenuItem()
            menu.append(separator)

            # Add electrode sub-menu.
            menu_e = gtk.Menu()
            menu_head_e = gtk.MenuItem('_Electrode')
            menu_head_e.set_submenu(menu_e)
            menu_head_e.set_use_underline(True)
            menu.append(menu_head_e)

            command_signal = 'electrode-command'
            data = {'electrode_id': shape, 'event': event.copy()}

            for group, commands in self.electrode_commands.iteritems():
                for command, title in commands.iteritems():
                    menu_item_j = gtk.MenuItem(title)
                    menu_e.append(menu_item_j)
                    _connect_callback(menu_item_j, command_signal, group,
                                      command, data)

        # Add menu items/groups for registered route commands.
        if routes and self.route_commands:
            # TODO: Refactor electrode/route command menu code to reduce code
            # duplication (i.e., DRY).
            separator = gtk.SeparatorMenuItem()
            menu.append(separator)

            # Add route sub-menu.
            menu_r = gtk.Menu()
            menu_head_r = gtk.MenuItem('_Route(s)')
            menu_head_r.set_submenu(menu_r)
            menu_head_r.set_use_underline(True)
            menu.append(menu_head_r)

            command_signal = 'route-command'
            data = {'route_ids': routes, 'event': event.copy()}
            for group, commands in self.route_commands.iteritems():
                for command, title in commands.iteritems():
                    menu_item_j = gtk.MenuItem(title)
                    menu_r.append(menu_item_j)

                    _connect_callback(menu_item_j, command_signal, group,
                                      command, data)

        menu.show_all()
        return menu