def prepare_color_widgets(
        self,
        colors,
        widget_width,
        icon_width,
        position_method_name,
        position_method_kwargs,
    ):
        """Set/create widgets to hold and display colors."""
        ## iterate over the black and white colors, creating
        ## a heavy check mark of each color

        black_tick, white_tick = (
            render_layered_icon(
                chars=[chr(124)],
                dimension_name="width",
                dimension_value=icon_width,
                colors=[color],
                background_width=widget_width,
                background_height=widget_width,
            )
            for color in (BLACK, WHITE)
        )

        ### we must sort the colors in a pleasing, logical
        ### way as to make it easier for the user to choose
        ### colors

        ## begin by ensuring the given colors are inside a
        ## list, so it can be sorted
        colors = list(colors)

        ## then obtain a new list with the colors already
        ## sorted according to a custom useful recipe
        sorted_colors = get_custom_sorted_colors(colors)

        ### store amount of color widgets needed
        no_of_colors = len(sorted_colors)

        ### now that the colors are nicely sorted, let's
        ### set them in existing color widgets, creating
        ### them if needed

        ## reference existing color objects locally
        existing_color2d_objs = self.existing_color2d_objs

        ## create more color objects if needed

        no_of_needed = no_of_colors - len(existing_color2d_objs)

        if no_of_needed > 0:

            existing_color2d_objs.extend(
                Color2D(widget_width, widget_width, BLACK) for _ in range(no_of_needed)
            )

        ## reference list of color widgets to be used
        ## locally
        color_widgets = self.color_widgets

        ## clear the list and extend it with the number of
        ## color widgets equivalent to the number of colors

        color_widgets.clear()
        color_widgets.extend(existing_color2d_objs[:no_of_colors])

        ## iterate over the color widgets and colors, setting
        ## each color in its respective widget and
        ## performing other setups

        for color_widget, color in zip(color_widgets, sorted_colors):

            ## set the color and size

            color_widget.set_color(color)
            color_widget.set_size((widget_width, widget_width))

            ## set the 'chosen' attribute to False;
            ## it is a flag indicating whether or not
            ## the color it represents is picked
            color_widget.chosen = False

            ## reference either the black or the white
            ## tick surface in the 'tick_surf' attribute
            ## of the widget, whichever contrasts more with
            ## its color

            color_widget.tick_surf = (
                black_tick
                if color_widget.contrasting_color == (0, 0, 0)
                else white_tick
            )

        ### now position all color widgets relative to
        ### each other

        method = getattr(
            color_widgets.rect,
            position_method_name,
        )

        method(**position_method_kwargs)
Set/create widgets to hold and display colors.
nodezator/colorsman/picker/op.py