Advertisement
febrezo

Barra de progeso en Python

May 22nd, 2013
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1.  # -*- coding: cp1252 -*-
  2. import sys
  3.  
  4. ##################
  5. # Clase Progreso #
  6. ##################     
  7. class Progreso:
  8.     '''
  9.         Muestra una barra de progreso que se actualiza en una misma línea. Ejemplo de uso:
  10.         from progreso import Progreso
  11.             import time
  12.  
  13.             titulo = "Analizando"
  14.             carCompletado = '#'
  15.             carVacio = '_'
  16.             tamBarra = 50
  17.  
  18.             barra = Progreso(titulo, carCompletado, carVacio, tamBarra)
  19.  
  20.             veces = 20
  21.             for i in range(veces):
  22.                 time.sleep(0.5)
  23.                 barra.actualizarBarra(float(i+1)/veces*100)
  24.  
  25.     '''
  26.     def __init__ (self, tit, carCom, carVac, tamBarra):
  27.         self.titulo=tit
  28.         self.carCompletado=carCom
  29.         self.carVacio=carVac
  30.         self.tamBarra=tamBarra
  31.         self.progreso=0
  32.        
  33.         sys.stdout.write(self.titulo + ": [" + self.carVacio *self.tamBarra + "]" + chr(8)*(self.tamBarra+1))
  34.         sys.stdout.flush()
  35.         self.progreso = 0
  36.        
  37.     def actualizarBarra(self, x):
  38.         celdas = int(x)*self.tamBarra//100
  39.         sys.stdout.write(self.carCompletado*(celdas - self.progreso))
  40.         sys.stdout.flush()
  41.         self.progreso = celdas
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement