mirror of
https://github.com/oDinZu/callirhoe.git
synced 2025-02-22 00:04:52 -05:00
lighweight mode support
relative options: --lightweight --lw-inner-padding
This commit is contained in:
parent
d165ba827c
commit
0aed16c504
5
AUTHORS
5
AUTHORS
@ -11,8 +11,9 @@ George M. Tzoumas <geortz@gmail.com>
|
|||||||
|
|
||||||
CONTRIBUTORS
|
CONTRIBUTORS
|
||||||
------------
|
------------
|
||||||
Neels Hofmeyr <neels@hofmeyr.de>
|
Neels Hofmeyr <neels@hofmeyr.de> -- sparse layout
|
||||||
Nick Kavalieris <ph4ntome@gmail.com>
|
Nick Kavalieris <ph4ntome@gmail.com> -- archlinux package
|
||||||
|
wrybread@github -- ideas for lightweight mode
|
||||||
|
|
||||||
LANGUAGE DEFINITIONS
|
LANGUAGE DEFINITIONS
|
||||||
--------------------
|
--------------------
|
||||||
|
@ -84,12 +84,13 @@ class DayCell(object):
|
|||||||
@type show_day_name: bool
|
@type show_day_name: bool
|
||||||
@ivar show_day_name: whether day name is displayed
|
@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.day = day
|
||||||
self.header = header
|
self.header = header
|
||||||
self.footer = footer
|
self.footer = footer
|
||||||
self.theme = theme
|
self.theme = theme
|
||||||
self.show_day_name = show_day_name
|
self.show_day_name = show_day_name
|
||||||
|
self.lightweight = lightweight
|
||||||
|
|
||||||
def _draw_short(self, cr, rect):
|
def _draw_short(self, cr, rect):
|
||||||
"""render the day cell in short mode"""
|
"""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
|
day_of_month, day_of_week, week_of_year = self.day
|
||||||
S_bg = S.bg
|
S_bg = S.bg
|
||||||
#if day_of_week >= 5 and (week_of_year & 1): S_bg = color_scale(S.bg,0.9)
|
#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])
|
R = rect_rel_scale(rect, G.size[0], G.size[1])
|
||||||
if self.show_day_name:
|
if self.show_day_name:
|
||||||
Rdom, Rdow = rect_hsplit(R, *G.mw_split)
|
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
|
day_of_month, day_of_week, week_of_year = self.day
|
||||||
S_bg = S.bg
|
S_bg = S.bg
|
||||||
#if day_of_week >= 5 and (week_of_year & 1): S_bg = tuple(reversed(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)
|
R1, Rhf = rect_hsplit(rect, *G.hf_hsplit)
|
||||||
if self.show_day_name:
|
if self.show_day_name:
|
||||||
R = rect_rel_scale(R1, G.size[2], G.size[3])
|
R = rect_rel_scale(R1, G.size[2], G.size[3])
|
||||||
|
@ -28,6 +28,10 @@ import _base
|
|||||||
parser = _base.get_parser(__name__)
|
parser = _base.get_parser(__name__)
|
||||||
parser.add_option("--phantom-days", action="store_true", default=False,
|
parser.add_option("--phantom-days", action="store_true", default=False,
|
||||||
help="show days from previous/next month in the unused cells")
|
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):
|
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
|
"""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:
|
if self.options.month_with_year:
|
||||||
mmeasure += 'A'*(len(str(year))+1)
|
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)
|
# 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_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
|
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
|
# draw day names
|
||||||
for col in range(7):
|
for col in range(7):
|
||||||
R = R_dnc.item(col)
|
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,
|
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)
|
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,
|
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)
|
align = (2,0), font = S.dow.font, measure = wmeasure)
|
||||||
@ -106,22 +119,27 @@ class CalendarRenderer(_base.CalendarRenderer):
|
|||||||
else:
|
else:
|
||||||
day_style = S.dom_weekend_phantom if col >= 5 else S.dom_phantom
|
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],
|
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)
|
dcell.draw(cr, R, self.options.short_daycell_ratio)
|
||||||
else:
|
else:
|
||||||
day_style = S.dom_weekend if col >= 5 else S.dom
|
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,
|
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
|
dom += 1
|
||||||
iso_w += 1
|
iso_w += 1
|
||||||
|
|
||||||
# draw month title (name)
|
# draw month title (name)
|
||||||
mcolor = S.month.color_map_bg[year%2][month]
|
mcolor = S.month.color_map_bg[year%2][month]
|
||||||
mcolor_fg = S.month.color_map_fg[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,
|
draw_box(cr, rect = R_mb, stroke_rgba = None if self.options.lightweight else S.month.frame,
|
||||||
stroke_width = mm_to_dots(S.month.frame_thickness)) # title box
|
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 = (),
|
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)
|
R_text = rect_rel_scale(R_mb, 1, 0.5)
|
||||||
mshad = None
|
mshad = None
|
||||||
if S.month.text_shadow:
|
if S.month.text_shadow:
|
||||||
|
@ -283,7 +283,7 @@ def draw_line(cr, rect, stroke_rgba = None, stroke_width = 1.0):
|
|||||||
cr.set_line_width(stroke_width)
|
cr.set_line_width(stroke_width)
|
||||||
cr.stroke()
|
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
|
"""draw a box (rectangle) with optional shadow
|
||||||
|
|
||||||
@param cr: cairo context
|
@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 fill_rgba: fill color (set if not C{None})
|
||||||
@param stroke_width: stroke width
|
@param stroke_width: stroke width
|
||||||
@param shadow: shadow thickness
|
@param shadow: shadow thickness
|
||||||
|
@param lightweight: draw only top side if filled
|
||||||
"""
|
"""
|
||||||
if (stroke_width <= 0): return
|
if (stroke_width <= 0): return
|
||||||
draw_shadow(cr, rect, shadow)
|
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()
|
cr.close_path()
|
||||||
if fill_rgba:
|
if fill_rgba:
|
||||||
set_color(cr, 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:
|
if stroke_rgba:
|
||||||
set_color(cr, stroke_rgba)
|
set_color(cr, stroke_rgba)
|
||||||
cr.set_line_width(stroke_width)
|
cr.set_line_width(stroke_width)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user