@ loutch,
Voici le code modifié, avec ajout d'une variable
decalage, actuellement j'ai réglé ce décalage horaire a -1 (pour moins 1 heure).
clock.lua
--[[ multiple analogue clocks by Didier-T (forum Ubuntu.fr) - 25 Nov 2012
Basé sur le travail de mrpeachy et Sector11
26 Nov 2012 - ajout hand_gap et hand_larg Didier-T
01 Dec 2012 - correction bug nb_jour Décembre Didier-T
02 Dec 2012 - ajout mode 24 heures Didier-T
09 Mar 2014 - ajout alumage progréssif des points de l'horloge
30 Avr 2014 - ajout fonction décalage horaire, pour ajout cadrant ville
use in conkyrc
lua_load /path/Chronograph.lua
lua_draw_hook_pre main
TEXT
]]
require 'cairo'
--Position et taille horloge
local init={
{text={"Dim","Lun","Mar","Mer","Jeu","Ven","Sam"},
nb=7*24,
formule='jour',
police="URW Chancery L",
taille=11,
text_color=0xffffff,
text_alpha=0.4,
text_color_current=0xffffff,
text_alpha_current=1,
point_color=0xffffff,
point_alpha=0.4,
point_color_current=0xffffff,
point_alpha_current=1,
hand_color=0xffff00,
hand_alpha=1,
center_x=175,
center_y=105,
text_radius=30,
point_radius=20,
hand_gap=0,
hand_larg=1.5,
hand_length=18,
point_ray=0.5
},
{text={""},
nb="",
formule='jour_num',
police="URW Chancery L",
taille=10,
text_color=0xffffff,
text_alpha=0.4,
text_color_current=0xffffff,
text_alpha_current=1,
point_color=0xffffff,
point_alpha=0.4,
point_color_current=0xffffff,
point_alpha_current=1,
hand_color=0xffff00,
hand_alpha=1,
center_x=110,
center_y=175,
text_radius=35,
point_radius=28,
hand_gap=0,
hand_larg=1.5,
hand_length=27,
point_ray=0.5
},
{text={"Jan","Fév","Mar","Avr","Mai","Jui","Jul","Aôu","Sep","Oct","Nov","Déc"},
nb="",
formule='mois',
police="URW Chancery L",
taille=10,
text_color=0xffffff,
text_alpha=0.4,
text_color_current=0xffffff,
text_alpha_current=1,
point_color=0xffffff,
point_alpha=0.4,
point_color_current=0xffffff,
point_alpha_current=1,
hand_color=0xffff00,
hand_alpha=1,
center_x=235,
center_y=175,
text_radius=35,
point_radius=26,
point_ray=1,
hand_gap=0,
hand_larg=1.5,
hand_length=25
},
{text={"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"},
hour_24=true,
nb=12*3600, --12 or 24 *3600
formule='heure',
police="URW Chancery L",
taille=22,
text_color=0xffffff,
text_alpha=0.4,
text_color_current=0x1540fc,
text_alpha_current=1,
point_color=0xffffff,
point_alpha=0.4,
point_color_current=0x1540fc,
point_alpha_current=1,
hand_color=0x1540fc,
hand_alpha=1,
center_x=173,
center_y=175,
text_radius=145,
point_radius=148,
hand_gap=0,
hand_length=75,
hand_larg=3.5,
point_ray=0
},
{text={"","1","2","3","4","","6","7","8","9","","11","12","13","14","","16","17","18","19","","21","22","23","24","","26","27","28","29","","31","32","33","34","","36","37","38","39","","41","42","43","44","","46","47","48","49","","51","52","53","54","","56","57","58","59"},
nb=3600,
formule='minute',
police="URW Chancery L",
taille=12,
text_color=0xffffff,
text_alpha=0.4,
text_color_current=0xff0000,
text_alpha_current=1,
point_color=0xffffff,
point_alpha=0.4,
point_color_current=0xff0000,
point_alpha_current=1,
hand_color=0xff0000,
hand_alpha=1,
center_x=174,
center_y=175,
text_radius=140,
point_radius=130,
point_ray=0.5,
hand_gap=0,
hand_larg=3.5,
hand_length=100
},
{text={"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"},
nb=60,
formule='secondes',
police="URW Chancery L",
taille=9,
text_color=0xffffff,
text_alpha=0.4,
text_color_current=0xffffff,
text_alpha_current=1,
point_color=0xffffff,
point_alpha=0.4,
point_color_current=0xffffff,
point_alpha_current=1,
hand_color=0xffff00,
hand_alpha=1,
center_x=175,
center_y=175,
text_radius=121,
point_radius=112,
point_ray=0.4,
hand_gap=0,
hand_larg=1.5,
hand_length=110,
progressif=true
},
-- petite montre du bas
{text={"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"},
hour_24=false,
nb=12*3600, --12 or 24 *3600
formule='heure',
decalage=-1,
police="URW Chancery L",
taille=10,
text_color=0xffffff,
text_alpha=0.4,
text_color_current=0xffffff,
text_alpha_current=0.4,
point_color=0xffffff,
point_alpha=0.4,
point_color_current=0xffffff,
point_alpha_current=0.4,
hand_color=0xffff00,
hand_alpha=1,
center_x=175,
center_y=245,
text_radius=35,
point_radius=28,
hand_gap=0,
hand_length=20,
hand_larg=1.5,
point_ray=0
},
{text={"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"},
nb=3600,
formule='minute',
police="URW Chancery L",
taille=9,
text_color=0xa8a8a8,
text_alpha=0,
text_color_current=0xffffff,
text_alpha_current=0,
point_color=0xffffff,
point_alpha=0,
point_color_current=0xffffff,
point_alpha_current=0,
hand_color=0xffff00,
hand_alpha=1,
center_x=175,
center_y=245,
text_radius=25,
point_radius=20,
point_ray=0,
hand_gap=0,
hand_larg=1.5,
hand_length=28
},
{text={"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"},
nb=60,
formule='secondes',
police="URW Chancery L",
taille=9,
text_color=0xffffff,
text_alpha=0,
text_color_current=0xffffff,
text_alpha_current=0,
point_color=0xffffff,
point_alpha=0,
point_color_current=0xffffff,
point_alpha_current=0,
hand_color=0xffffff,
hand_alpha=1,
center_x=175,
center_y=245,
text_radius=30,
point_radius=20,
point_ray=0.5,
hand_gap=0,
hand_larg=0,
hand_length=30,
progressif=true
},
}
function conky_main()
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
local cr = cairo_create(cs)
local extents=cairo_text_extents_t:create()
tolua.takeownership(extents)
local h, min, sec=time()
local jour, jour_num, mois, nb_jour=date()
if tonumber(conky_parse('${updates}'))>3 then
for i in pairs(init) do
draw(cr, extents, init[i], h, min, sec, jour, jour_num, mois, nb_jour)
end
end
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
collectgarbage()
end
function draw(cr, extents, value, h, min, sec, jour, jour_num, mois, nb_jour)
local function affichage(cr, extents, j, valeur, value, text, nb)
if value.progressif == nil then
value.progressif=false
end
if value.progressif==true and j<=valeur then
texte(value.police, value.taille, text, nb, value.text_radius, value.center_x, value.center_y, value.text_color_current, value.text_alpha_current, j, extents, cr)
point(nb, value.point_radius, value.center_x, value.center_y, value.point_color_current, value.point_alpha_current, j, cr, value.point_ray)
elseif value.progressif==false and j==valeur then
texte(value.police, value.taille, text, nb, value.text_radius, value.center_x, value.center_y, value.text_color_current, value.text_alpha_current, j, extents, cr)
point(nb, value.point_radius, value.center_x, value.center_y, value.point_color_current, value.point_alpha_current, j, cr, value.point_ray)
else
texte(value.police, value.taille, text, nb, value.text_radius, value.center_x, value.center_y, value.text_color, value.text_alpha, j, extents, cr)
point(nb, value.point_radius, value.center_x, value.center_y, value.point_color, value.point_alpha, j, cr, value.point_ray)
end
end
local pos
local nb=tonumber(table.getn(value.text))
cairo_select_font_face (cr, value.police, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, value.taille)
-- Section Horloge
if value.formule=="heure" then
if value.decalage~=nil then
h=h+tonumber(value.decalage)
end
local text
nb=value.nb/3600
if nb==24 then h=tonumber(os.date("%H")) end
pos=heure(h, min, sec)
for i=1, nb do
local j=i-1
if value.hour_24==true then
if tonumber(os.date("%H"))<nb then
text=value.text[i]
else
text=value.text[i+12]
end
else
text=value.text[i]
end
affichage(cr, extents, j, h, value, text, nb)
end
elseif value.formule=="minute" then
pos=minute(min, sec)
for i=1, nb do
local j=i-1
local text=value.text[i]
affichage(cr, extents, j, min, value, text, nb)
end
elseif value.formule=="secondes" then
pos=sec
for i=1, nb do
local j=i-1
local text=value.text[i]
affichage(cr, extents, j, sec, value, text, nb)
end
-- Section date
elseif value.formule=="mois" then
value.nb, pos=month()
for i=1, nb do
local j=i-1
local text=value.text[i]
affichage(cr, extents, j, mois-1, value, text, nb)
end
elseif value.formule=="jour_num" then
value.nb=nb_jour*24
nb=nb_jour
pos=day(jour-1)
for i=1, nb_jour do
if math.mod(i, 2) == 0 then
text=string.format("%02d",i)
else
text=""
end
local j=i-1
affichage(cr, extents, j, jour-1, value, text, nb)
end
elseif value.formule=="jour" then
pos=(jour_num*24)+tonumber(os.date("%H"))
for i=1, nb do
local j=i-1
local text=value.text[i]
affichage(cr, extents, j, jour_num, value, text, nb)
end
-- Horloge avec personnalisée (non utilisé pour le moment)
else
pos=tonumber(conky_parse(value.formule))
for i=1, nb do
local j=i-1
local text=value.text[i]
if tonumber(text)==pos then
texte(value.police, value.taille, text, nb, value.text_radius, value.center_x, value.center_y, value.text_color_current, value.text_alpha_current, i, extents, cr)
point(nb, value.point_radius, value.center_x, value.center_y, value.point_color_current, value.point_alpha_current, i, cr, value.point_ray)
else
texte(value.police, value.taille, text, nb, value.text_radius, value.center_x, value.center_y, value.text_color, value.text_alpha, i, extents, cr)
point(nb, value.point_radius, value.center_x, value.center_y, value.point_color, value.point_alpha, i, cr, value.point_ray)
end
end
end
hand(pos, value.nb, value.text_radius, value.hand_length, value.hand_gap, value.hand_larg, value.center_x, value.center_y, value.hand_color, value.hand_alpha, cr)
end
function date()
local nb_jour
local jour=tonumber(os.date("%d"))
local jour_num=tonumber(os.date("%w"))
local mois=tonumber(os.date("%m"))
if mois==12 then
nb_jour=31
else
nb_jour=tonumber(conky_parse("${exec date --date '1 month' +%j}"))-tonumber(conky_parse("${exec date +%j}"))
end
return jour, jour_num, mois, nb_jour
end
function day(jour)
local hjour=(jour*24)+tonumber(os.date("%H"))
return hjour
end
function month()
local nb_jours_annee=tonumber(conky_parse("${exec echo $(date --date '31 Dec' +%j)}"))
local jour_annee=tonumber(conky_parse("${exec echo $(date +%j)}"))
return nb_jours_annee, jour_annee
end
function time()
local h=tonumber(os.date("%I"))
local min=tonumber(os.date("%M"))
local sec=tonumber(os.date("%S"))
return h, min, sec
end
function heure(h, min, sec)
local hs=(h*3600)+(min*60)+sec
return hs
end
function minute(min, sec)
local m=(min*60)+sec
return m
end
function rgb_to_r_g_b(col,alp)
return ((col / 0x10000) % 0x100) / 255, ((col / 0x100) % 0x100) / 255, (col % 0x100) / 255, alp
end
function texte(police, taille, text, nb, radius, center_x, center_y, color, alpha, i, extents, cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b(color,alpha))
local point=(math.pi/180)*((360/nb)*(i))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_text_extents(cr,text,extents)
local width=extents.width
local height=extents.height
cairo_move_to(cr,center_x+x-(width/2),center_y+y+(height/2))
cairo_show_text (cr, text)
cairo_stroke (cr)
end
function point(nb, radius, center_x, center_y, color, alpha, i, cr, ray)
cairo_set_source_rgba (cr,rgb_to_r_g_b(color,alpha))
local point=(math.pi/180)*((360/nb)*(i))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,ray,0,2*math.pi)
cairo_stroke (cr)
end
function hand(pos, nb, radius, hand_length, hand_gap, largeur, center_x, center_y, color, alpha, cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b(color,alpha))
local point=(math.pi/180)*((360/nb)*(pos))
local x_gap=0+hand_gap*(math.sin(point))
local y_gap=0-hand_gap*(math.cos(point))
local x=0+hand_length*(math.sin(point))
local y=0-hand_length*(math.cos(point))
cairo_move_to (cr,center_x+x_gap,center_y+y_gap)
cairo_line_to (cr,center_x+x,center_y+y)
cairo_set_line_width (cr,largeur)
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND)
cairo_stroke (cr)
end
A+,
Didier
P.S. : ne t'excuse pas de modifier ce qui existe, c'est fait pour 😉
et n'hésite pas a partager le résultat de tes "modifications", ça me plais plus que l'original 🙂