diff --git a/AUTHORS b/AUTHORS index ddfca8d..587247a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,8 +11,9 @@ George M. Tzoumas CONTRIBUTORS ------------ -Neels Hofmeyr -Nick Kavalieris +Neels Hofmeyr -- sparse layout +Nick Kavalieris -- archlinux package +wrybread@github -- ideas for lightweight mode LANGUAGE DEFINITIONS -------------------- diff --git a/layouts/_base.py b/layouts/_base.py index d188c8b..3aa8f7c 100644 --- a/layouts/_base.py +++ b/layouts/_base.py @@ -84,12 +84,13 @@ class DayCell(object): @type show_day_name: bool @ivar show_day_name: whether day name is displayed """ - def __init__(self, day, header, footer, theme, show_day_name): + def __init__(self, day, header, footer, theme, show_day_name, lightweight = False): self.day = day self.header = header self.footer = footer self.theme = theme self.show_day_name = show_day_name + self.lightweight = lightweight def _draw_short(self, cr, rect): """render the day cell in short mode""" @@ -98,7 +99,8 @@ class DayCell(object): day_of_month, day_of_week, week_of_year = self.day S_bg = S.bg #if day_of_week >= 5 and (week_of_year & 1): S_bg = color_scale(S.bg,0.9) - draw_box(cr, rect, S.frame, S_bg, mm_to_dots(S.frame_thickness)) + draw_box(cr, rect, S.frame, S_bg, mm_to_dots(S.frame_thickness), + lightweight = self.lightweight) R = rect_rel_scale(rect, G.size[0], G.size[1]) if self.show_day_name: Rdom, Rdow = rect_hsplit(R, *G.mw_split) @@ -130,7 +132,8 @@ class DayCell(object): day_of_month, day_of_week, week_of_year = self.day S_bg = S.bg #if day_of_week >= 5 and (week_of_year & 1): S_bg = tuple(reversed(S.bg)) - draw_box(cr, rect, S.frame, S_bg, mm_to_dots(S.frame_thickness)) + draw_box(cr, rect, S.frame, S_bg, mm_to_dots(S.frame_thickness), + lightweight = self.lightweight) R1, Rhf = rect_hsplit(rect, *G.hf_hsplit) if self.show_day_name: R = rect_rel_scale(R1, G.size[2], G.size[3]) diff --git a/layouts/classic.py b/layouts/classic.py index 41a930c..4b0d887 100644 --- a/layouts/classic.py +++ b/layouts/classic.py @@ -28,6 +28,10 @@ import _base parser = _base.get_parser(__name__) parser.add_option("--phantom-days", action="store_true", default=False, help="show days from previous/next month in the unused cells") +parser.add_option("--lightweight", action="store_true", default=False, + help="lightweight cell rendering (lighter/no borders)") +parser.add_option("--lw-inner-padding", type="float", default=1.5, + help="inner padding for month box in lightweight mode") def _weekrows_of_month(year, month): """returns the number of Monday-Sunday ranges (or subsets of) that a month contains, which are 4, 5 or 6 @@ -54,7 +58,15 @@ class CalendarRenderer(_base.CalendarRenderer): if self.options.month_with_year: mmeasure += 'A'*(len(str(year))+1) - grid = GLayout(rect_from_origin(rect), 7, 7) + if self.options.lightweight: + pad = mm_to_dots(self.options.lw_inner_padding); # compute padding from mm to our coordinate system + rect2 = rect_pad(rect, (pad,)*4) # shrink month rect by pad + offset = (rect2[0]-rect[0],rect2[1]-rect[1]) # get offset of new top-left corner wrt prev rect + rect2 = rect_from_origin(rect2); # move new rect to origin (for grid computation) + rect2 = (rect2[0]+offset[0],rect2[1]+offset[1],rect2[2],rect2[3]) # compensate for offset so that it is correctly centered + else: + rect2 = rect_from_origin(rect) + grid = GLayout(rect2, 7, 7) # 61.8% - 38.2% split (golden) R_mb, R_db = rect_vsplit(grid.item_span(1, 7, 0, 0), 0.618) # month name bar, day name bar R_dnc = HLayout(R_db, 7) # day name cells = 1/7-th of day name bar @@ -69,9 +81,10 @@ class CalendarRenderer(_base.CalendarRenderer): # draw day names for col in range(7): R = R_dnc.item(col) - draw_box(cr, rect = R, stroke_rgba = S.dom.frame, + draw_box(cr, rect = R, stroke_rgba = None if self.options.lightweight else S.dom.frame, fill_rgba = S.dom.bg if col < 5 else S.dom_weekend.bg, - stroke_width = mm_to_dots(S.dow.frame_thickness)) + stroke_width = mm_to_dots(S.dow.frame_thickness), + lightweight = self.options.lightweight) R_text = rect_rel_scale(R, 1, 0.5) draw_str(cr, text = L.day_name[col], rect = R_text, scaling = -1, stroke_rgba = S.dow.fg, align = (2,0), font = S.dow.font, measure = wmeasure) @@ -106,22 +119,27 @@ class CalendarRenderer(_base.CalendarRenderer): else: day_style = S.dom_weekend_phantom if col >= 5 else S.dom_phantom dcell = _base.DayCell(day = (real_dom, col, iso_w), header = holiday_tuple[0], footer = holiday_tuple[1], - theme = (day_style, G.dom, L), show_day_name = False) + theme = (day_style, G.dom, L), show_day_name = False, + lightweight = self.options.lightweight ) dcell.draw(cr, R, self.options.short_daycell_ratio) else: day_style = S.dom_weekend if col >= 5 else S.dom draw_box(cr, rect = R, stroke_rgba = day_style.frame, fill_rgba = day_style.bg, - stroke_width = mm_to_dots(day_style.frame_thickness)) + stroke_width = mm_to_dots(day_style.frame_thickness), + lightweight = self.options.lightweight) dom += 1 iso_w += 1 # draw month title (name) mcolor = S.month.color_map_bg[year%2][month] mcolor_fg = S.month.color_map_fg[year%2][month] - draw_box(cr, rect = R_mb, stroke_rgba = S.month.frame, fill_rgba = mcolor, - stroke_width = mm_to_dots(S.month.frame_thickness)) # title box + draw_box(cr, rect = R_mb, stroke_rgba = None if self.options.lightweight else S.month.frame, + fill_rgba = mcolor, + stroke_width = mm_to_dots(S.month.frame_thickness), + lightweight = self.options.lightweight) # title box draw_box(cr, rect = rect_from_origin(rect), stroke_rgba = S.month.frame, fill_rgba = (), - stroke_width = mm_to_dots(S.month.frame_thickness)) # full box + stroke_width = mm_to_dots(S.month.frame_thickness), + lightweight = self.options.lightweight) # full box R_text = rect_rel_scale(R_mb, 1, 0.5) mshad = None if S.month.text_shadow: diff --git a/lib/xcairo.py b/lib/xcairo.py index dcc2667..774ce3d 100644 --- a/lib/xcairo.py +++ b/lib/xcairo.py @@ -283,7 +283,7 @@ def draw_line(cr, rect, stroke_rgba = None, stroke_width = 1.0): cr.set_line_width(stroke_width) cr.stroke() -def draw_box(cr, rect, stroke_rgba = None, fill_rgba = None, stroke_width = 1.0, shadow = None): +def draw_box(cr, rect, stroke_rgba = None, fill_rgba = None, stroke_width = 1.0, shadow = None, lightweight = False): """draw a box (rectangle) with optional shadow @param cr: cairo context @@ -292,6 +292,7 @@ def draw_box(cr, rect, stroke_rgba = None, fill_rgba = None, stroke_width = 1.0, @param fill_rgba: fill color (set if not C{None}) @param stroke_width: stroke width @param shadow: shadow thickness + @param lightweight: draw only top side if filled """ if (stroke_width <= 0): return draw_shadow(cr, rect, shadow) @@ -303,7 +304,12 @@ def draw_box(cr, rect, stroke_rgba = None, fill_rgba = None, stroke_width = 1.0, cr.close_path() if fill_rgba: set_color(cr, fill_rgba) - cr.fill_preserve() + if lightweight: + cr.fill() + cr.move_to(x, y) + cr.rel_line_to(w, 0) + else: + cr.fill_preserve() if stroke_rgba: set_color(cr, stroke_rgba) cr.set_line_width(stroke_width)