def set_visual(self, visual_data):
        """Store visual in preview panel and update rect's size

        Parameters
        ==========
        visual_data (string, pygame.Surface or dict)
            Data used for displaying visual in the preview panel.
        """

        if isinstance(visual_data, Surface):

            ### get a new surface which is a copy of a checkered surf
            ### with the same size as the visual

            new_surf = CHECKERED_SURF_MAP[(
                visual_data.get_size(),  # surf size
                PREVIEW_PANEL_CHECKER_A, # checker color a
                PREVIEW_PANEL_CHECKER_B, # checker color b
                10,    # checker rect width
                10,    # checker rect height
            )].copy()

            ### blit visual over new surface
            new_surf.blit(visual_data, (0, 0))

        elif isinstance(visual_data, str):
            new_surf = get_text_surf(visual_data, SIDEVIZ_TEXT_SETTINGS)

        elif isinstance(visual_data, dict):

            try:

                data = visual_data['data']
                hint = visual_data['hint']

            except KeyError:

                raise RuntimeError(
                    "Can't set side visual because"
                    " 'data' and/or 'hint' key can't"
                    " be found"
                )

            else:

                if hint == 'text':
                    new_surf = get_text_surf(data, SIDEVIZ_TEXT_SETTINGS)

                elif hint == 'monospaced_text':
                    new_surf = get_text_surf(data, SIDEVIZ_MONOSPACED_TEXT_SETTINGS)

                elif hint == 'python_source':
                    new_surf = get_python_source_surf(data)

                else:

                    raise RuntimeError(
                        "side visual data 'hint' must be"
                        " 'text' or 'python_source'"
                    )

        else:

            raise RuntimeError(
                "Can't set side visual because type is not supported"
            )

        ### update preview panel's image and rect's size
        ### taking new surface into account

        self.preview_panel.image = new_surf
        self.preview_panel.rect.size = new_surf.get_size()
Store visual in preview panel and update rect's size

        Parameters
        ==========
        visual_data (string, pygame.Surface or dict)
            Data used for displaying visual in the preview panel.
        
nodezator/graphman/callablenode/outputviz.py