# GLINT graphical package management
# Copyright (C) 1995 Red Hat, Inc
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

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, { 'fill' : 'yellow', 'text': "" })

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

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

	self.amount = amount
	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 get(self, amount):
	return self.amount

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

	self.amount = 0

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