from Tkinter import *
from rhtkinter import *
import string

class Scale(RHFrame):

    def createWidgets(self):
	self.C = Canvas
	self.C = Canvas(self, { 'width' : "%d" % self.width, 
				'height' : "%d" % self.height} )
	self.C.pack()
	self.pack()

	back = self.C.create_polygon(0, 0, self.width, 0, 
					self.width, self.height, 0, self.height,
					 { 'fill' : 'light slate grey' })
	self.bar = self.C.create_polygon(0, 0, 0, 0, 0, 0, 0, 0)
	self.label = self.C.create_text(0, 0, { 'text': "" })

    def setLabel(self, label):
	self.C.delete(self.label)
	self.label = self.C.create_text(self.width / 2, self.height / 2, 
					{ 'text' : label } )
	self.C.tkraise(self.label, self.bar)

    def set(self, amount):
	self.C.delete(self.bar)

	barwidth = self.width * ((1.0 * amount) / self.fullValue)
	self.bar = self.C.create_polygon(0, 0, barwidth, 0, 
					 barwidth, self.height, 0, self.height,
					 { 'fill' : 'dark slate grey' })
	self.C.tkraise(self.label, self.bar)

    def __init__(self, width, height, fullval, Master = None):
	self.width = width
	self.height = height
	self.fullValue = fullval

	RHFrame.__init__(self, Master)
	self.createWidgets()
