#!/usr/bin/python

import atspi
d=atspi.registry.getDesktop()
import pdb
import time
import sys
if len(sys.argv) > 1:
	delay = float(sys.argv[1])
else:
	delay = 10

# This function lifted straight from dogtail.logging
def zeroPad(self, int, width = 1):
	"""
	Pads an integer 'int' with zeroes, up to width 'width'.

	Returns a string.

	It will not truncate. If you call zeroPad(100, 2), '100' will be returned.
	"""
	if int < 10 ** width:
		return ("0" * (width - len(str(int))) ) + str(int)
	else:
		return str(int)

while True:
	print time.asctime(time.localtime())
	for i in range(d.getChildCount()):
		cWidth = len(str(d.getChildCount() -1))
		print zeroPad(None, i, cWidth),

		c=None
		try:
			c=d.getChildAtIndex(i)
		except AssertionError:
			pdb.set_trace()
		print c.getName()
	print
	time.sleep(delay)

