Utilities/__init__.py

changeset 343
f23d1272de6b
parent 177
c822ccc4d138
child 381
64ae9e09d8bc
equal deleted inserted replaced
342:360c4eb76d6c 343:f23d1272de6b
594 return path 594 return path
595 595
596 ellipsis = '...' 596 ellipsis = '...'
597 597
598 head, tail = os.path.split(path) 598 head, tail = os.path.split(path)
599 while head: 599 mid = len(head) // 2
600 path = os.path.join("%s%s" % (head, ellipsis), tail) 600 head1 = head[:mid]
601 head2 = head[mid:]
602 while head1:
603 # head1 is same size as head2 or one shorter
604 path = os.path.join("%s%s%s" % (head1, ellipsis, head2), tail)
601 if measure(path) <= width: 605 if measure(path) <= width:
602 return path 606 return path
603 head = head[:-1] 607 head1 = head1[:-1]
608 head2 = head2[1:]
604 path = os.path.join(ellipsis, tail) 609 path = os.path.join(ellipsis, tail)
605 if measure(path) <= width: 610 if measure(path) <= width:
606 return path 611 return path
607 while tail: 612 while tail:
608 path = "%s%s" % (ellipsis, tail) 613 path = "%s%s" % (ellipsis, tail)

eric ide

mercurial