def move_item(self, steps, item_to_move, custom_command=True):
        """Move given item up or down."""
        ### if there's only one value, moving makes no
        ### sense, so cancel the execution of the rest of
        ### the method by returning earlier
        if len(self.value) == 1:
            return

        ### reference all_objects locally for quicker and
        ### easier access
        all_objects = self.all_objects

        ### store the current topleft of the whole widget
        ### (this is used for repositioning the items,
        ### and must be done before moving the items
        ### because otherwise, if the item moved is the
        ### first one, the top changes and we don't
        ### want that)
        current_topleft = all_objects.rect.topleft

        ### excluding the add_button from the existing
        ### items by popping it, since we know it is the
        ### last item
        all_objects.pop()

        ### discover the index of the item to be moved

        for n, item in enumerate(all_objects):
            if item is item_to_move:
                break

        ### calculate its new value by adding the number of
        ### steps to it
        new_index = n + steps

        ### constrain the index to the possible existing
        ### ones by obtain the remainder of dividing it
        ### by the quantity of existing items
        new_index %= len(all_objects)

        ### then pop the item and insert it in the new
        ### index;
        ###
        ### notice that we don't need to catch its reference
        ### from the output of the list.pop() call, because
        ### we already have a reference to it in our
        ### "item_to_move" variable

        all_objects.pop(n)
        all_objects.insert(new_index, item_to_move)

        ### now just append the add button back and
        ### reposition the items

        all_objects.append(self.add_button)

        (
            all_objects.rect.snap_rects_ip(
                retrieve_pos_from="bottomleft",
                assign_pos_to="topleft",
                offset_pos_by=(0, self.vertical_padding),
            )
        )

        all_objects.rect.topleft = current_topleft

        ### update the values so they reflect the new
        ### order
        self.value = self.get()

        ### execute custom command, if requested
        if custom_command:
            self.command()
Move given item up or down.
nodezator/our3rdlibs/iterablewidget/op.py