[TPG] Misc changes for new dispense
[zanchey/dispense2.git] / codesnippets / horizscroll.py
1 #!/usr/bin/env python
2
3 import string
4 import sys
5 import time
6
7 class HorizScroll:
8         def __init__(self, text):
9                 self.text = text
10                 pass
11
12         def expand(self, padding=None, paddingchar=" ", dir=None):
13                 if len(self.text) <= 10:
14                         return [text]
15
16                 if not padding:
17                         padding = len(self.text) / 2
18
19                 format = "%-" + str(padding) + "." + str(padding) + "s"
20                 pad = string.replace(format % " "," ",paddingchar)
21                 padtext = self.text + pad
22                 expansion = []
23
24                 for x in range(0,len(padtext)):
25                           expansion.append(padtext[x:] + padtext[:x])
26                 
27                 if dir == -1:
28                         expansion.reverse()
29
30                 return expansion
31
32 if __name__ == '__main__':
33         h = HorizScroll("hello cruel world")
34         eh = h.expand()
35         while 1:
36                 for x in eh:
37                         sys.stdout.write("\r")
38                         print "%-10.10s" % x,
39                         sys.stdout.flush()
40                         time.sleep(0.1)
41

UCC git Repository :: git.ucc.asn.au