summaryrefslogtreecommitdiff
path: root/example.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2010-06-11 19:42:18 +1200
committerLars Wirzenius <liw@liw.fi>2010-06-11 19:42:18 +1200
commit2c70ee267a0172de421cdbc068515e785a3963a5 (patch)
tree826341df276347e5d602a1053f5c588a4c0882b7 /example.py
parent429fc587274decea9052521a4b1decc3e0f63eaa (diff)
downloadttystatus-2c70ee267a0172de421cdbc068515e785a3963a5.tar.gz
Update example program to use some of the new widgets.
Diffstat (limited to 'example.py')
-rw-r--r--example.py35
1 files changed, 29 insertions, 6 deletions
diff --git a/example.py b/example.py
index d7938b7..e56ddf6 100644
--- a/example.py
+++ b/example.py
@@ -25,14 +25,37 @@ import ttystatus
def main():
ts = ttystatus.TerminalStatus(period=0.1)
- ts.add(ttystatus.Literal('Finding symlinks: '))
- ts.add(ttystatus.String('pathname'))
-
+ ts.add(ttystatus.Literal('Looking for files: '))
+ ts.add(ttystatus.Counter('pathname'))
+ ts.add(ttystatus.Literal(' found, currently in '))
+ ts.add(ttystatus.Pathname('dirname'))
+
+ pathnames = []
for dirname, subdirs, basenames in os.walk(sys.argv[1]):
- for pathname in [os.path.join(dirname, x) for x in basenames]:
+ ts['dirname'] = dirname
+ for basename in basenames:
+ pathname = os.path.join(dirname, basename)
ts['pathname'] = pathname
- if os.path.islink(pathname):
- ts.notify('Symlink! %s' % pathname)
+ pathnames.append(pathname)
+
+ ts.clear()
+ ts.add(ttystatus.Literal('Finding symlinks: '))
+ ts.add(ttystatus.Index('pathname', 'pathnames'))
+ ts.add(ttystatus.Literal(' ('))
+ ts.add(ttystatus.PercentDone('done', 'total', decimals=2))
+ ts.add(ttystatus.Literal(' done) '))
+ ts.add(ttystatus.Counter('symlink'))
+ ts.add(ttystatus.Literal(' symlinks found'))
+ ts['pathnames'] = pathnames
+ ts['done'] = 0
+ ts['total'] = len(pathnames)
+
+ for pathname in pathnames:
+ ts['pathname'] = pathname
+ if os.path.islink(pathname):
+ ts['symlink'] = pathname
+ ts.notify('Symlink! %s' % pathname)
+ ts['done'] += 1
ts.finish()