Mrpeachy 12 24 clock dk75mod.module (en)
From Conky PitStop
mrpeachy_12_24_clock_dk75mod.module
Language | English Français |
mrpeachy 12/24 clock multi-clock and time zones modyfication for One4All project
Mrpeachy 12 24 clock dk75mod.module-2.0.tar.gz
--[[drawing a clock in conkyrc by mrpeachy - 12 March 2010 Edited by Sector11 for personal use - 12 Mar 2012 changelog: v2.0 - (21.06.2012) modded beyond recognition to incorporate time-zones, multi-clock design and to use internal One4All functions v1.0 - (04.2012) converted to one4all module by dk75 --]] local modname = ... local M = {} _G[modname] = M package.loaded[modname] = M --[[ ############################################################################### ### SETTINGS ### ############################################################################### --]] local settings_table = { { clock_type = 12, --12 OR 24 clock_tz = "local", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "local", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 250, clock_centery = 150, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, { clock_type = 12, --12 OR 24 clock_tz = "European/Madrid", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "Alicante", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 450, clock_centery = 150, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, { clock_type = 12, --12 OR 24 clock_tz = "Africa/Cape_Town", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "Cape Town", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 650, clock_centery = 150, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, { clock_type = 12, --12 OR 24 clock_tz = "Asia/Dubai", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "Abu Dhabi", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 850, clock_centery = 150, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, { clock_type = 12, --12 OR 24 clock_tz = "Asia/Chongqing", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "Sanya", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 1050, clock_centery = 150, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, { clock_type = 12, --12 OR 24 clock_tz = "Pacific/Auckland", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "Auckland", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 150, clock_centery = 350, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, { clock_type = 12, --12 OR 24 clock_tz = "America/Sao_Paulo", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "Itajaí", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 350, clock_centery = 350, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, { clock_type = 12, --12 OR 24 clock_tz = "America/New_York", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "Miami", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 550, clock_centery = 350, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, { clock_type = 12, --12 OR 24 clock_tz = "Europe/Lisbon", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "Lisbon", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 750, clock_centery = 350, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, { clock_type = 12, --12 OR 24 clock_tz = "Europe/Paris", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "Lorient", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 950, clock_centery = 350, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, { clock_type = 12, --12 OR 24 clock_tz = "Europe/Dublin", --check tzselect in BASH/SH terminal to see what TIMEZONE to set for desired location - set "local" for a local time clock_label = "Galway", clock_label_color = '0xffffff', clock_label_alpha = 1, --CLOCK SETTINGS clock_radius = 90, clock_centerx = 1150, clock_centery = 350, -- SET MARKS number_marks = 12, --how many marks around edge m_length = 10, --set mark length m_width = 3, --set mark line width m_cap = CAIRO_LINE_CAP_ROUND, --set mark line cap type m_color = '0x000000', --set mark color [black = 0x000000] m_alpha = 1, --set mark alpha [full opaque = 1] --SET BORDER OPTIONS clock_border_width = 2, --set clock border width c_color = '0x000000', --set color for clock border [white = 0xffffff] c_alpha = 1, --set alpha for clock border [50% transparent = 0.5] b_to_m = 5, --gap from clock border to hour marks --SECONDS HAND SETUP sh_length = 90, --set length of seconds hand sh_width = 1, --set hand width sh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap sh_color = '0xff0000', --set seconds hand color [red = 0xff0000] sh_alpha = 1, --set seconds hand alpha --MINUTE HAND SETUP mh_length = 80, --set length of minutes hand mh_width = 2, --set hand width mh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap mh_color = '0x000000', --set minute hand color [green = 0x00ff00] mh_alpha = 1, --set minute hand alpha --HOUR HAND SETUP hh_length = 70, --set length of hour hand hh_width = 4, --set hand width hh_cap = CAIRO_LINE_CAP_ROUND, --set hand line cap hh_color = '0x000000', --set hour hand color [blue = 0x0000ff] hh_alpha = 1, --set hour hand alpha }, } --[[ ############################################################################### ### END OF SETTINGS ### ############################################################################### --]] function M.label(x, y, radius, text, color, alpha) cairo_select_font_face(cr, "DejaVu Sans Mono", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD) cairo_set_font_size(cr, math.floor(radius/5)) cairo_set_source_rgba(cr, one4all_cairo.rgb2rgba(color, alpha)) local extents = cairo_text_extents_t:create() -- initialize text_extents structure (generic, a must be for following functions) cairo_text_extents(cr, text, extents) cairo_move_to(cr, x-extents.width/2, y+radius+math.floor(radius/4)) cairo_show_text(cr, text) cairo_stroke(cr) end function M.hands(x, y, angle, length, styleCAP, styleWIDTH, color, alpha) --set our starting line coordinates, the center of the circle cairo_move_to (cr, x, y) --describe the line we will draw cairo_line_to (cr,one4all_main.pointATcircle(x, y, angle, length)) --set up line attributes and draw line cairo_set_line_width (cr, styleWIDTH) cairo_set_source_rgba (cr, one4all_cairo.rgb2rgba(color, alpha)) cairo_set_line_cap (cr, styleCAP) cairo_stroke (cr) end function M.clock(t) --DRAWING CODE --draw border cairo_set_source_rgba (cr,one4all_cairo.rgb2rgba(t.c_color, t.c_alpha)) cairo_set_line_width (cr,t.clock_border_width) cairo_arc (cr,t.clock_centerx,t.clock_centery,t.clock_radius,0,2*math.pi) cairo_stroke (cr) --DRAW MARKS --stuff that can be moved outside of the loop, needs only be set once --calculate end and start radius for marks local m_end_rad=t.clock_radius-t.b_to_m local m_start_rad=m_end_rad-t.m_length cairo_set_line_cap (cr, t.m_cap) --set line cap type cairo_set_line_width (cr,t.m_width) --set line width cairo_set_source_rgba (cr,one4all_cairo.rgb2rgba(t.m_color, t.m_alpha)) --set color and alpha for marks --start for loop local i, angle = nil for i=0, t.number_marks-1 do angle = i*(360/t.number_marks)-90 cairo_move_to(cr, one4all_main.pointATcircle(t.clock_centerx, t.clock_centery, angle, m_start_rad)) cairo_line_to(cr, one4all_main.pointATcircle(t.clock_centerx, t.clock_centery, angle, m_end_rad)) cairo_stroke (cr) end --end for loop local h_angle, m_angle, s_angle = one4all_main.time2angle(12, t.clock_tz) --DRAW HOUR HAND ############################ M.hands(t.clock_centerx, t.clock_centery, h_angle, t.hh_length, t.hh_cap, t.hh_width, t.hh_color, t.hh_alpha) --DRAW MINUTES HAND ############################ M.hands(t.clock_centerx, t.clock_centery, m_angle, t.mh_length, t.mh_cap, t.mh_width, t.mh_color, t.mh_alpha) --DRAW SECOND HAND ############################# M.hands(t.clock_centerx, t.clock_centery, s_angle, t.sh_length, t.sh_cap, t.sh_width, t.sh_color, t.sh_alpha) --Draw label for a clock M.label(t.clock_centerx, t.clock_centery, t.clock_radius, t.clock_label, t.clock_label_color, t.clock_label_alpha) end --[[ ############################################################################### ### MODULE MAIN LOOP ### ############################################################################### --]] function M.main() for i in pairs(settings_table) do M.clock(settings_table[i]) end end