spinner.py

Go to the documentation of this file.
00001 ##
00002 # 
00003 # Implements a text spinner.  Prints to stdout.
00004 # 
00005 # Copyright (C) 2002 GDS Software
00006 # 
00007 # This program is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU General Public License as
00009 # published by the Free Software Foundation; either version 2 of
00010 # the License, or (at your option) any later version.
00011 # 
00012 # This program is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 # GNU General Public License for more details.
00016 # 
00017 # You should have received a copy of the GNU General Public
00018 # License along with this program; if not, write to the Free
00019 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00020 # MA  02111-1307  USA
00021 # 
00022 # See http://www.gnu.org/licenses/licenses.html for more details.
00023 # 
00024 
00025 import sys
00026 __version__ = "$Id: spinner.py,v 1.4 2002/08/21 12:41:49 donp Exp $"
00027 
00028 class Spinner:
00029     def __init__(self, type=0):
00030         if type == 0:
00031             self.char = ['.', 'o', 'O', 'o']
00032         else:
00033             self.char = ['|', '/', '-', '\\', '-']
00034         self.len  = len(self.char)
00035         self.curr = 0
00036 
00037     def Print(self):
00038         self.curr = (self.curr + 1) % self.len
00039         str = self.char[self.curr]
00040         sys.stdout.write("\b \b%s" % str)
00041 
00042     def Done(self):
00043         sys.stdout.write("\b \b")
00044 
00045 if __name__ == "__main__":
00046     import time
00047     num_times  = 50
00048     delay_time = 0.08 # seconds
00049 
00050     print "Demo of type=0 spinner:"
00051     s = Spinner(type=0)
00052     for jx in xrange(num_times):
00053         s.Print()
00054         time.sleep(delay_time)
00055     s.Done()
00056 
00057     print "Demo of type=1 spinner:"
00058     s = Spinner(type=1)
00059     for jx in xrange(num_times):
00060         s.Print()
00061         time.sleep(delay_time)
00062     s.Done()
00063 
00064 

© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."

Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.

122,241 lines of code and growing...