def insert(self, index, item): """ Insert an item into the manager at the specified index. Parameters ---------- index : int The position at which to insert the object item : string, Group instance or ActionManagerItem instance The item to insert. Notes ----- If the item is a group, the Group is inserted into the manager's list of groups. It the item is a string, then a group is created with the string as the ``id`` and the new group is inserted into the list of groups. If the item is an ActionManagerItem then the item is inserted into the manager's defualt group. """ # 1) The item is a 'Group' instance. if isinstance(item, Group): group = item # Insert the group into the manager. group.parent = self self._groups.insert(index, item) # 2) The item is a string. elif isinstance(item, basestring): # Create a group with that Id. group = Group(id=item) # Insert the group into the manager. group.parent = self self._groups.insert(index, group) # 3) The item is an 'ActionManagerItem' instance. else: # Find the default group. group = self._get_default_group() # Insert the item into the default group. group.insert(index, item) return group
def insert(self, index, item): """ Insert an item into the manager at the specified index. Parameters ---------- index : int The position at which to insert the object item : string, Group instance or ActionManagerItem instance The item to insert. Notes ----- If the item is a group, the Group is inserted into the manager's list of groups. It the item is a string, then a group is created with the string as the ``id`` and the new group is inserted into the list of groups. If the item is an ActionManagerItem then the item is inserted into the manager's defualt group. """ # 1) The item is a 'Group' instance. if isinstance(item, Group): group = item # Insert the group into the manager. group.parent = self self._groups.insert(index, item) # 2) The item is a string. elif isinstance(item, str): # Create a group with that Id. group = Group(id=item) # Insert the group into the manager. group.parent = self self._groups.insert(index, group) # 3) The item is an 'ActionManagerItem' instance. else: # Find the default group. group = self._get_default_group() # Insert the item into the default group. group.insert(index, item) return group
def _prepare_item(self, item): """ Prepare an item to be added to this ActionManager. Parameters ---------- item : string, Group instance or ActionManagerItem instance The item to be added to this ActionManager Returns ------- item : Group or ActionManagerItem Modified item """ # 1) The item is a 'Group' instance. if isinstance(item, Group): item.parent = self # 2) The item is a string. elif isinstance(item, six.string_types): # Create a group with that Id. item = Group(id=item) item.parent = self return item