易于定制的进度条模块

fusha的Python项目详细描述


fusha是一个易于定制的python进度条模块。 它包含默认进度条。但是,你可以自己写 进度条很容易继承此包中提供的类。

功能

  • 使用语句可以很容易地使用fusha,如下所示;

    withFusha():waiting_function()
  • 通过继承,您可以轻松地编写自己的进度条。 fushatemplate类如下;

    classFusha(FushaTemplate):def__init__(self,interval=0.12)FushaTemplate.__init__(self,interval)defformat(self):returnwaiting_formatdefexit_format(self):returnexit_format

安装

$ python setup.py install

$ pip install fusha

开始

fusha提供默认的三个进度条:fusha、fushabar和fushabble。

使用fusha最简单的方法是使用语句创建fusha的实例 在调用您必须等待一段时间的函数之前:

importtimefromfushaimportFushawithFusha():time.sleep(3)

就这些。

默认进度条

fusha提供三个默认进度条。你可以如下使用它们。

importtimefromfushaimportFusha,FushaBar,FushaBubbleprint"Fusha start"withFusha(interval=0.12,title='now loading ...'):time.sleep(3)print"finish"print"FushaBar start"withFushaBar(interval=0.12,bar_len=20)asf:foriinrange(100):f.update(i)time.sleep(.1)print"finish"print"FushaBubble start"withFushaBubble(interval=0.2,title="now loading ..."):time.sleep(3)print"finish"

屏幕截图

福莎

http://kenkov.jp/_images/software/Fusha.gif

福沙巴

http://kenkov.jp/_images/software/FushaBar.gif

福萨布布尔

http://kenkov.jp/_images/software/FushaBubble.gif

如何自定义

您可以轻松创建自己的进度条。

首先,您应该创建一个继承fushatemplate类的新类。 然后,您应该重写两种方法——^ {STR 1 } $格式和^ {STR 1 } $ ExITIX格式< /强>。 函数在with语句中运行时,将调用format方法; 另一方面,在完成您的函数后,将调用^ {STR 1 } $ ExITIX格式<强>。 两个函数都应该返回字符串。

以下代码适用于fushabble:

from fusha import FushaTemplate

class FushaBubble(FushaTemplate):

    def __init__(self,
                 interval=0.12,
                 title='waiting ...'):
        FushaTemplate.__init__(self, interval)
        self.title = title
        self._count =0

    def format(self):
        if self._count % 3==0:
            fmt='\r{0} .'.format(self.title)elif self._count % 3==1:
            fmt='\r{0} o'.format(self.title)else:
            fmt='\r{0} O'.format(self.title)# set count
if self._count ==2:
            self._count =0else:
            self._count +=1return fmt

    def exit_format(self):
        return'\r{0} done\n'.format(self.title)

许可证

麻省理工学院许可证(MIT)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java无法启动应用程序:JNLP错误   java根据用户输入在PreparedStatement中使用setTime()或setNull()   java EJB与同步   java以object为键通过hashmap进行搜索   java中的模10^9+7   针对包含其他对象的对象的java OOP最佳实践   如何将字符串作为HTML代码从Java文件读取到JSP页面?   java我的POM怎么了?“解析表达式..检测到递归表达式循环”   用于Hbase的Mapreduce的java NoSuchMethodError   JAVAlang.SecurityException:权限拒绝:启动意图{act=安卓.Intent.action.MAIN cat=[安卓.Intent.category.LAUNCHER]   数组初始化谜语Java   通过arraylist搜索时的java句柄关联