Returns a year's calendar as a multi-line string.
(self, theyear, w=2, l=1, c=6, m=3)
| 424 | return s |
| 425 | |
| 426 | def formatyear(self, theyear, w=2, l=1, c=6, m=3): |
| 427 | """ |
| 428 | Returns a year's calendar as a multi-line string. |
| 429 | """ |
| 430 | w = max(2, w) |
| 431 | l = max(1, l) |
| 432 | c = max(2, c) |
| 433 | colwidth = (w + 1) * 7 - 1 |
| 434 | v = [] |
| 435 | a = v.append |
| 436 | a(repr(theyear).center(colwidth*m+c*(m-1)).rstrip()) |
| 437 | a('\n'*l) |
| 438 | header = self.formatweekheader(w) |
| 439 | for (i, row) in enumerate(self.yeardays2calendar(theyear, m)): |
| 440 | # months in this row |
| 441 | months = range(m*i+1, min(m*(i+1)+1, 13)) |
| 442 | a('\n'*l) |
| 443 | names = (self.formatmonthname(theyear, k, colwidth, False) |
| 444 | for k in months) |
| 445 | a(formatstring(names, colwidth, c).rstrip()) |
| 446 | a('\n'*l) |
| 447 | headers = (header for k in months) |
| 448 | a(formatstring(headers, colwidth, c).rstrip()) |
| 449 | a('\n'*l) |
| 450 | |
| 451 | # max number of weeks for this row |
| 452 | height = max(len(cal) for cal in row) |
| 453 | for j in range(height): |
| 454 | weeks = [] |
| 455 | for cal in row: |
| 456 | if j >= len(cal): |
| 457 | weeks.append('') |
| 458 | else: |
| 459 | weeks.append(self.formatweek(cal[j], w)) |
| 460 | a(formatstring(weeks, colwidth, c).rstrip()) |
| 461 | a('\n' * l) |
| 462 | return ''.join(v) |
| 463 | |
| 464 | def pryear(self, theyear, w=0, l=0, c=6, m=3): |
| 465 | """Print a year's calendar.""" |