Package layouts :: Module classic
[hide private]
[frames] | no frames]

Source Code for Module layouts.classic

  1  # -*- coding: utf-8 -*- 
  2  #    callirhoe - high quality calendar rendering 
  3  #    Copyright (C) 2012-2014 George M. Tzoumas 
  4   
  5  #    This program is free software: you can redistribute it and/or modify 
  6  #    it under the terms of the GNU General Public License as published by 
  7  #    the Free Software Foundation, either version 3 of the License, or 
  8  #    (at your option) any later version. 
  9  # 
 10  #    This program is distributed in the hope that it will be useful, 
 11  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  #    GNU General Public License for more details. 
 14  # 
 15  #    You should have received a copy of the GNU General Public License 
 16  #    along with this program.  If not, see http://www.gnu.org/licenses/ 
 17   
 18  """classic layout""" 
 19   
 20  from lib.xcairo import * 
 21  from lib.geom import * 
 22  import calendar 
 23  import sys 
 24  from datetime import date, timedelta 
 25   
 26  import _base 
 27   
 28  parser = _base.get_parser(__name__) 
 29   
30 -def _weekrows_of_month(year, month):
31 """returns the number of Monday-Sunday ranges (or subsets of) that a month contains, which are 4, 5 or 6 32 33 @rtype: int 34 """ 35 day,span = calendar.monthrange(year, month) 36 if day == 0 and span == 28: return 4 37 if day == 5 and span == 31: return 6 38 if day == 6 and span >= 30: return 6 39 return 5
40
41 -class CalendarRenderer(_base.CalendarRenderer):
42 """classic tiles layout class"""
43 - def _draw_month(self, cr, rect, month, year):
44 S,G,L = self.Theme 45 make_sloppy_rect(cr, rect, G.month.sloppy_dx, G.month.sloppy_dy, G.month.sloppy_rot) 46 47 day, span = calendar.monthrange(year, month) 48 weekrows = 6 if G.month.symmetric else _weekrows_of_month(year, month) 49 dom = -day + 1; 50 wmeasure = 'A'*max(map(len,L.day_name)) 51 mmeasure = 'A'*max(map(len,L.month_name)) 52 if self.options.month_with_year: 53 mmeasure += 'A'*(len(str(year))+1) 54 55 grid = GLayout(rect_from_origin(rect), 7, 7) 56 # 61.8% - 38.2% split (golden) 57 R_mb, R_db = rect_vsplit(grid.item_span(1, 7, 0, 0), 0.618) # month name bar, day name bar 58 R_dnc = HLayout(R_db, 7) # day name cells = 1/7-th of day name bar 59 dom_grid = GLayout(grid.item_span(6, 7, 1, 0), weekrows, 7) 60 61 # draw box shadow 62 if S.month.box_shadow: 63 f = S.month.box_shadow_size 64 shad = (f,-f) if G.landscape else (f,f) 65 draw_shadow(cr, rect_from_origin(rect), shad) 66 67 # draw day names 68 for col in range(7): 69 R = R_dnc.item(col) 70 draw_box(cr, rect = R, stroke_rgba = S.dom.frame, 71 fill_rgba = S.dom.bg if col < 5 else S.dom_weekend.bg, 72 stroke_width = mm_to_dots(S.dow.frame_thickness)) 73 R_text = rect_rel_scale(R, 1, 0.5) 74 draw_str(cr, text = L.day_name[col], rect = R_text, scaling = -1, stroke_rgba = S.dow.fg, 75 align = (2,0), font = S.dow.font, measure = wmeasure) 76 77 # draw day cells 78 for row in range(weekrows): 79 for col in range(7): 80 R = dom_grid.item(row, col) 81 if dom > 0 and dom <= span: 82 holiday_tuple = self.holiday_provider(year, month, dom, col) 83 day_style = holiday_tuple[2] 84 dcell = _base.DayCell(day = (dom, col), header = holiday_tuple[0], footer = holiday_tuple[1], 85 theme = (day_style, G.dom, L), show_day_name = False) 86 dcell.draw(cr, R, self.options.short_daycell_ratio) 87 else: 88 day_style = S.dom_weekend if col >= 5 else S.dom 89 draw_box(cr, rect = R, stroke_rgba = day_style.frame, fill_rgba = day_style.bg, 90 stroke_width = mm_to_dots(day_style.frame_thickness)) 91 dom += 1 92 93 # draw month title (name) 94 mcolor = S.month.color_map_bg[year%2][month] 95 mcolor_fg = S.month.color_map_fg[year%2][month] 96 draw_box(cr, rect = R_mb, stroke_rgba = S.month.frame, fill_rgba = mcolor, 97 stroke_width = mm_to_dots(S.month.frame_thickness)) # title box 98 draw_box(cr, rect = rect_from_origin(rect), stroke_rgba = S.month.frame, fill_rgba = (), 99 stroke_width = mm_to_dots(S.month.frame_thickness)) # full box 100 R_text = rect_rel_scale(R_mb, 1, 0.5) 101 mshad = None 102 if S.month.text_shadow: 103 f = S.month.text_shadow_size 104 mshad = (f,-f) if G.landscape else (f,f) 105 title_str = L.month_name[month] 106 if self.options.month_with_year: title_str += ' ' + str(year) 107 draw_str(cr, text = title_str, rect = R_text, scaling = -1, stroke_rgba = mcolor_fg, 108 align = (2,0), font = S.month.font, measure = mmeasure, shadow = mshad) 109 cr.restore()
110