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

Source Code for Module layouts.bars

 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  """bars layout""" 
19   
20  from lib.xcairo import * 
21  from lib.geom import * 
22  import calendar 
23  import optparse 
24  import sys 
25  from datetime import date, timedelta 
26   
27  import _base 
28   
29  parser = _base.get_parser(__name__) 
30  parser.set_defaults(rows=2) 
31   
32 -class CalendarRenderer(_base.CalendarRenderer):
33 """bars layout class"""
34 - def _draw_month(self, cr, rect, month, year):
35 S,G,L = self.Theme 36 make_sloppy_rect(cr, rect, G.month.sloppy_dx, G.month.sloppy_dy, G.month.sloppy_rot) 37 38 day, span = calendar.monthrange(year, month) 39 mmeasure = 'A'*max(map(len,L.month_name)) 40 if self.options.month_with_year: 41 mmeasure += 'A'*(len(str(year))+1) 42 43 rows = 31 if G.month.symmetric else span 44 grid = VLayout(rect_from_origin(rect), 32) # title bar always symmetric 45 dom_grid = VLayout(grid.item_span(31,1), rows) 46 47 # draw box shadow 48 if S.month.box_shadow: 49 f = S.month.box_shadow_size 50 shad = (f,-f) if G.landscape else (f,f) 51 draw_shadow(cr, rect_from_origin(rect), shad) 52 53 # draw day cells 54 for dom in range(1,rows+1): 55 R = dom_grid.item(dom-1) 56 if dom <= span: 57 holiday_tuple = self.holiday_provider(year, month, dom, day) 58 day_style = holiday_tuple[2] 59 dcell = _base.DayCell(day = (dom, day), header = holiday_tuple[0], footer = holiday_tuple[1], 60 theme = (day_style, G.dom, L), show_day_name = True) 61 dcell.draw(cr, R, self.options.short_daycell_ratio) 62 else: 63 day_style = S.dom 64 draw_box(cr, rect = R, stroke_rgba = day_style.frame, fill_rgba = day_style.bg, 65 stroke_width = mm_to_dots(day_style.frame_thickness)) 66 day = (day + 1) % 7 67 68 # draw month title (name) 69 mcolor = S.month.color_map_bg[year%2][month] 70 mcolor_fg = S.month.color_map_fg[year%2][month] 71 R_mb = grid.item(0) 72 draw_box(cr, rect = R_mb, stroke_rgba = S.month.frame, fill_rgba = mcolor, 73 stroke_width = mm_to_dots(S.month.frame_thickness)) # title box 74 draw_box(cr, rect = rect_from_origin(rect), stroke_rgba = S.month.frame, fill_rgba = (), 75 stroke_width = mm_to_dots(S.month.frame_thickness)) # full box 76 R_text = rect_rel_scale(R_mb, 1, 0.5) 77 mshad = None 78 if S.month.text_shadow: 79 f = S.month.text_shadow_size 80 mshad = (f,-f) if G.landscape else (f,f) 81 title_str = L.month_name[month] 82 if self.options.month_with_year: title_str += ' ' + str(year) 83 draw_str(cr, text = title_str, rect = R_text, scaling = -1, stroke_rgba = mcolor_fg, 84 align = (2,0), font = S.month.font, measure = mmeasure, shadow = mshad) 85 cr.restore()
86