#!/usr/bin/env python
#-----------------------------------------------------------------------
# ProgressIndicatorBox - A progress indicator dialog box for freevo.
#-----------------------------------------------------------------------
#  By Thorsten Pferdekaemper
#----------------------------------------------------------------------- 
"""
A Progress Indicator Dialog box type class for Freevo.
""" 

from PopupBox import *

class ProgressIndicatorBox(PopupBox):
  
    def __init__(self, text=' ', total = 0):
        PopupBox.__init__(self)
        self.text = text
        self.total = total
        self.processed = 0
        
    def __conv_text(self):
        return '%s of %s\n%s' % (self.processed, self.total, self.text)
        
    def set_progress(self, processed, total=None):
        if total:
           self.total = total
        self.processed = processed 
        self.label.set_text(self.__conv_text())
        if self.visible:
           self.show()       


    def _draw(self):
        self.surface = pygame.Surface(self.get_size(), 0, 32)
        c   = self.bg_color.get_color_sdl()
        a   = self.bg_color.get_alpha()
        self.surface.fill(c)
        self.surface.set_alpha(a)
        if self.total:
           width = ( self.get_size()[0] - 8 ) * self.processed / self.total
        else:
           width = 0  
        rect = self.surface.subsurface((4,4,width,20))
        rect.fill(self.fg_color.get_color_sdl())
        rect.set_alpha(self.fg_color.get_alpha())
        
        Container._draw(self)

        self.blit_parent()
        

    



