Returns a year's calendar as a multi-line string.
(self, theyear, w=2, l=1, c=6, m=3)
| 405 | return s |
| 406 | |
| 407 | def formatyear(self, theyear, w=2, l=1, c=6, m=3): |
| 408 | """ |
| 409 | Returns a year's calendar as a multi-line string. |
| 410 | """ |
| 411 | w = max(2, w) |
| 412 | l = max(1, l) |
| 413 | c = max(2, c) |
| 414 | colwidth = (w + 1) * 7 - 1 |
| 415 | v = [] |
| 416 | a = v.append |
| 417 | a(repr(theyear).center(colwidth*m+c*(m-1)).rstrip()) |
| 418 | a('\n'*l) |
| 419 | header = self.formatweekheader(w) |
| 420 | for (i, row) in enumerate(self.yeardays2calendar(theyear, m)): |
| 421 | # months in this row |
| 422 | months = range(m*i+1, min(m*(i+1)+1, 13)) |
| 423 | a('\n'*l) |
| 424 | names = (self.formatmonthname(theyear, k, colwidth, False) |
| 425 | for k in months) |
| 426 | a(formatstring(names, colwidth, c).rstrip()) |
| 427 | a('\n'*l) |
| 428 | headers = (header for k in months) |
| 429 | a(formatstring(headers, colwidth, c).rstrip()) |
| 430 | a('\n'*l) |
| 431 | |
| 432 | # max number of weeks for this row |
| 433 | height = max(len(cal) for cal in row) |
| 434 | for j in range(height): |
| 435 | weeks = [] |
| 436 | for cal in row: |
| 437 | if j >= len(cal): |
| 438 | weeks.append('') |
| 439 | else: |
| 440 | weeks.append(self.formatweek(cal[j], w)) |
| 441 | a(formatstring(weeks, colwidth, c).rstrip()) |
| 442 | a('\n' * l) |
| 443 | return ''.join(v) |
| 444 | |
| 445 | def pryear(self, theyear, w=0, l=0, c=6, m=3): |
| 446 | """Print a year's calendar.""" |