#
#   Python GUI - Scroll frames - Generic
#

from Views import View
from ScrollBars import ScrollBar

class ScrollFrame(View):
    """A ScrollFrame adds scroll bars to a client View."""

    def __init__(self, client, scrolling = 'hv', **kwds):
        View.__init__(self)
        client_width, client_height = client.size
        frame_width = client_width
        frame_height = client_height
        hsb = None
        vsb = None
        if 'h' in scrolling:
            hsb = ScrollBar(direction = 'h', client = client, width = client_width)
            frame_height += hsb.height
        if 'v' in scrolling:
            vsb = ScrollBar(direction = 'v', client = client, height = client_height)
            frame_width += vsb.width
        self.size = (frame_width, frame_height)
        self.place(client, left = 0, top = 0, sticky = 'nsew')
        if hsb:
            self.place(hsb, left = 0, bottom = 0, sticky = 'ews')
        if vsb:
            self.place(vsb, top = 0, right = 0, sticky = 'nse')
        self.set(**kwds)
