Bonjour daniel38100,
voici le script chronographe modifié, avec une petite perte de poids 😉
--[[ 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
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="monofur",
taille=12,
text_color=0xFFFFFF,
text_alpha=1,
text_color_current=0xFF0000,
text_alpha_current=1,
point_color=0xFFFFFF,
point_alpha=1,
point_color_current=0xFF0000,
point_alpha_current=1,
hand_color=0xFFFFFF,
hand_alpha=0.7,
center_x=175,
center_y=90,
text_radius=45,
point_radius=32,
hand_gap=0,
hand_larg=1,
hand_length=28,
point_ray=0.5
},
{text={""},
nb="",
formule='jour_num',
police="Century Schoolbook",
taille=10,
text_color=0xFFFFFF,
text_alpha=1,
text_color_current=0xFF0000,
text_alpha_current=1,
point_color=0xFFFFFF,
point_alpha=1,
point_color_current=0xFF0000,
point_alpha_current=1,
hand_color=0xFFFFFF,
hand_alpha=0.7,
center_x=90,
center_y=175,
text_radius=45,
point_radius=35,
hand_gap=0,
hand_larg=1,
hand_length=28,
point_ray=0.5
},
{text={"Jan","Fév","Mar","Avr","Mai","Jui","Jul","Aôu","Sep","Oct","Nov","Déc"},
nb="",
formule='mois',
police="monofur",
taille=12,
text_color=0xFFFFFF,
text_alpha=1,
text_color_current=0xFF0000,
text_alpha_current=1,
point_color=0xFFFFFF,
point_alpha=1,
point_color_current=0xFF0000,
point_alpha_current=1,
hand_color=0xFFFFFF,
hand_alpha=0.7,
center_x=260,
center_y=175,
text_radius=45,
point_radius=32,
point_ray=1,
hand_gap=0,
hand_larg=1,
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"},
hour_24=true,
nb=12*3600, --12 or 24 *3600
formule='heure',
police="Tibetan Machine Uni",
taille=13,
text_color=0xFFFFFF,
text_alpha=1,
text_color_current=0xFFFF00,
text_alpha_current=1,
point_color=0xFFFFFF,
point_alpha=1,
point_color_current=0xFFFF00,
point_alpha_current=1,
hand_color=0xFFFFFF,
hand_alpha=0.7,
center_x=175,
center_y=175,
text_radius=165,
point_radius=150,
hand_gap=0,
hand_length=110,
hand_larg=3,
point_ray=1
},
{text={"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""},
nb=3600,
formule='minute',
police="monofur",
taille=9,
text_color=0xFFFFFF,
text_alpha=1,
text_color_current=0xF00000,
text_alpha_current=1,
point_color=0xFFFFFF,
point_alpha=1,
point_color_current=0xF00000,
point_alpha_current=1,
hand_color=0xFFFFFF,
hand_alpha=0.7,
center_x=175,
center_y=175,
text_radius=170,
point_radius=150,
point_ray=0,
hand_gap=0,
hand_larg=2,
hand_length=135
},
{text={"","01","02","03","04","","06","07","08","09","","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=60,
formule='secondes',
police="cmr10",
taille=10,
text_color=0xFFFFFF,
text_alpha=1,
text_color_current=0xFFFFFF,
text_alpha_current=1,
point_color=0xFFFFFF,
point_alpha=1,
point_color_current=0xFF0000,
point_alpha_current=1,
hand_color=0xFF0000,
hand_alpha=0.4,
center_x=175,
center_y=175,
text_radius=160,
point_radius=150,
point_ray=0.5,
hand_gap=150,
hand_larg=4,
hand_length=165,
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
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

j'ai ajouter une variable nommée "progressif", elle a deux valeurs possibles, true ou false. si rien n'est indiqué elle est considérée comme false.