def redraw_pattern(self):
        """Redraw the chosen pattern.

        It is also used as the preparation operation for
        the patterns mode.
        """
        ### perform the operation stored in the
        ### 'close_generator' attribute, which might be
        ### an empty function or actually close a previously
        ### created generator
        self.close_generator()

        ### if the patterns option menu isn't stored in the
        ### list of the buttons, append it along with the
        ### redraw pattern button

        if self.pattern_options not in self.buttons:

            self.labels.append(self.pattern_label)

            self.buttons.extend(
                (
                    self.pattern_options,
                    self.redraw_pattern_button,
                )
            )

        ### get the name of the chosen pattern from the
        ### options menu
        pattern_name = self.pattern_options.get()

        ### use the name to retrieve the corresponding
        ### drawing operation from the pattern drawing map
        drawing_callable = PATTERN_DRAWING_MAP[pattern_name]

        ### perform the drawing operation with the surface
        ### representing the canvas and the list of colors,
        ### catching the resulting return value

        result = drawing_callable(self.canvas.image, self.colors)

        ### set the 'update' and 'close_generator'
        ### attributes to specific objects depending on
        ### whether the result is a generator-iterator
        ### or not

        ## if the result is a generator-iterator, set the
        ## 'update' and 'close_generator' attributes to
        ## references of the generator-iterator's '__next__'
        ## and 'close' methods, respectively

        if isinstance(result, GeneratorType):

            self.update = result.__next__

            self.close_generator = result.close

        ## otherwise just set both attributes to an empty
        ## function

        else:

            self.update = self.close_generator = empty_function
Redraw the chosen pattern.

        It is also used as the preparation operation for
        the patterns mode.
        
nodezator/colorsman/viewer/modes/patterns/main.py