/[anoncvs]/projects/dispense2/sql-edition/servers/HorizScroll.py


UCC Code Repository

Contents of /projects/dispense2/sql-edition/servers/HorizScroll.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download) (as text)
Wed Sep 29 09:30:38 2004 UTC (16 years, 8 months ago) by mtearle
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -1 lines
File MIME type: text/x-python
Toggle wraparound logic ... I think it was the wrong way around

1 dagobah 1.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, wraparound=False):
13     if len(self.text) <= 10:
14     return [text]
15    
16 dagobah 1.2 if padding == None:
17 dagobah 1.1 padding = len(self.text) / 2 + 1
18    
19     format = "%-" + str(padding) + "." + str(padding) + "s"
20     pad = string.replace(format % " "," ",paddingchar)
21     padtext = self.text + pad
22 mtearle 1.3 if not wraparound:
23 dagobah 1.2 numiters = len(self.text) - 10
24 dagobah 1.1 else:
25     numiters = len(padtext)
26    
27     expansion = []
28    
29     for x in range(0,numiters):
30     expansion.append("%-10.10s" % (padtext[x:] + padtext[:x]))
31    
32     if dir == -1:
33     expansion.reverse()
34    
35     return expansion
36    
37     if __name__ == '__main__':
38     h = HorizScroll("hello cruel world")
39     eh = h.expand()
40     while 1:
41     for x in eh:
42     sys.stdout.write("\r")
43     print "%-10.10s" % x,
44     sys.stdout.flush()
45     time.sleep(0.1)
46    

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26