#
#   Python GUI - Scroll bars - Gtk
#

import gtk
from Components import Component
from GScrollBars import ScrollBar as GScrollBar

class ScrollBar(Component, GScrollBar):

    def __init__(self, direction = None, **kwds):
        if direction == 'h':
            gtk_scrollbar = gtk.HScrollbar()
            self._direction = 0
        elif direction == 'v':
            gtk_scrollbar = gtk.VScrollbar()
            self._direction = 1
        else:
            raise ValueError("No direction specified for ScrollBar")
        gtk_scrollbar.show()
        self._gtk_scrollbar = gtk_scrollbar
        Component.__init__(self, _gtk_outer = gtk_scrollbar, **kwds)

    def destroy(self):
        GScrollBar.destroy(self)
        Component.destroy(self)
    
    def set_client(self, new_client):
        GScrollBar.set_client(self, new_client)
        if new_client:
            gtk_adjustment = new_client._gtk_adjustments()[self._direction]
        else:
            gtk_adjustment = None
        self._gtk_scrollbar.set_adjustment(gtk_adjustment)
