def stacked_preferred_size(container, components=None):
    """ Returns the size (width,height) that is preferred for this component.

    Overrides Component.
    """
    if container.fixed_preferred_size is not None:
        container._cached_preferred_size = container.fixed_preferred_size
        return container.fixed_preferred_size
    if components is None:
        components = container.components
    ndx = container.stack_index
    other_ndx = 1 - ndx
    no_visible_components = True
    total_size = 0
    max_other_size = 0
    for component in components:
        if not container._should_layout(component):
            continue
        no_visible_components = False
        pref_size = component.get_preferred_size()
        total_size += pref_size[ndx] + container.spacing
        if pref_size[other_ndx] > max_other_size:
            max_other_size = pref_size[other_ndx]
    if total_size >= container.spacing:
        total_size -= container.spacing
    if (container.stack_dimension not in container.resizable and container.
        stack_dimension not in container.fit_components):
        total_size = container.bounds[ndx]
    elif no_visible_components or total_size == 0:
        total_size = container.default_size[ndx]
    if (container.other_dimension not in container.resizable and container.
        other_dimension not in container.fit_components):
        max_other_size = container.bounds[other_ndx]
    elif no_visible_components or max_other_size == 0:
        max_other_size = container.default_size[other_ndx]
    if ndx == 0:
        container._cached_preferred_size = (total_size + container.hpadding,
            max_other_size + container.vpadding)
    else:
        container._cached_preferred_size = (max_other_size + container.
            hpadding, total_size + container.vpadding)
    return container._cached_preferred_size
