#951 Le 01/09/2011, à 20:44
- Levi59
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
je crois que c'est sh le problème. lance avec bash ou en rendant le script exécutable et en le lançant via :
./test2.sh
OU
bash test2.sh
Pour ton code, le probleme vient du calcul. l'interpreteur ne sait pas calculer des nombres décimaux par défaut. il faut utiliser "bc".
Hors ligne
#952 Le 01/09/2011, à 20:52
- shamen456
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
@levi59: merci... ton script marche au poil...maintenant il va falloir représenter ça sur l’écran...
Hors ligne
#953 Le 01/09/2011, à 21:31
- Levi59
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
pour la partie lua j'ai jamais fait. Par contre je crois qu'il y a un sujet conky pour lua sur le forum... @ voir.
Hors ligne
#954 Le 01/09/2011, à 21:48
- sunkart
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
Je pensais à Levi59 quand je disais que les pros du script pouvait t'aider, je ne m'étais pas tromper
Cyril
Hors ligne
#955 Le 02/09/2011, à 09:01
- shamen456
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
@levi59: j'ai légèrement adapté ton script en remplaçant FRXX1949 par $1 afin de l’exécuter avec comme paramètre la localisation...ça sera plus pratique pour la suite.
j'ai fait des tests avec 20 valeurs dans le fichier. en prenant des mesures toutes les 4hrs, ca donnerait un historique de 3 jours pour ceux dont la machine tourne en continu...
(je ne sais pas encore combien de valeurs seront nécessaires pour avoir un affichage correct et relevant, toutes les idées sont les bienvenues [relevé toutes les heures, toutes les 4Hrs, 12Hrs, 1xpar jour...])
je me plonge dans le lua pour essayer d'afficher qqch....mais ici aussi un expert serait le bienvenu...
j'ai bidouillé un graphe en juxtaposant 20 colonnes (sur base du script bargraph de wlourf)et ça donne ceci...
bargraphpression.lua
--[[ BARGRAPH WIDGET
v2.1 by wlourf (07 Jan. 2011)
this widget draws a bargraph with different effects
http://u-scripts.blogspot.com/2010/07/bargraph-widget.html
To call the script in a conky, use, before TEXT
lua_load /path/to/the/script/bargraph.lua
lua_draw_hook_pre main_rings
and add one line (blank or not) after TEXT
Parameters are :
3 parameters are mandatory
name - the name of the conky variable to display, for example for {$cpu cpu0}, just write name="cpu"
arg - the argument of the above variable, for example for {$cpu cpu0}, just write arg="cpu0"
arg can be a numerical value if name=""
max - the maximum value the above variable can reach, for example, for {$cpu cpu0}, just write max=100
Optional parameters:
x,y - coordinates of the starting point of the bar, default = middle of the conky window
cap - end of cap line, ossibles values are r,b,s (for round, butt, square), default="b"
http://www.cairographics.org/samples/set_line_cap/
angle - angle of rotation of the bar in degress, default = 0 (i.e. a vertical bar)
set to 90 for an horizontal bar
skew_x - skew bar around x axis, default = 0
skew_y - skew bar around y axis, default = 0
blocks - number of blocks to display for a bar (values >0) , default= 10
height - height of a block, default=10 pixels
width - width of a block, default=20 pixels
space - space between 2 blocks, default=2 pixels
angle_bar - this angle is used to draw a bar on a circular way (ok, this is no more a bar !) default=0
radius - for cicular bars, internal radius, default=0
with radius, parameter width has no more effect.
Colours below are defined into braces {colour in hexadecimal, alpha}
fg_colour - colour of a block ON, default= {0x00FF00,1}
bg_colour - colour of a block OFF, default = {0x00FF00,0.5}
alarm - threshold, values after this threshold will use alarm_colour colour , default=max
alarm_colour - colour of a block greater than alarm, default=fg_colour
smooth - (true or false), create a gradient from fg_colour to bg_colour, default=false
mid_colour - colours to add to gradient, with this syntax {position into the gradient (0 to1), colour hexa, alpha}
for example, this table {{0.25,0xff0000,1},{0.5,0x00ff00,1},{0.75,0x0000ff,1}} will add
3 colurs to gradient created by fg_colour and alarm_colour, default=no mid_colour
led_effect - add LED effects to each block, default=no led_effect
if smooth=true, led_effect is not used
possibles values : "r","a","e" for radial, parallelel, perdendicular to the bar (just try!)
led_effect has to be used with theses colours :
fg_led - middle colour of a block ON, default = fg_colour
bg_led - middle colour of a block OFF, default = bg_colour
alarm_led - middle colour of a block > ALARM, default = alarm_colour
reflection parameters, not avaimable for circular bars
reflection_alpha - add a reflection effect (values from 0 to 1) default = 0 = no reflection
other values = starting opacity
reflection_scale - scale of the reflection (default = 1 = height of text)
reflection_length - length of reflection, define where the opacity will be set to zero
calues from 0 to 1, default =1
reflection - position of reflection, relative to a vertical bar, default="b"
possibles values are : "b","t","l","r" for bottom, top, left, right
draw_me - if set to false, text is not drawn (default = true or 1)
it can be used with a conky string, if the string returns 1, the text is drawn :
example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",
v1.0 (10 Feb. 2010) original release
v1.1 (13 Feb. 2010) numeric values can be passed instead conky stats with parameters name="", arg = numeric_value
v1.2 (28 Feb. 2010) just renamed the widget to bargraph
v1.3 (03 Mar. 2010) added parameters radius & angle_bar to draw the bar in a circular way
v2.0 (12 Jul. 2010) rewrite script + add reflection effects and parameters are now set into tables
v2.1 (07 Jan. 2011) Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation version 3 (GPLv3)
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-- MA 02110-1301, USA.
]]
require 'cairo'
----------------START OF PARAMETERS ----------
function conky_main_bars()
local bars_settings={
{
name="execp",
arg="sed -n '1p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=15,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '2p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=25,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '2p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=35,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '3p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=45,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '4p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=55,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '5p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=65,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '6p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=75,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '7p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=85,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '8p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=95,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '9p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=105,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '10p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=115,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '11p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=125,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '12p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=135,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '13p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=145,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '14p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=155,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '15p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=165,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '16p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=175,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '17p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=185,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '18p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=195,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '19p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=205,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '20p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=215,y=120,
blocks=1,
height=110,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
}
-----------END OF PARAMETERS--------------
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)
cr = cairo_create(cs)
--prevent segmentation error when reading cpu state
if tonumber(conky_parse('${updates}'))>3 then
for i in pairs(bars_settings) do
draw_multi_bar_graph(bars_settings[i])
end
end
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end
function draw_multi_bar_graph(t)
cairo_save(cr)
--check values
if t.draw_me == true then t.draw_me = nil end
if t.draw_me ~= nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end
if t.name==nil and t.arg==nil then
print ("No input values ... use parameters 'name' with 'arg' or only parameter 'arg' ")
return
end
if t.max==nil then
print ("No maximum value defined, use 'max'")
return
end
if t.name==nil then t.name="" end
if t.arg==nil then t.arg="" end
--set default values
if t.min == nil then t.min=0 end
if t.x == nil then t.x = conky_window.width/2 end
if t.y == nil then t.y = conky_window.height/2 end
if t.blocks == nil then t.blocks=10 end
if t.height == nil then t.height=10 end
if t.angle == nil then t.angle=0 end
t.angle = t.angle*math.pi/180
--line cap style
if t.cap==nil then t.cap = "b" end
local cap="b"
for i,v in ipairs({"s","r","b"}) do
if v==t.cap then cap=v end
end
local delta=0
if t.cap=="r" or t.cap=="s" then delta = t.height end
if cap=="s" then cap = CAIRO_LINE_CAP_SQUARE
elseif cap=="r" then
cap = CAIRO_LINE_CAP_ROUND
elseif cap=="b" then
cap = CAIRO_LINE_CAP_BUTT
end
--end line cap style
--if t.led_effect == nil then t.led_effect="r" end
if t.width == nil then t.width=20 end
if t.space == nil then t.space=2 end
if t.radius == nil then t.radius=0 end
if t.angle_bar == nil then t.angle_bar=0 end
t.angle_bar = t.angle_bar*math.pi/360 --halt angle
--colours
if t.bg_colour == nil then t.bg_colour = {0x00FF00,0.5} end
if #t.bg_colour~=2 then t.bg_colour = {0x00FF00,0.5} end
if t.fg_colour == nil then t.fg_colour = {0x00FF00,1} end
if #t.fg_colour~=2 then t.fg_colour = {0x00FF00,1} end
if t.alarm_colour == nil then t.alarm_colour = t.fg_colour end
if #t.alarm_colour~=2 then t.alarm_colour = t.fg_colour end
if t.mid_colour ~= nil then
for i=1, #t.mid_colour do
if #t.mid_colour[i]~=3 then
print ("error in mid_color table")
t.mid_colour[i]={1,0xFFFFFF,1}
end
end
end
if t.bg_led ~= nil and #t.bg_led~=2 then t.bg_led = t.bg_colour end
if t.fg_led ~= nil and #t.fg_led~=2 then t.fg_led = t.fg_colour end
if t.alarm_led~= nil and #t.alarm_led~=2 then t.alarm_led = t.fg_led end
if t.led_effect~=nil then
if t.bg_led == nil then t.bg_led = t.bg_colour end
if t.fg_led == nil then t.fg_led = t.fg_colour end
if t.alarm_led == nil then t.alarm_led = t.fg_led end
end
if t.alarm==nil then t.alarm = t.max end --0.8*t.max end
if t.smooth == nil then t.smooth = false end
if t.skew_x == nil then
t.skew_x=0
else
t.skew_x = math.pi*t.skew_x/180
end
if t.skew_y == nil then
t.skew_y=0
else
t.skew_y = math.pi*t.skew_y/180
end
if t.reflection_alpha==nil then t.reflection_alpha=0 end
if t.reflection_length==nil then t.reflection_length=1 end
if t.reflection_scale==nil then t.reflection_scale=1 end
--end of default values
local function rgb_to_r_g_b(col_a)
return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
end
--functions used to create patterns
local function create_smooth_linear_gradient(x0,y0,x1,y1)
local pat = cairo_pattern_create_linear (x0,y0,x1,y1)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
if t.mid_colour ~=nil then
for i=1, #t.mid_colour do
cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
end
end
return pat
end
local function create_smooth_radial_gradient(x0,y0,r0,x1,y1,r1)
local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
if t.mid_colour ~=nil then
for i=1, #t.mid_colour do
cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
end
end
return pat
end
local function create_led_linear_gradient(x0,y0,x1,y1,col_alp,col_led)
local pat = cairo_pattern_create_linear (x0,y0,x1,y1) ---delta, 0,delta+ t.width,0)
cairo_pattern_add_color_stop_rgba (pat, 0.0, rgb_to_r_g_b(col_alp))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1.0, rgb_to_r_g_b(col_alp))
return pat
end
local function create_led_radial_gradient(x0,y0,r0,x1,y1,r1,col_alp,col_led,mode)
local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
if mode==3 then
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_alp))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))
else
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))
end
return pat
end
local function draw_single_bar()
--this fucntion is used for bars with a single block (blocks=1) but
--the drawing is cut in 3 blocks : value/alarm/background
--not zvzimzblr for circular bar
local function create_pattern(col_alp,col_led,bg)
local pat
if not t.smooth then
if t.led_effect=="e" then
pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
elseif t.led_effect=="a" then
pat = create_led_linear_gradient (t.width/2, 0,t.width/2,-t.height,col_alp,col_led)
elseif t.led_effect=="r" then
pat = create_led_radial_gradient (t.width/2, -t.height/2, 0, t.width/2,-t.height/2,t.height/1.5,col_alp,col_led,2)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
else
if bg then
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.bg_colour))
else
pat = create_smooth_linear_gradient(t.width/2, 0, t.width/2,-t.height)
end
end
return pat
end
local y1=-t.height*pct/100
local y2,y3
if pct>(100*t.alarm/t.max) then
y1 = -t.height*t.alarm/100
y2 = -t.height*pct/100
if t.smooth then y1=y2 end
end
if t.angle_bar==0 then
--block for fg value
local pat = create_pattern(t.fg_colour,t.fg_led,false)
cairo_set_source(cr,pat)
cairo_rectangle(cr,0,0,t.width,y1)
cairo_fill(cr)
cairo_pattern_destroy(pat)
-- block for alarm value
if not t.smooth and y2 ~=nil then
pat = create_pattern(t.alarm_colour,t.alarm_led,false)
cairo_set_source(cr,pat)
cairo_rectangle(cr,0,y1,t.width,y2-y1)
cairo_fill(cr)
y3=y2
cairo_pattern_destroy(pat)
else
y2,y3=y1,y1
end
-- block for bg value
cairo_rectangle(cr,0,y2,t.width,-t.height-y3)
pat = create_pattern(t.bg_colour,t.bg_led,true)
cairo_set_source(cr,pat)
cairo_pattern_destroy(pat)
cairo_fill(cr)
end
end --end single bar
local function draw_multi_bar()
--function used for bars with 2 or more blocks
for pt = 1,t.blocks do
--set block y
local y1 = -(pt-1)*(t.height+t.space)
local light_on=false
--set colors
local col_alp = t.bg_colour
local col_led = t.bg_led
if pct>=(100/t.blocks) or pct>0 then --ligth on or not the block
if pct>=(pcb*(pt-1)) then
light_on = true
col_alp = t.fg_colour
col_led = t.fg_led
if pct>=(100*t.alarm/t.max) and (pcb*pt)>(100*t.alarm/t.max) then
col_alp = t.alarm_colour
col_led = t.alarm_led
end
end
end
--set colors
--have to try to create gradients outside the loop ?
local pat
if not t.smooth then
if t.angle_bar==0 then
if t.led_effect=="e" then
pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
elseif t.led_effect=="a" then
pat = create_led_linear_gradient (t.width/2, -t.height/2+y1,t.width/2,0+t.height/2+y1,col_alp,col_led)
elseif t.led_effect=="r" then
pat = create_led_radial_gradient (t.width/2, y1, 0, t.width/2,y1,t.width/1.5,col_alp,col_led,2)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
else
if t.led_effect=="a" then
pat = create_led_radial_gradient (0, 0, t.radius+(t.height+t.space)*(pt-1),
0, 0, t.radius+(t.height+t.space)*(pt),
col_alp,col_led,3)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
end
else
if light_on then
if t.angle_bar==0 then
pat = create_smooth_linear_gradient(t.width/2, t.height/2, t.width/2,-(t.blocks-0.5)*(t.height+t.space))
else
pat = create_smooth_radial_gradient(0, 0, (t.height+t.space), 0,0,(t.blocks+1)*(t.height+t.space),2)
end
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.bg_colour))
end
end
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
--draw a block
if t.angle_bar==0 then
cairo_move_to(cr,0,y1)
cairo_line_to(cr,t.width,y1)
else
cairo_arc( cr,0,0,
t.radius+(t.height+t.space)*(pt)-t.height/2,
-t.angle_bar -math.pi/2 ,
t.angle_bar -math.pi/2)
end
cairo_stroke(cr)
end
end
local function setup_bar_graph()
--function used to retrieve the value to display and to set the cairo structure
if t.blocks ~=1 then t.y=t.y-t.height/2 end
local value = 0
if t.name ~="" then
value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))
--$to_bytes doesn't work when value has a decimal point,
--https://garage.maemo.org/plugins/ggit/browse.php/?p=monky;a=commitdiff;h=174c256c81a027a2ea406f5f37dc036fac0a524b;hp=d75e2db5ed3fc788fb8514121f67316ac3e5f29f
--http://sourceforge.net/tracker/index.php?func=detail&aid=3000865&group_id=143975&atid=757310
--conky bug?
--value = (conky_parse(string.format('${%s %s}', t.name, t.arg)))
--if string.match(value,"%w") then
-- value = conky_parse(string.format('${to_bytes %s}',value))
--end
else
value = tonumber(t.arg)
end
if value==nil then value =0 end
pct = 100*value/t.max
pcb = 100/t.blocks
cairo_set_line_width (cr, t.height)
cairo_set_line_cap (cr, cap)
cairo_translate(cr,t.x,t.y)
cairo_rotate(cr,t.angle)
local matrix0 = cairo_matrix_t:create()
tolua.takeownership(matrix0)
cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
cairo_transform(cr,matrix0)
--call the drawing function for blocks
if t.blocks==1 and t.angle_bar==0 then
draw_single_bar()
if t.reflection=="t" or t.reflection=="b" then cairo_translate(cr,0,-t.height) end
else
draw_multi_bar()
end
--dot for reminder
--[[
if t.blocks ~=1 then
cairo_set_source_rgba(cr,1,0,0,1)
cairo_arc(cr,0,t.height/2,3,0,2*math.pi)
cairo_fill(cr)
else
cairo_set_source_rgba(cr,1,0,0,1)
cairo_arc(cr,0,0,3,0,2*math.pi)
cairo_fill(cr)
end]]
--call the drawing function for reflection and prepare the mask used
if t.reflection_alpha>0 and t.angle_bar==0 then
local pat2
local matrix1 = cairo_matrix_t:create()
tolua.takeownership(matrix1)
if t.angle_bar==0 then
pts={-delta/2,(t.height+t.space)/2,t.width+delta,-(t.height+t.space)*(t.blocks)}
if t.reflection=="t" then
cairo_matrix_init (matrix1,1,0,0,-t.reflection_scale,0,-(t.height+t.space)*(t.blocks-0.5)*2*(t.reflection_scale+1)/2)
pat2 = cairo_pattern_create_linear (t.width/2,-(t.height+t.space)*(t.blocks),t.width/2,(t.height+t.space)/2)
elseif t.reflection=="r" then
cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,delta+2*t.width,0)
pat2 = cairo_pattern_create_linear (delta/2+t.width,0,-delta/2,0)
elseif t.reflection=="l" then
cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,-delta,0)
pat2 = cairo_pattern_create_linear (-delta/2,0,delta/2+t.width,-0)
else --bottom
cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(t.height+t.space)*(t.reflection_scale+1)/2)
pat2 = cairo_pattern_create_linear (t.width/2,(t.height+t.space)/2,t.width/2,-(t.height+t.space)*(t.blocks))
end
end
cairo_transform(cr,matrix1)
if t.blocks==1 and t.angle_bar==0 then
draw_single_bar()
cairo_translate(cr,0,-t.height/2)
else
draw_multi_bar()
end
cairo_set_line_width(cr,0.01)
cairo_pattern_add_color_stop_rgba (pat2, 0,0,0,0,1-t.reflection_alpha)
cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
if t.angle_bar==0 then
cairo_rectangle(cr,pts[1],pts[2],pts[3],pts[4])
end
cairo_clip_preserve(cr)
cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
cairo_stroke(cr)
cairo_mask(cr,pat2)
cairo_pattern_destroy(pat2)
cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
end --reflection
pct,pcb=nil
end --setup_bar_graph()
--start here !
setup_bar_graph()
cairo_restore(cr)
end
bon conky à tous...
Dernière modification par shamen456 (Le 02/09/2011, à 16:23)
Hors ligne
#956 Le 02/09/2011, à 21:36
- shamen456
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
Bonjour à tous...
Grâce au script bash de levi59 et aux scripts lua de wlourf,
je crois qu'on arrive finalement a quelque chose de pas trop mal...
les nouvelles valeurs apparaissent sur la droite et "poussent" les anciennes valeurs vers la gauche
voici le conky pour appeler les différents éléments :
# Use Xft?
use_xft yes
xftfont DejaVu Sans:size=10
xftalpha 0.8
text_buffer_size 2048
# Update interval in seconds
update_interval 1
# This is the number of times Conky will update before quitting.
# Set to zero to run forever.
total_run_times 0
# Create own window instead of using desktop (required in nautilus)
own_window yes
own_window_transparent yes
own_window_type override
own_window_class conky
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
background yes
# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes
# Minimum size of text area
minimum_size 230 200
#maximum_width 200
# Draw shades?
draw_shades no
# Draw outlines?
draw_outline no
# Draw borders around text
draw_borders no
# Stippled borders?
stippled_borders 0
# border margins
border_inner_margin 5
# border width
border_width 1
# Default colors and also border colors
default_color black
default_shade_color black
default_outline_color black
own_window_colour black
color0 C00000 #D16241 #aujourd'hui
color1 0000FF #B1ADA7 #semaine
color2 303030 #167AAB #WE et jours/mois
# Text alignment, other possible values are commented
#alignment top_left
alignment top_right
#alignment bottom_left
#alignment bottom_right
# Gap between borders of screen and text
# same thing as passing -x at command line
gap_x 620
gap_y 90
# Subtract file system buffers from used memory?
no_buffers yes
# set to yes if you want all text to be in uppercase
uppercase no
# number of cpu samples to average
# set to 1 to disable averaging
cpu_avg_samples 10
# number of net samples to average
# set to 1 to disable averaging
net_avg_samples 10
# Force UTF8? note that UTF8 support required XFT
override_utf8_locale yes
# Add spaces to keep things from moving about? This only affects certain objects.
use_spacer none
short_units yes
# -- Lua Load -- #
# SET THE PATH TO THE SCRIPT HERE
lua_load ~/.conky/bargraph/bargraphpression.lua
lua_draw_hook_pre main_bars
lua_load ~/.conky/bargraph/textpression.lua
lua_draw_hook_post draw_text
#LEAVE AT LEAST ONE LINE, BLANK OR NOT AFTER TEXT
TEXT
${image ./pix/bigpanel2.png -s 225x180 -p +0,-2}${execi 14400 bash ./.conky/bargraph/pression.sh BEXX0006}
14400 correspond à une actualisation toute les 4 heures, adaptez le code de localisation à votre ville...
le script bash pression.sh [merci à Levi59] (il crée deux fichiers log, un pour les valeurs à afficher et un pour les textes à afficher)
#!/bin/bash
# si le fichier contient plus de XX valeurs (première = plus vieille)
#supprimer première valeur
[[ -f ListePressionAdapt.log ]] && {
[[ $(wc -l < ListePressionAdapt.log) -eq 20 ]] && sed -i '1d' ListePressionAdapt.log
}
[[ -f ListePression.log ]] && {
[[ $(wc -l < ListePression.log) -eq 20 ]] && sed -i '1d' ListePression.log
}
i=0
while read
do
((i++))
[[ ${REPLY} =~ "Pressure:" ]] && j=$i
[[ ${i} -eq $((j+7)) ]] && PR_INCH=${REPLY}
done < <(wget -nv http://www.weather.com/weather/today/$1 -O -)
PR_HPA=$(bc << EOF
scale=2
$PR_INCH * 33.86389 - 960
EOF
)
echo $PR_HPA >> ListePressionAdapt.log
PR_HP=$(bc << EOF
scale=2
$PR_INCH * 33.86389
EOF
)
echo $PR_HP >> ListePression.log
le fichier bargraphpression.lua pour afficher le graphique [merci à wlourf]
--[[ BARGRAPH WIDGET
v2.1 by wlourf (07 Jan. 2011)
this widget draws a bargraph with different effects
http://u-scripts.blogspot.com/2010/07/bargraph-widget.html
To call the script in a conky, use, before TEXT
lua_load /path/to/the/script/bargraph.lua
lua_draw_hook_pre main_rings
and add one line (blank or not) after TEXT
Parameters are :
3 parameters are mandatory
name - the name of the conky variable to display, for example for {$cpu cpu0}, just write name="cpu"
arg - the argument of the above variable, for example for {$cpu cpu0}, just write arg="cpu0"
arg can be a numerical value if name=""
max - the maximum value the above variable can reach, for example, for {$cpu cpu0}, just write max=100
Optional parameters:
x,y - coordinates of the starting point of the bar, default = middle of the conky window
cap - end of cap line, ossibles values are r,b,s (for round, butt, square), default="b"
http://www.cairographics.org/samples/set_line_cap/
angle - angle of rotation of the bar in degress, default = 0 (i.e. a vertical bar)
set to 90 for an horizontal bar
skew_x - skew bar around x axis, default = 0
skew_y - skew bar around y axis, default = 0
blocks - number of blocks to display for a bar (values >0) , default= 10
height - height of a block, default=10 pixels
width - width of a block, default=20 pixels
space - space between 2 blocks, default=2 pixels
angle_bar - this angle is used to draw a bar on a circular way (ok, this is no more a bar !) default=0
radius - for cicular bars, internal radius, default=0
with radius, parameter width has no more effect.
Colours below are defined into braces {colour in hexadecimal, alpha}
fg_colour - colour of a block ON, default= {0x00FF00,1}
bg_colour - colour of a block OFF, default = {0x00FF00,0.5}
alarm - threshold, values after this threshold will use alarm_colour colour , default=max
alarm_colour - colour of a block greater than alarm, default=fg_colour
smooth - (true or false), create a gradient from fg_colour to bg_colour, default=false
mid_colour - colours to add to gradient, with this syntax {position into the gradient (0 to1), colour hexa, alpha}
for example, this table {{0.25,0xff0000,1},{0.5,0x00ff00,1},{0.75,0x0000ff,1}} will add
3 colurs to gradient created by fg_colour and alarm_colour, default=no mid_colour
led_effect - add LED effects to each block, default=no led_effect
if smooth=true, led_effect is not used
possibles values : "r","a","e" for radial, parallelel, perdendicular to the bar (just try!)
led_effect has to be used with theses colours :
fg_led - middle colour of a block ON, default = fg_colour
bg_led - middle colour of a block OFF, default = bg_colour
alarm_led - middle colour of a block > ALARM, default = alarm_colour
reflection parameters, not avaimable for circular bars
reflection_alpha - add a reflection effect (values from 0 to 1) default = 0 = no reflection
other values = starting opacity
reflection_scale - scale of the reflection (default = 1 = height of text)
reflection_length - length of reflection, define where the opacity will be set to zero
calues from 0 to 1, default =1
reflection - position of reflection, relative to a vertical bar, default="b"
possibles values are : "b","t","l","r" for bottom, top, left, right
draw_me - if set to false, text is not drawn (default = true or 1)
it can be used with a conky string, if the string returns 1, the text is drawn :
example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",
v1.0 (10 Feb. 2010) original release
v1.1 (13 Feb. 2010) numeric values can be passed instead conky stats with parameters name="", arg = numeric_value
v1.2 (28 Feb. 2010) just renamed the widget to bargraph
v1.3 (03 Mar. 2010) added parameters radius & angle_bar to draw the bar in a circular way
v2.0 (12 Jul. 2010) rewrite script + add reflection effects and parameters are now set into tables
v2.1 (07 Jan. 2011) Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation version 3 (GPLv3)
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-- MA 02110-1301, USA.
]]
require 'cairo'
----------------START OF PARAMETERS ----------
function conky_main_bars()
local bars_settings={
{
name="execp",
arg="sed -n '1p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=15,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '2p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=25,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '3p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=35,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '4p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=45,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '5p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=55,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '6p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=65,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '7p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=75,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '8p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=85,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '9p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=95,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '10p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=105,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '11p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=115,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '12p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=125,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '13p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=135,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '14p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=145,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '15p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=155,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '16p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=165,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '17p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=175,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '18p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=185,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '19p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=195,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="execp",
arg="sed -n '20p' ListePressionAdapt.log",
max=100,
alarm=50,
bg_colour={0x000000,0.25},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=205,y=120,
blocks=1,
height=100,width=10,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="",
arg="0",
max=200,
alarm=50,
bg_colour={0x000000,.5},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=15,y=80,angle=90,
blocks=1,
height=200,width=1,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="",
arg="0",
max=200,
alarm=50,
bg_colour={0x000000,.5},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=15,y=60,angle=90,
blocks=1,
height=200,width=1,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="",
arg="0",
max=200,
alarm=50,
bg_colour={0x000000,.5},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=15,y=40,angle=90,
blocks=1,
height=200,width=1,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="",
arg="0",
max=200,
alarm=50,
bg_colour={0x000000,.5},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=15,y=100,angle=90,
blocks=1,
height=200,width=1,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
{
name="",
arg="0",
max=200,
alarm=50,
bg_colour={0xff0000,.5},
fg_colour={0x808080,1},
alarm_colour={0xffff00,1},
x=15,y=70,angle=90,
blocks=1,
height=200,width=1,
smooth=true,
mid_colour={{.4,0xc0ffff,1}}
},
}
-----------END OF PARAMETERS--------------
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)
cr = cairo_create(cs)
--prevent segmentation error when reading cpu state
if tonumber(conky_parse('${updates}'))>3 then
for i in pairs(bars_settings) do
draw_multi_bar_graph(bars_settings[i])
end
end
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end
function draw_multi_bar_graph(t)
cairo_save(cr)
--check values
if t.draw_me == true then t.draw_me = nil end
if t.draw_me ~= nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end
if t.name==nil and t.arg==nil then
print ("No input values ... use parameters 'name' with 'arg' or only parameter 'arg' ")
return
end
if t.max==nil then
print ("No maximum value defined, use 'max'")
return
end
if t.name==nil then t.name="" end
if t.arg==nil then t.arg="" end
--set default values
if t.min == nil then t.min=0 end
if t.x == nil then t.x = conky_window.width/2 end
if t.y == nil then t.y = conky_window.height/2 end
if t.blocks == nil then t.blocks=10 end
if t.height == nil then t.height=10 end
if t.angle == nil then t.angle=0 end
t.angle = t.angle*math.pi/180
--line cap style
if t.cap==nil then t.cap = "b" end
local cap="b"
for i,v in ipairs({"s","r","b"}) do
if v==t.cap then cap=v end
end
local delta=0
if t.cap=="r" or t.cap=="s" then delta = t.height end
if cap=="s" then cap = CAIRO_LINE_CAP_SQUARE
elseif cap=="r" then
cap = CAIRO_LINE_CAP_ROUND
elseif cap=="b" then
cap = CAIRO_LINE_CAP_BUTT
end
--end line cap style
--if t.led_effect == nil then t.led_effect="r" end
if t.width == nil then t.width=20 end
if t.space == nil then t.space=2 end
if t.radius == nil then t.radius=0 end
if t.angle_bar == nil then t.angle_bar=0 end
t.angle_bar = t.angle_bar*math.pi/360 --halt angle
--colours
if t.bg_colour == nil then t.bg_colour = {0x00FF00,0.5} end
if #t.bg_colour~=2 then t.bg_colour = {0x00FF00,0.5} end
if t.fg_colour == nil then t.fg_colour = {0x00FF00,1} end
if #t.fg_colour~=2 then t.fg_colour = {0x00FF00,1} end
if t.alarm_colour == nil then t.alarm_colour = t.fg_colour end
if #t.alarm_colour~=2 then t.alarm_colour = t.fg_colour end
if t.mid_colour ~= nil then
for i=1, #t.mid_colour do
if #t.mid_colour[i]~=3 then
print ("error in mid_color table")
t.mid_colour[i]={1,0xFFFFFF,1}
end
end
end
if t.bg_led ~= nil and #t.bg_led~=2 then t.bg_led = t.bg_colour end
if t.fg_led ~= nil and #t.fg_led~=2 then t.fg_led = t.fg_colour end
if t.alarm_led~= nil and #t.alarm_led~=2 then t.alarm_led = t.fg_led end
if t.led_effect~=nil then
if t.bg_led == nil then t.bg_led = t.bg_colour end
if t.fg_led == nil then t.fg_led = t.fg_colour end
if t.alarm_led == nil then t.alarm_led = t.fg_led end
end
if t.alarm==nil then t.alarm = t.max end --0.8*t.max end
if t.smooth == nil then t.smooth = false end
if t.skew_x == nil then
t.skew_x=0
else
t.skew_x = math.pi*t.skew_x/180
end
if t.skew_y == nil then
t.skew_y=0
else
t.skew_y = math.pi*t.skew_y/180
end
if t.reflection_alpha==nil then t.reflection_alpha=0 end
if t.reflection_length==nil then t.reflection_length=1 end
if t.reflection_scale==nil then t.reflection_scale=1 end
--end of default values
local function rgb_to_r_g_b(col_a)
return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
end
--functions used to create patterns
local function create_smooth_linear_gradient(x0,y0,x1,y1)
local pat = cairo_pattern_create_linear (x0,y0,x1,y1)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
if t.mid_colour ~=nil then
for i=1, #t.mid_colour do
cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
end
end
return pat
end
local function create_smooth_radial_gradient(x0,y0,r0,x1,y1,r1)
local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
if t.mid_colour ~=nil then
for i=1, #t.mid_colour do
cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
end
end
return pat
end
local function create_led_linear_gradient(x0,y0,x1,y1,col_alp,col_led)
local pat = cairo_pattern_create_linear (x0,y0,x1,y1) ---delta, 0,delta+ t.width,0)
cairo_pattern_add_color_stop_rgba (pat, 0.0, rgb_to_r_g_b(col_alp))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1.0, rgb_to_r_g_b(col_alp))
return pat
end
local function create_led_radial_gradient(x0,y0,r0,x1,y1,r1,col_alp,col_led,mode)
local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
if mode==3 then
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_alp))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))
else
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))
end
return pat
end
local function draw_single_bar()
--this fucntion is used for bars with a single block (blocks=1) but
--the drawing is cut in 3 blocks : value/alarm/background
--not zvzimzblr for circular bar
local function create_pattern(col_alp,col_led,bg)
local pat
if not t.smooth then
if t.led_effect=="e" then
pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
elseif t.led_effect=="a" then
pat = create_led_linear_gradient (t.width/2, 0,t.width/2,-t.height,col_alp,col_led)
elseif t.led_effect=="r" then
pat = create_led_radial_gradient (t.width/2, -t.height/2, 0, t.width/2,-t.height/2,t.height/1.5,col_alp,col_led,2)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
else
if bg then
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.bg_colour))
else
pat = create_smooth_linear_gradient(t.width/2, 0, t.width/2,-t.height)
end
end
return pat
end
local y1=-t.height*pct/100
local y2,y3
if pct>(100*t.alarm/t.max) then
y1 = -t.height*t.alarm/100
y2 = -t.height*pct/100
if t.smooth then y1=y2 end
end
if t.angle_bar==0 then
--block for fg value
local pat = create_pattern(t.fg_colour,t.fg_led,false)
cairo_set_source(cr,pat)
cairo_rectangle(cr,0,0,t.width,y1)
cairo_fill(cr)
cairo_pattern_destroy(pat)
-- block for alarm value
if not t.smooth and y2 ~=nil then
pat = create_pattern(t.alarm_colour,t.alarm_led,false)
cairo_set_source(cr,pat)
cairo_rectangle(cr,0,y1,t.width,y2-y1)
cairo_fill(cr)
y3=y2
cairo_pattern_destroy(pat)
else
y2,y3=y1,y1
end
-- block for bg value
cairo_rectangle(cr,0,y2,t.width,-t.height-y3)
pat = create_pattern(t.bg_colour,t.bg_led,true)
cairo_set_source(cr,pat)
cairo_pattern_destroy(pat)
cairo_fill(cr)
end
end --end single bar
local function draw_multi_bar()
--function used for bars with 2 or more blocks
for pt = 1,t.blocks do
--set block y
local y1 = -(pt-1)*(t.height+t.space)
local light_on=false
--set colors
local col_alp = t.bg_colour
local col_led = t.bg_led
if pct>=(100/t.blocks) or pct>0 then --ligth on or not the block
if pct>=(pcb*(pt-1)) then
light_on = true
col_alp = t.fg_colour
col_led = t.fg_led
if pct>=(100*t.alarm/t.max) and (pcb*pt)>(100*t.alarm/t.max) then
col_alp = t.alarm_colour
col_led = t.alarm_led
end
end
end
--set colors
--have to try to create gradients outside the loop ?
local pat
if not t.smooth then
if t.angle_bar==0 then
if t.led_effect=="e" then
pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
elseif t.led_effect=="a" then
pat = create_led_linear_gradient (t.width/2, -t.height/2+y1,t.width/2,0+t.height/2+y1,col_alp,col_led)
elseif t.led_effect=="r" then
pat = create_led_radial_gradient (t.width/2, y1, 0, t.width/2,y1,t.width/1.5,col_alp,col_led,2)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
else
if t.led_effect=="a" then
pat = create_led_radial_gradient (0, 0, t.radius+(t.height+t.space)*(pt-1),
0, 0, t.radius+(t.height+t.space)*(pt),
col_alp,col_led,3)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
end
else
if light_on then
if t.angle_bar==0 then
pat = create_smooth_linear_gradient(t.width/2, t.height/2, t.width/2,-(t.blocks-0.5)*(t.height+t.space))
else
pat = create_smooth_radial_gradient(0, 0, (t.height+t.space), 0,0,(t.blocks+1)*(t.height+t.space),2)
end
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.bg_colour))
end
end
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
--draw a block
if t.angle_bar==0 then
cairo_move_to(cr,0,y1)
cairo_line_to(cr,t.width,y1)
else
cairo_arc( cr,0,0,
t.radius+(t.height+t.space)*(pt)-t.height/2,
-t.angle_bar -math.pi/2 ,
t.angle_bar -math.pi/2)
end
cairo_stroke(cr)
end
end
local function setup_bar_graph()
--function used to retrieve the value to display and to set the cairo structure
if t.blocks ~=1 then t.y=t.y-t.height/2 end
local value = 0
if t.name ~="" then
value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))
--$to_bytes doesn't work when value has a decimal point,
--https://garage.maemo.org/plugins/ggit/browse.php/?p=monky;a=commitdiff;h=174c256c81a027a2ea406f5f37dc036fac0a524b;hp=d75e2db5ed3fc788fb8514121f67316ac3e5f29f
--http://sourceforge.net/tracker/index.php?func=detail&aid=3000865&group_id=143975&atid=757310
--conky bug?
--value = (conky_parse(string.format('${%s %s}', t.name, t.arg)))
--if string.match(value,"%w") then
-- value = conky_parse(string.format('${to_bytes %s}',value))
--end
else
value = tonumber(t.arg)
end
if value==nil then value =0 end
pct = 100*value/t.max
pcb = 100/t.blocks
cairo_set_line_width (cr, t.height)
cairo_set_line_cap (cr, cap)
cairo_translate(cr,t.x,t.y)
cairo_rotate(cr,t.angle)
local matrix0 = cairo_matrix_t:create()
tolua.takeownership(matrix0)
cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
cairo_transform(cr,matrix0)
--call the drawing function for blocks
if t.blocks==1 and t.angle_bar==0 then
draw_single_bar()
if t.reflection=="t" or t.reflection=="b" then cairo_translate(cr,0,-t.height) end
else
draw_multi_bar()
end
--dot for reminder
--[[
if t.blocks ~=1 then
cairo_set_source_rgba(cr,1,0,0,1)
cairo_arc(cr,0,t.height/2,3,0,2*math.pi)
cairo_fill(cr)
else
cairo_set_source_rgba(cr,1,0,0,1)
cairo_arc(cr,0,0,3,0,2*math.pi)
cairo_fill(cr)
end]]
--call the drawing function for reflection and prepare the mask used
if t.reflection_alpha>0 and t.angle_bar==0 then
local pat2
local matrix1 = cairo_matrix_t:create()
tolua.takeownership(matrix1)
if t.angle_bar==0 then
pts={-delta/2,(t.height+t.space)/2,t.width+delta,-(t.height+t.space)*(t.blocks)}
if t.reflection=="t" then
cairo_matrix_init (matrix1,1,0,0,-t.reflection_scale,0,-(t.height+t.space)*(t.blocks-0.5)*2*(t.reflection_scale+1)/2)
pat2 = cairo_pattern_create_linear (t.width/2,-(t.height+t.space)*(t.blocks),t.width/2,(t.height+t.space)/2)
elseif t.reflection=="r" then
cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,delta+2*t.width,0)
pat2 = cairo_pattern_create_linear (delta/2+t.width,0,-delta/2,0)
elseif t.reflection=="l" then
cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,-delta,0)
pat2 = cairo_pattern_create_linear (-delta/2,0,delta/2+t.width,-0)
else --bottom
cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(t.height+t.space)*(t.reflection_scale+1)/2)
pat2 = cairo_pattern_create_linear (t.width/2,(t.height+t.space)/2,t.width/2,-(t.height+t.space)*(t.blocks))
end
end
cairo_transform(cr,matrix1)
if t.blocks==1 and t.angle_bar==0 then
draw_single_bar()
cairo_translate(cr,0,-t.height/2)
else
draw_multi_bar()
end
cairo_set_line_width(cr,0.01)
cairo_pattern_add_color_stop_rgba (pat2, 0,0,0,0,1-t.reflection_alpha)
cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
if t.angle_bar==0 then
cairo_rectangle(cr,pts[1],pts[2],pts[3],pts[4])
end
cairo_clip_preserve(cr)
cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
cairo_stroke(cr)
cairo_mask(cr,pat2)
cairo_pattern_destroy(pat2)
cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
end --reflection
pct,pcb=nil
end --setup_bar_graph()
--start here !
setup_bar_graph()
cairo_restore(cr)
end
et le textpression.lua pour afficher les valeurs en-dessous du graphe [encore de wlourf...]
--[[TEXT WIDGET v1.42 by Wlourf 07 Feb. 2011
This widget can drawn texts set in the "text_settings" table with some parameters
http://u-scripts.blogspot.com/2010/06/text-widget.html
To call the script in a conky, use, before TEXT
lua_load /path/to/the/script/graph.lua
lua_draw_hook_pre main_graph
and add one line (blank or not) after TEXT
The parameters (all optionals) are :
text - text to display, default = "Conky is good for you"
it can be used with conky variables, i.e. text="my cpu1 is ${cpu cpu1} %")
- coordinates below are relative to top left corner of the conky window
x - x coordinate of first letter (bottom-left), default = center of conky window
y - y coordinate of first letter (bottom-left), default = center of conky window
h_align - horizontal alignement of text relative to point (x,y), default="l"
available values are "l": left, "c" : center, "r" : right
v_align - vertical alignment of text relative to point (x,y), default="b"
available values "t" : top, "m" : middle, "b" : bottom
font_name - name of font to use, default = Free Sans
font_size - size of font to use, default = 14
italic - display text in italic (true/false), default=false
oblique - display text in oblique (true/false), default=false (I don' see the difference with italic!)
bold - display text in bold (true/false), default=false
angle - rotation of text in degrees, default = 0 (horizontal)
colour - table of colours for text, default = plain white {{1,0xFFFFFF,1}}
this table contains one or more tables with format {P,C,A}
P=position of gradient (0 = beginning of text, 1= end of text)
C=hexadecimal colour
A=alpha (opacity) of color (0=invisible,1=opacity 100%)
Examples :
for a plain color {{1,0x00FF00,0.5}}
for a gradient with two colours {{0,0x00FF00,0.5},{1,0x000033,1}}
or {{0.5,0x00FF00,1},{1,0x000033,1}} -with this one, gradient will start in the middle of the text
for a gradient with three colours {{0,0x00FF00,0.5},{0.5,0x000033,1},{1,0x440033,1}}
and so on ...
orientation - in case of gradient, "orientation" defines the starting point of the gradient, default="ww"
there are 8 available starting points : "nw","nn","ne","ee","se","ss","sw","ww"
(n for north, w for west ...)
theses 8 points are the 4 corners + the 4 middles of text's outline
so a gradient "nn" will go from "nn" to "ss" (top to bottom, parallele to text)
a gradient "nw" will go from "nw" to "se" (left-top corner to right-bottom corner)
radial - define a radial gradient (if present at the same time as "orientation", "orientation" will have no effect)
this parameter is a table with 6 numbers : {xa,ya,ra,xb,yb,rb}
they define two circle for the gradient :
xa, ya, xb and yb are relative to x and y values above
reflection_alpha - add a reflection effect (values from 0 to 1) default = 0 = no reflection
other values = starting opacity
reflection_scale - scale of the reflection (default = 1 = height of text)
reflection_length - length of reflection, define where the opacity will be set to zero
calues from 0 to 1, default =1
skew_x,skew_y - skew text around x or y axis
draw_me - if set to false, text is not drawn (default = true or 1)
it can be used with a conky string, if the string returns 1, the text is drawn :
example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",
v1.0 07/06/2010, Original release
v1.1 10/06/2010 Add "orientation" parameter
v1.2 15/06/2010 Add "h_align", "v_align" and "radial" parameters
v1.3 25/06/2010 Add "reflection_alpha", "reflection_length", "reflection_scale",
"skew_x" et "skew_y"
v1.4 07/01/2011 Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
text is parsed inside the function, not in the array of settings
v1.41 26/01/2011 Correct bug for h_align="c"
v1.42 09/02/2011 Correct bug for orientation="ee"
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation version 3 (GPLv3)
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-- MA 02110-1301, USA.
]]
require 'cairo'
function conky_draw_text()
local text_settings={
--BEGIN OF PARAMETERS
{
text="${exec sed -n '1p' ListePression.log | cut -c1-7}",
x=17,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '2p' ListePression.log | cut -c1-7}",
x=27,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '3p' ListePression.log | cut -c1-7}",
x=37,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '4p' ListePression.log | cut -c1-7}",
x=47,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '5p' ListePression.log | cut -c1-7}",
x=57,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '6p' ListePression.log | cut -c1-7}",
x=67,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '7p' ListePression.log | cut -c1-7}",
x=77,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '8p' ListePression.log | cut -c1-7}",
x=87,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '9p' ListePression.log | cut -c1-7}",
x=97,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '10p' ListePression.log | cut -c1-7}",
x=107,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '11p' ListePression.log | cut -c1-7}",
x=117,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '12p' ListePression.log | cut -c1-7}",
x=127,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '13p' ListePression.log | cut -c1-7}",
x=137,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '14p' ListePression.log | cut -c1-7}",
x=147,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '15p' ListePression.log | cut -c1-7}",
x=157,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '16p' ListePression.log | cut -c1-7}",
x=167,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '17p' ListePression.log | cut -c1-7}",
x=177,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '18p' ListePression.log | cut -c1-7}",
x=187,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '19p' ListePression.log | cut -c1-7}",
x=197,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
{
text="${exec sed -n '20p' ListePression.log | cut -c1-7}",
x=207,
y=121,
colour={{1 ,0x000000,.8}},
angle=90,
font_name="Ubuntu Light",bold=true,
font_size=8,
orientation="nw"
},
}
--------------END OF PARAMETERS----------------
if conky_window == nil then return end
if tonumber(conky_parse("$updates"))<3 then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
for i,v in pairs(text_settings) do
cr = cairo_create (cs)
display_text(v)
cairo_destroy(cr)
cr = nil
end
cairo_surface_destroy(cs)
end
function rgb_to_r_g_b2(tcolour)
local colour,alpha=tcolour[2],tcolour[3]
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
function display_text(t)
if t.draw_me==true then t.draw_me = nil end
if t.draw_me~=nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end
local function set_pattern(te)
--this function set the pattern
if #t.colour==1 then
cairo_set_source_rgba(cr,rgb_to_r_g_b2(t.colour[1]))
else
local pat
if t.radial==nil then
local pts=linear_orientation(t,te)
pat = cairo_pattern_create_linear (pts[1],pts[2],pts[3],pts[4])
else
pat = cairo_pattern_create_radial (t.radial[1],t.radial[2],t.radial[3],t.radial[4],t.radial[5],t.radial[6])
end
for i=1, #t.colour do
cairo_pattern_add_color_stop_rgba (pat, t.colour[i][1], rgb_to_r_g_b2(t.colour[i]))
end
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
end
end
--set default values if needed
if t.text==nil then t.text="Conky is good for you !" end
if t.x==nil then t.x = conky_window.width/2 end
if t.y==nil then t.y = conky_window.height/2 end
if t.colour==nil then t.colour={{1,0xFFFFFF,1}} end
if t.font_name==nil then t.font_name="Free Sans" end
if t.font_size==nil then t.font_size=14 end
if t.angle==nil then t.angle=0 end
if t.italic==nil then t.italic=false end
if t.oblique==nil then t.oblique=false end
if t.bold==nil then t.bold=false end
if t.radial ~= nil then
if #t.radial~=6 then
print ("error in radial table")
t.radial=nil
end
end
if t.orientation==nil then t.orientation="ww" end
if t.h_align==nil then t.h_align="l" end
if t.v_align==nil then t.v_align="b" end
if t.reflection_alpha == nil then t.reflection_alpha=0 end
if t.reflection_length == nil then t.reflection_length=1 end
if t.reflection_scale == nil then t.reflection_scale=1 end
if t.skew_x==nil then t.skew_x=0 end
if t.skew_y==nil then t.skew_y=0 end
cairo_translate(cr,t.x,t.y)
cairo_rotate(cr,t.angle*math.pi/180)
cairo_save(cr)
local slant = CAIRO_FONT_SLANT_NORMAL
local weight = CAIRO_FONT_WEIGHT_NORMAL
if t.italic then slant = CAIRO_FONT_SLANT_ITALIC end
if t.oblique then slant = CAIRO_FONT_SLANT_OBLIQUE end
if t.bold then weight = CAIRO_FONT_WEIGHT_BOLD end
cairo_select_font_face(cr, t.font_name, slant,weight)
for i=1, #t.colour do
if #t.colour[i]~=3 then
print ("error in color table")
t.colour[i]={1,0xFFFFFF,1}
end
end
local matrix0 = cairo_matrix_t:create()
tolua.takeownership(matrix0)
local skew_x,skew_y=t.skew_x/t.font_size,t.skew_y/t.font_size
cairo_matrix_init (matrix0, 1,skew_y,skew_x,1,0,0)
cairo_transform(cr,matrix0)
cairo_set_font_size(cr,t.font_size)
local te=cairo_text_extents_t:create()
tolua.takeownership(te)
t.text=conky_parse(t.text)
cairo_text_extents (cr,t.text,te)
set_pattern(te)
local mx,my=0,0
if t.h_align=="c" then
mx=-te.width/2-te.x_bearing
elseif t.h_align=="r" then
mx=-te.width
end
if t.v_align=="m" then
my=-te.height/2-te.y_bearing
elseif t.v_align=="t" then
my=-te.y_bearing
end
cairo_move_to(cr,mx,my)
cairo_show_text(cr,t.text)
if t.reflection_alpha ~= 0 then
local matrix1 = cairo_matrix_t:create()
tolua.takeownership(matrix1)
cairo_set_font_size(cr,t.font_size)
cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(te.height+te.y_bearing+my)*(1+t.reflection_scale))
cairo_set_font_size(cr,t.font_size)
te=nil
local te=cairo_text_extents_t:create()
tolua.takeownership(te)
cairo_text_extents (cr,t.text,te)
cairo_transform(cr,matrix1)
set_pattern(te)
cairo_move_to(cr,mx,my)
cairo_show_text(cr,t.text)
local pat2 = cairo_pattern_create_linear (0,
(te.y_bearing+te.height+my),
0,
te.y_bearing+my)
cairo_pattern_add_color_stop_rgba (pat2, 0,1,0,0,1-t.reflection_alpha)
cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
--line is not drawn but with a size of zero, the mask won't be nice
cairo_set_line_width(cr,1)
local dy=te.x_bearing
if dy<0 then dy=dy*(-1) end
cairo_rectangle(cr,mx+te.x_bearing,te.y_bearing+te.height+my,te.width+dy,-te.height*1.05)
cairo_clip_preserve(cr)
cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
--cairo_stroke(cr)
cairo_mask(cr,pat2)
cairo_pattern_destroy(pat2)
cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
te=nil
end
end
function linear_orientation(t,te)
local w,h=te.width,te.height
local xb,yb=te.x_bearing,te.y_bearing
if t.h_align=="c" then
xb=xb-w/2
elseif t.h_align=="r" then
xb=xb-w
end
if t.v_align=="m" then
yb=-h/2
elseif t.v_align=="t" then
yb=0
end
local p=0
if t.orientation=="nn" then
p={xb+w/2,yb,xb+w/2,yb+h}
elseif t.orientation=="ne" then
p={xb+w,yb,xb,yb+h}
elseif t.orientation=="ww" then
p={xb,h/2,xb+w,h/2}
elseif vorientation=="se" then
p={xb+w,yb+h,xb,yb}
elseif t.orientation=="ss" then
p={xb+w/2,yb+h,xb+w/2,yb}
elseif t.orientation=="ee" then
p={xb+w,h/2,xb,h/2}
elseif t.orientation=="sw" then
p={xb,yb+h,xb+w,yb}
elseif t.orientation=="nw" then
p={xb,yb,xb+w,yb+h}
end
return p
end
et finalement merci à Carpediem pour l'idee initiale....
Bon conky à tous
--Edit --
ce n'est certainement pas la méthode la plus économique en ressources ni en nombre de lignes de code, donc si un expert en lua veut faire quelque chose de moins gourmand, ça serait pas mal...
Dernière modification par shamen456 (Le 02/09/2011, à 21:40)
Hors ligne
#957 Le 03/09/2011, à 00:01
- sunkart
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
C'est beau
J'ai dans l'idée de faire la même chose avec un script qui me récupère es T°, utilisation CPU et RAM un peu dans le genre Mumin mais avec un vrai archivage, il faut peut-être que je me tourne vers ça.
Bravo en tout cas.
Cyril
Hors ligne
#958 Le 03/09/2011, à 12:33
- mutavh
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
Bonjour à tous!
J'essaye d'utiliser le script de shamen456 (#907) avec le script lua associé.
Ceci dit je tombe sur ce message d'erreur:
Conky: llua_do_call: function conky_main execution failed: /home/xavier/.conky/.arcs_blue.lua:402: attempt to perform arithmetic on local 'value' (a nil value)
La ligne correspondante dans le fichier lua est:
local val = value % (max_value + 1)
Je n'arrive pas à comprendre le sens de cette ligne ni ce qui déconne...
Est-ce que quelqu'un peut m'aider svp?
Hors ligne
#959 Le 03/09/2011, à 15:00
- shamen456
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
@mutav : c'est bizarre, j'ai jamais eut cette erreur en adaptant le script...
essaie en plaçant ce code sur la ligne juste avant
if value==nil then value=0 end
si j’interprète bien ce qu'il te dit, c'est qu'il essaie de calculer qqch avec value=nil (une valeur texte) au lieu de value=0 (valeur chiffrée)...que les spécialistes en programmation me corrigent si je dis des conneries...
...l'apprentissage par essais et erreurs a ses limites..
Hors ligne
#960 Le 03/09/2011, à 17:04
- carpediem
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
Félicitation shamen456 super travail, et un grand merci à Levi59 pour sont aide et pour ma part je me suis simplement contenté d'être à l'initiative de cette idée.
Par contre je rencontre un problème
Voici ce qui s'affiche sur mon bureau
merci
Cordialement carpediem
"Carpe diem quam minimum credula postero"
(Cueille le jour présent, en te fiant le moins possible au lendemain.)
HORACE
Hors ligne
#961 Le 03/09/2011, à 19:58
- shamen456
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
c'est bizarre, c'est comme s'il ne trouvait pas les valeurs à afficher sur le graphe...
essaie de supprimer les deux fichiers log pour réinitialiser les données...
Hors ligne
#962 Le 04/09/2011, à 05:30
- carpediem
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
oui c'est bizarre, je n'ai pas de fichier log qui apparaisse. Je pense que c'est un problème avec le conkyrc
#Fonctionnement de conky
total_run_times 0 #Temps en secondes ; 0 = toujours actif
background yes #Pour que conky tourne en arrière plan ; no = pour les tests
#Réglages système
cpu_avg_samples 1 #Nb d'échantillons pour calculer la moyenne d'utilisation CPU
net_avg_samples 2 #Nb d'échantillons pour calculer la moyenne d'utilisation CPU
#Mémoire
double_buffer yes #Éviter le clignotement
no_buffers yes #Soustraire les mémoires tampons de la mémoire utilisée
text_buffer_size 1024 #Taille du cache pour le texte
#Fonctionnement de conky
total_run_times 0 #Temps en secondes ; 0 = toujours actif
background yes #Pour que conky tourne en arrière plan ; no = pour les tests
#Réglages système
cpu_avg_samples 1 #Nb d'échantillons pour calculer la moyenne d'utilisation CPU
net_avg_samples 2 #Nb d'échantillons pour calculer la moyenne d'utilisation CPU
#Mémoire
double_buffer yes #Éviter le clignotement
no_buffers yes #Soustraire les mémoires tampons de la mémoire utilisée
text_buffer_size 1024 #Taille du cache pour le texte
#Affichage
out_to_console no #Affiche le texte sur la sortie standard
update_interval 1 #Taux de rafraîchissement de la fenêtre (s)
#Fenêtre conky
#alignment top_left #Alignement
#---
minimum_size 200 200 #Taille minimum (px) ; largeur / hauteur
maximum_width 250 400 #Largeur maximum (px)
#---
gap_x 380 #Écart avec le bord gauche / droit
gap_y 700 #Écart avec le bord haut / bas
#---
draw_shades no #Afficher les ombres
draw_outline no #Afficher les contours de fenêtre
draw_borders no #Afficher des contours autour des blocs de texte
border_width 1 #Largeur du contour
border_inner_margin 1 #Largeur des marges
#---
own_window yes #Utiliser sa propre fenêtre
own_window_type override #Type de fenêtre ; normal / override / desktop
own_window_transparent yes #Pseudo transparence
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
#Mise en forme
use_xft yes #Utiliser Xft (polices lissées etc)
xftalpha 1 #Utiliser Xft
override_utf8_locale yes #Force l'UTF8
uppercase no #Tout le texte en majuscule
use_spacer right #Ajoute des espaces après certains objets (qu'avec des polices fixes)
#---
xftfont saxMono:size=9 #Police par défaut
#---
default_bar_size 360 3 #Barre par défaut (longeur hauteur)
stippled_borders 6 #Taille des pointillés
#Couleurs
default_color FFFFFF #Couleur par défaut
default_shade_color 333333 #Couleur des ombres
default_outline_color black #Couleur des contours
#---
color1 242424 #Gris
#---
short_units yes #Unités courtes
pad_percents 2 #Unité à 2 décimales
default_color FFFFFF
color1 D2CBC1
color2 red #red, color of current T°
color3 blue #color of feels like T°
color4 B1ADA7
color5 7B7870
color6 3F3C36
color7 black #text color
# -- Lua Load -- #
# SET THE PATH TO THE SCRIPT HERE
lua_load ~/Conky/Baro/bargraphpression.lua
lua_draw_hook_pre main_bars
lua_load ~/Conky/Baro/textpression.lua
lua_draw_hook_post draw_text
TEXT
${execi 3600 bash ./Conky/Baro/pression.sh FRXX1949}
"Carpe diem quam minimum credula postero"
(Cueille le jour présent, en te fiant le moins possible au lendemain.)
HORACE
Hors ligne
#963 Le 04/09/2011, à 06:58
- shamen456
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
@Carpediem: les fichiers log sont créées dans ton répertoire /home/loginname/
essaie de lancer pression.sh dans un terminal pour voir ce qu'il te dit.
je ne vois pas ce qui pourrait clocher dans ton conkyrc
Hors ligne
#964 Le 04/09/2011, à 08:44
- carpediem
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
@shamen456: il n'y a aucun fichier log dans mon répertoire /home/claude/
carpediem ~/Conky/Baro$ ./pression.sh
http://www.weather.com/weather/today/:
2011-09-04 08:38:59 ERREUR 404: Not Found.
(standard_in) 2: syntax error
(standard_in) 2: syntax error
carpediem ~/Conky/Baro$ sh pression.sh
pression.sh: 6: [[: not found
pression.sh: 9: [[: not found
pression.sh: 17: Syntax error: redirection unexpected
carpediem ~/Conky/Baro$ bash pression.sh
[sudo] password for claude:
Error: "/var/tmp/kdecache-claude" is owned by uid 1000 instead of uid 0.
Application asked to unregister timer 0x4100000a which is not registered in this thread. Fix application.
Error: "/tmp/kde-claude" is owned by uid 1000 instead of uid 0.
Error: "/tmp/ksocket-claude" is owned by uid 1000 instead of uid 0.
QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: Aucun fichier ou dossier de ce type
QFileSystemWatcher: failed to add paths: /home/claude/.config/ibus/bus
kate(26866)/kdeui (kdelibs) KXMLGUIClient::~KXMLGUIClient: 0x1afd9e8 deleted without having been removed from the factory first. This will leak standalone popupmenus and could lead to crashes.
kate(26866)/kdeui (kdelibs) KXMLGUIClient::~KXMLGUIClient: 0x2119e90 deleted without having been removed from the factory first. This will leak standalone popupmenus and could lead to crashes.
kate(26866)/kdeui (kdelibs) KXMLGUIClient::~KXMLGUIClient: 0x2095148 deleted without having been removed from the factory first. This will leak standalone popupmenus and could lead to crashes.
carpediem ~/Conky/Baro$
"Carpe diem quam minimum credula postero"
(Cueille le jour présent, en te fiant le moins possible au lendemain.)
HORACE
Hors ligne
#965 Le 04/09/2011, à 09:07
- shamen456
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
@carpediem: essaie en mettant le paramètre de localisation (ou bien tu remplace $1 dans le script par ta localisation)
sinon apparemment il essaie d’accéder à un répertoire temporaire mais n'a pas les droits d’accès...mais la mes connaissances sont limitées..:(
Hors ligne
#966 Le 04/09/2011, à 09:15
- carpediem
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
@shamen456: j'ai modifié dans mon conkyrc
${image ./Conky/Baro/bigpanel2.png -s 225x180 -p +0,-2}${execi 14400 bash ./Conky/Baro/pression.sh FRXX1949}
par
${image /home/claude/Conky/Baro/bigpanel2.png -s 225x180 -p +0,-2}${execi 14400 bash /home/claude/Conky/Baro/pression.sh FRXX1949}
Mais je n'ai toujours pas de fichier log dans mon répertoire.
--Edit--
apparemment ça fonctionne, mais je ne trouve toujours pas les fichiers log.
Dernière modification par carpediem (Le 04/09/2011, à 09:46)
"Carpe diem quam minimum credula postero"
(Cueille le jour présent, en te fiant le moins possible au lendemain.)
HORACE
Hors ligne
#967 Le 04/09/2011, à 09:51
- shamen456
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
@carpediem: oui apparement il trouve des donnees à afficher...il faudrait trouver où il cree les fichiers log afin de les supprimer avant de relancer le conky pour tout réinitialiser et faire correspondre les barres aux données... actuellement il t'affiche les 6 dernières données mais elles sont décalées
Hors ligne
#968 Le 04/09/2011, à 10:14
- carpediem
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
Hourra je viens de trouver mes fichiers log, ils étaient caches dans /home/claude/document. j'ai réinitialisé et rentré les valeurs un peu fantaisiste pour tester.
Merci à toi @shamen456 ainsi qu'à @Levi59 pour votre fabuleux travail.
Cordialement carpediem
"Carpe diem quam minimum credula postero"
(Cueille le jour présent, en te fiant le moins possible au lendemain.)
HORACE
Hors ligne
#969 Le 04/09/2011, à 13:00
- wlourf
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
${goto 17}${color1}Up: ${color0}${uptime_short}${goto 100}${color1}CPU:${goto 135}${if_match ${cpu} >= 80}${color2}${else}${if_match ${cpu} >= 50}${color3}${else}${if_match ${cpu} >= 20}${color4}${else}${color0}${endif}${endif}${endif}${cpu}%${goto 175}[${freq_g}GHz]${goto 240}${cpugraph 12,30 949494 949494}${goto 275}${color0}${exec sensors | grep temp1 | awk '{ print $2}' | sed 's/\.0°C//g' | sed 's/+//g'}°${goto 300}${exec sensors | grep fan1 | awk '{ print $2}'}RPM${goto 370}${color1}GPU: ${color0}${exec nvidia-settings -q gpucoretemp | grep '):' | awk '{print $4}'| cut -c1-2}°${goto 425}${color1}M/B: ${color0}${exec sensors | grep temp2 | awk '{ print $2}' | sed 's/\.0°C//g' | sed 's/+//g'}°${goto 480}${color1}RAM:${goto 515}${if_match ${memperc} >= 80}${color2}${else}${if_match ${memperc} >= 50}${color3}${else}${if_match ${memperc} >= 20}${color4}${else}${color0}${endif}${endif}${endif}${memperc}%${goto 550}[${mem}]${goto 615}${color1}SWAP: ${if_match ${swapperc} >= 80}${color2}${else}${if_match ${swapperc} >= 50}${color3}${else}${if_match ${swapperc} >= 20}${color4}${else}${color0}${endif}${endif}${endif}${goto 660}${swapperc}%${goto 700}[${swap}]${if_match ${execi 360 aptitude search "~U" | wc -l | tail}==0}${image /home/wahibacyril/UbuntuOne/conky/icones/green_light.png -p 0,2 -s 12x12}${else}${image /home/wahibacyril/UbuntuOne/conky/icones/red_light.png -p 0,2 -s 12x12}${endif} ${color1}SDA:${goto 35}${color0}${execi 10 hddtemp -n /dev/sda}°${goto 60}${diskiograph_read /dev/sda 12,10 844796 844796}${diskiograph_write /dev/sda 12,10 2d7db3 2d7db3}${goto 85}${color1}Films:${goto 125}${if_match ${fs_used_perc /media/Films} >= 85}${color2}${else}${if_match ${fs_used_perc /media/Films} >= 65}${color3}${else}${if_match ${fs_used_perc /media/Films} >= 35}${color4}${else}${color0}${endif}${endif}${endif}${fs_used_perc /media/Films}%${goto 155}${color0}[${fs_used /media/Films}/${fs_size /media/Films}]${goto 270}${color1}Photos:${goto 320}${if_match ${fs_used_perc /media/Photos} >= 85}${color2}${else}${if_match ${fs_used_perc /media/Photos} >= 65}${color3}${else}${if_match ${fs_used_perc /media/Photos} >= 35}${color4}${else}${color0}${endif}${endif}${endif}${fs_used_perc /media/Photos}%${goto 350}${color0}[${fs_used /media/Photos}/${fs_size /media/Photos}]${goto 465}${color1}SDB:${goto 495}${color0}${execi 10 hddtemp -n /dev/sdb}°${goto 520}${diskiograph_read /dev/sdb 12,10 844796 844796}${diskiograph_write /dev/sdb 12,10 2d7db3 2d7db3}${goto 545}${color1}Ubuntu:${goto 595}${if_match ${fs_used_perc /} >= 85}${color2}${else}${if_match ${fs_used_perc /} >= 65}${color3}${else}${if_match ${fs_used_perc /} >= 35}${color4}${else}${color0}${endif}${endif}${endif}${fs_used_perc /}%${goto 625}${color0}[${fs_used /}/${fs_size /}]${goto 740}${color1}Data:${goto 775}${if_match ${fs_used_perc /media/Data} >= 85}${color2}${else}${if_match ${fs_used_perc /media/Data} >= 65}${color3}${else}${if_match ${fs_used_perc /media/Data} >= 35}${color4}${else}${color0}${endif}${endif}${endif}${fs_used_perc /media/Data}%${goto 805}${color0}[${fs_used /media/Data}/${fs_size /media/Data}]${goto 920}${color1}Musiques:${goto 985}${if_match ${fs_used_perc /media/Musiques} >= 85}${color2}${else}${if_match ${fs_used_perc /media/Musiques} >= 65}${color3}${else}${if_match ${fs_used_perc /media/Musiques} >= 35}${color4}${else}${color0}${endif}${endif}${endif}${fs_used_perc /media/Musiques}%${goto 1015}${color0}[${fs_used /media/Musiques}/${fs_size /media/Musiques}]
C'est pas super lisible vu que c'est sur une seule ligne
tu peux scinder ta ligne avec \ ou # : http://conky.pitstop.free.fr/wiki/index … s_%28fr%29
Hors ligne
#970 Le 04/09/2011, à 18:00
- sunkart
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
Ah yes !!! Je vais l'updater pour qu'il soit plus lisible.
Merci de l'astuce !!
Cyril
Hors ligne
#971 Le 05/09/2011, à 23:36
- Levi59
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
remoi sur le baromètre! Je voudrais demander l'aide de ceux qui affichent les donnée de pression pour tester l'utilisation de gnuplot.
C'est la première fois que j'utilise ce logiciel donc je ne suis pas encore super au point mais bon...
J'aimerais que la partie gnuplot soit corrigé au besoin.
Voici la version que je propose (j'ai repris mon ancien script) :
le script se lance avec le code de la ville en argument et créé un fichier log des pressions dans lequel se trouve la date (depuis epoch) et la valeur relevée (-1005 pour mettre l'axe x sur 1005) ainsi qu'un fichier graph.png représentant le graphique des données.
Il suffit alors d'afficher l'image dans conky!
Confere plus bas! ^^
Merci de me donner un retour!
Dernière modification par Levi59 (Le 08/09/2011, à 19:44)
Hors ligne
#972 Le 05/09/2011, à 23:52
- shamen456
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
@levi59 : j'obtiens l'erreur suivante
jacques@jacques-Aspire-7730G:~$ bash barognuplot.sh BEXX0006
2011-09-05 23:50:37 URL:http://www.weather.com/weather/today/BEXX0006 [196326/196326] -> "-" [1]
barognuplot.sh: ligne 21: Erreur de syntaxe près du symbole inattendu « } »
barognuplot.sh: ligne 21: `[[ -z $PR_INCH ]] && {echo "erreur"; exit 1; }'
jacques@jacques-Aspire-7730G:~$
et je ne sais pas trop à quoi ça correspond...
--EDIT--
il faut rajouter un espace entre { et echo à la ligne 21
...par contre je ne trouve pas le fichier graphe?
Dernière modification par shamen456 (Le 05/09/2011, à 23:58)
Hors ligne
#973 Le 05/09/2011, à 23:55
- Levi59
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
Exact! Le pire c'est que j'avais aussi repéré et corrigé l'erreur mais j'ai pas actualisé sur le forum
Hors ligne
#974 Le 06/09/2011, à 13:47
- Levi59
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
Petite mise à jour du code...
Comme le graphique tiens compte des dates, j'ai modifié le début du script pour qu'il vérifie les dates du fichier log et supprime les valeurs âgées de plus d'une semaine. Ça permet de mieux gérer l'affichage.
Le fonctionnement reste le même que pour la version précédente. (@shamen456 les emplacements des fichiers sont au début du script)
#!/bin/bash
## files
LOG="$HOME/.conky/ListePression.log"
GRAPH="$HOME/.conky/graph.png"
## Vérifier argument
[[ -z $1 ]] && {
echo "Absence d'argument: mettre le code de la ville en argument"; exit 1
}
##Infos générales
DATE=$(date +"%s")
DATE1WEEK=$(date --date="1 week ago" +"%s")
# liste des dates de relevé du fichier log
EPOCH=()
while read
do
EPOCH+=( "$REPLY" )
done< <(awk '{print $1}' "$LOG")
# si le fichier existe et contient des valeurs de plus d'une semaine (première = plus vieille)
#supprimer première valeur
[[ -f $LOG ]] && {
for i in $(seq 0 $(($(wc -l < $LOG)-1)))
do
[[ $DATE1WEEK -gt ${EPOCH[$i]} ]] && sed -i '1d' $LOG || break
done
}
## Récupération de la pression sur weather.com
i=0
while read
do
((i++))
[[ ${REPLY} =~ "Pressure:" ]] && j=$i
[[ ${i} -eq $((j+7)) ]] && PR_INCH=${REPLY}
done < <(wget -nv http://www.weather.com/weather/today/$1 -O -)
[[ -z $PR_INCH ]] && {
echo "erreur"; exit 1
}
## Conversion en hectopascal
PR_HP=$(bc << EOF
scale=2
$PR_INCH * 33.86389 - 1005
EOF
)
echo "$DATE $PR_HP" >> $LOG
gnuplot <<EOF
set terminal png enhanced size 400,250 font "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf,9" #transparent
set output "$GRAPH"
unset key
set grid
set xzeroaxis lt -1 lw 1
set yzeroaxis
set ytics ("905" -100, "955" -50, "1005" 0, "1055" 50,"1105" 100)
set mxtics 0
set xdata time
set timefmt "%s"
set xtics 86400
set format x "%d/%m"
plot ["$DATE1WEEK":"$DATE"] [-135:135] "$LOG" using 1:2 with lines
EOF
exit 0
PS: Je suis toujours dans l'attente de corrections pour la partie gnuplot
--EDIT--
modification de l'apparence du graph! ^^
Dernière modification par Levi59 (Le 06/09/2011, à 15:52)
Hors ligne
#975 Le 06/09/2011, à 16:00
- maestroom
Re : (4) Conky : Postez vos conkyrc ou certaines parties intéressantes
Nouveau Fond d'écran impose nouveau conky! Toujours dans le plus simple des expressions!
voici une petite image XD
voici donc les codes utiliser (merci a wlourf )
start_conky.sh
#!/bin/bash
sleep 25
conky -c ~/conky.conf &
sleep 15
conky -c /home/maestroom/conky/net &
sleep 15
conky -c /home/maestroom/conky/cpu &
exit 0
conky.conf
# Conky settings #
background no
update_interval 1
cpu_avg_samples 2
net_avg_samples 2
override_utf8_locale yes
double_buffer yes
no_buffers yes
text_buffer_size 2048
imlib_cache_size 0
# Window specifications #
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
border_inner_margin 0
border_outer_margin 0
minimum_size 550 550
maximum_width 550
alignment tr
gap_x 619
gap_y 326
# Graphics settings #
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
# Text settings #
use_xft yes
xftfont caviar dreams:size=8
xftalpha 0.1
uppercase no
# Lua Load #
lua_load /home/maestroom/conky/script/clock.lua
lua_draw_hook_pre main_pie
TEXT
${voffset 200}${color ffbb00}${font caviar dreams:size=8}
${font Radio Space Bold video:size=24}${goto 260}${time %H:%M:%S}
${font Radio Space Bold video:size=12}${goto 260}RAM: ${memperc}%
${voffset 10}${goto 260}Home:${fs_used_perc /}%
${goto 260}serenity ${fs_used_perc /media/serenity}%
${goto 260}Dead space:${fs_used_perc /media/Dead_space}%
${goto 260}Exodus:${fs_used_perc /media/EXODUS}%
clock.lua lié avec conky.conf
--[[PIE CHART WIDGET by Wlourf v1.3 07 Jan. 2011
This widget draw a pie chart or a ring in a conky window.
More info on the parameters with pictures on this page :
http://u-scripts.blogspot.com/2010/04/pie-chart-widget.html
To call the script in a conky, use, before TEXT
lua_load /path/to/the/script/piechart.lua
lua_draw_hook_pre main_rings
and add one line (blank or not) after TEXT
Parameters are :
tableV -- table of labels and values {{label,conky_variable,conky_argument,convert to Go-Mo-Ko units (true/false) or unit}, ...}
-- this table is mandatory, others parameters are optionals
-- example :
tableV={
{"cpu 0","cpu","cpu0",100,"%"},
{"cpu 1","cpu","cpu1",100,"%"},
},
-- to know disk space, use this line :
tableV=read_df(false,true),
1st argument : show _media
2nd argument : sort output array
xc -- x center of the pie, default = conky_window.width/2
yc, -- y center of the pie, default = conky_window.height/2
radius_int -- internal radius in pixel, default = conky_window.width/6
radius_ext -- external radius in pixel, default = conky_window.width/4
first_angle -- first angle of the pie (in degrees), default=0
last_angle -- last angle of the pie (in degrees), default=360
type_arc, -- fill the arc in a linear way (ring) or radial way (pie), values l or r, default=l
inverse_l_arc -- inverse arc for rings (true/false), default=false
proportional -- display proportional sectors (true/false); default =false
gradient_effect -- gradient effect (true/false), default=true
line_length -- length for horizontal line (from radius_ext to end of line), default=radius_ext
line_thickness -- thickness of line, default=1
line_space -- vertical space between two lines, default=10 pixels
extend_line -- grow up the line (true/false) if length of text> line_length, default=true
nb_decimals -- number of decimals for numbers, default=1
show_text -- display text (true/false), default=true
font_name -- font, default "Japan"
font_size -- font size, default=12
font_color -- font color (for gradient) or nil (for constant color), default = nil
font_alpha -- font alpha, default=1
txt_offset -- space between text and line, default=1
txt_format -- string for formatting text, possibles values are : default = "&l : &v"
-- &l for label
-- &o for occupied percentage
-- &f for free percentage
-- &v for value
-- &n for free value (non-occupied)
-- &m for max value
-- &p for percentage value of full graph
tablebg -- table of tables of colours for background {colors,alpha}
tablefg -- table of tables of colours for foreground {colors,alpha}
draw_me -- if set to false, text is not drawn (default = true or 1)
it can be used with a conky string, if the string returns 1, the text is drawn :
example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",
v1.0 10/04/2010 original release
v1.1 15/05/2010 the parameters are in a table (pie_settings), only the values in pie_settings.tableV are mandatory
added an option to draw values like a ring (type_arc="l")
v1.2 26/05/2010 add inverse_l parameter (for type_arc="l")
bug fix : line_length problem
read_df function improved
v1.21 26/06/2010 rename some parameters and write more infos
v1.3 07/01/2011 Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation version 3 (GPLv3)
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-- MA 02110-1301, USA.
]]
require 'cairo'
--main function
function conky_main_pie()
--flag used in this script to display or not text informations
local file = io.open("/tmp/flag-conky-pie","r")
io.close()
local flag_show_text=(file == nil)
-- ------------------PARAMETERS TO SET-----------------------
--theses parameters are called many times so I put them into variables
local rad0,rad1=50,75
local lgth=75
local font_name,font_size="FreeSans",14
local col0,col1,col2=0x0920ff,0xc90016,0xec5f0a
local h=conky_window.height
--for the clock
local temp = os.date("*t")
local hour = temp.hour
if hour>12 then hour=hour-12 end
local hpc,mpc,spc=hour/12,temp.min/60,temp.sec/60
local pie_settings= {
--CLOCK
{
tableV={
{"hour.min","",1,1,""},
{"hour.min","",0,11,""},
},
xc=330,yc=272,
radius_int=110,
radius_ext=140,
first_angle=hpc*360,
last_angle=hpc*360+360,
show_text=false,
proportional=true,
tablefg={
{0xffbb00,0.5},
},
tablebg={
{0x79c4fd,0.5},
},
},
{
tableV={
{"hour.min","",1,1,""},
{"hour.min","",0,59,""},
},
xc=330,yc=272,
radius_int=125,
radius_ext=160,
first_angle=mpc*360,
last_angle=mpc*360+360,
show_text=false,
proportional=true,
tablefg={
{0xffbb00,0.5},
},
tablebg={
{0x79c4fd,1},
},
},
{
tableV={
{"hour.min","",1,1,""},
{"hour.min","",0,59,""},
},
xc=330,yc=272,
radius_int=145,
radius_ext=190,
first_angle=spc*360,
last_angle=spc*360+360,
show_text=false,
proportional=true,
tablefg={
{0xffbb00,0.5},
},
tablebg={
{0x79c4fd,1.5},
}
},
}
-------------------END OF PARAMETERS ---------------
local w=conky_window.width
local h=conky_window.height
local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
local cr = cairo_create(cs)
if tonumber(conky_parse('${updates}'))>5 then
for i in pairs(pie_settings) do
draw_pie(cr,pie_settings[i])
end
end
cairo_surface_destroy(cs)
cairo_destroy(cr)
cr=nil
end
function string:split(delimiter)
--source for the split function : http://www.wellho.net/resources/ex.php4?item=u108/split
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end
function rgb_to_r_g_b(colour, alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
function size_to_text(size,nb_dec)
local txt_v
if nb_dec<0 then nb_dec=0 end
size = tonumber(size)
if size>1024*1024*1024 then
txt_v=string.format("%."..nb_dec.."f Go",size/1024/1024/1024)
elseif size>1024*1024 then
txt_v=string.format("%."..nb_dec.."f Mo",size/1024/1024)
elseif size>1024 then
txt_v=string.format("%."..nb_dec.."f Ko",size/1024)
else
txt_v=string.format("%."..nb_dec.."f o",size)
end
return txt_v
end
function read_df(show_media,sort_table)
--read output of command df and return arrays of value for files systems
--reurn array of table {file syst, "", occupied space , total space , convert to G, M, K ...}
local f = io.popen("df")
local results={}
while true do
local line = f:read("*l")
if line == nil then break end
while string.match(line," ") do
line=string.gsub(line," "," ")
end
local arr_l=string.split(line," ")
local match = string.match(arr_l[1],"/")
if string.match(arr_l[1],"/") then
-- if not show_media then arr_l[6]=string.gsub(arr_l[6],"/media/","",1) end
-- table.insert(results,{arr_l[6],"",(arr_l[2]-arr_l[4])*1024,arr_l[2]*1024,true})
end
end
f:close()
if sort_table then
--how to sort table into table?
local flagS=true
while flagS do
for k=2, #results do
flagS=false
if tonumber(results[1][3])>tonumber(results[2][3]) then
local tmpV = results[1]
results[1] = results[2]
results[2] = tmpV
flagS=true
end
if tonumber(results[k][3])<tonumber(results[k-1][3]) then
local tmpV = results[k-1]
results[k-1] = results[k]
results[k] = tmpV
flagS=true
end
end
end
end
return results --array {file syst, occupied space , total space }
end
function draw_pie(cr,t)
if t.draw_me == true then t.draw_me = nil end
if t.draw_me ~= nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end
local lastAngle
local lastPt2
local tableV
if t.tableV==nil then
print ("No input values ...")
return
else
tableV=t.tableV
end
if t.xc==nil then t.xc=conky_window.width/2 end
if t.yc==nil then t.yc=conky_window.height/2 end
if t.radius_int==nil then t.radius_int =conky_window.width/6 end
if t.radius_ext==nil then t.radius_ext =conky_window.width/4 end
if t.first_angle==nil then t.first_angle =0 end
if t.last_angle==nil then t.last_angle=360 end
if t.proportional==nil then t.proportional=false end
if t.tablebg==nil then t.tablebg={{0xFFFFFF,0.5},{0xFFFFFF,0.5}} end
if t.tablefg==nil then t.tablefg={{0xFF0000,1},{0x00FF00,1}} end
if t.gradient_effect==nil then t.gradient_effect=true end
if t.show_text==nil then t.show_text=true end
if t.line_length==nil then t.line_length=t.radius_int end
if t.line_space==nil then t.line_space=10 end
if t.line_thickness==nil then t.line_thickness=1 end
if t.extend_line==nil then t.extend_line=true end
if t.font_name==nil then t.font_name="Japan" end
if t.font_size==nil then t.font_size=12 end
--if t.font_color==nil then t.font_color=0xFFFFFF end
if t.font_alpha==nil then t.font_alpha = 1 end
if t.txt_offset==nil then t.txt_offset = 1 end
if t.txt_format==nil then t.txt_format = "&l : &v" end
if t.nb_decimals==nil then t.nb_decimals=1 end
if t.type_arc==nil then t.type_arc="l" end
if t.inverse_l_arc==nil then t.inverse_l_arc=false end
local radiuspc
local angle0
local function draw_sector(tablecolor,colorindex,pc,lastAngle,angle,radius,radius_int,gradient_effect,type_arc,inverse_l_arc)
--draw a portion of arc
radiuspc=(radius-radius_int)*pc+radius_int
angle0=lastAngle
local val=1
if type_arc=="l" then
val=pc;radiuspc=radius
end
local angle1=angle*val
if type_arc=="l" and inverse_l_arc then
cairo_save(cr)
cairo_rotate(cr,angle0+angle)
if gradient_effect then
local pat = cairo_pattern_create_radial (0,0, radius_int, 0,0,radius)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
else
cairo_set_source_rgba(cr,rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
end
cairo_move_to(cr,0,-radius_int)
cairo_line_to(cr,0,-radiuspc)
cairo_rotate(cr,-math.pi/2)
cairo_arc_negative(cr,0,0,radiuspc,0,-angle1)
cairo_rotate(cr,-math.pi/2-angle1)
cairo_line_to(cr,0,radius_int)
cairo_rotate(cr,math.pi/2)
cairo_arc(cr,0,0,radius_int,0,angle1)
cairo_close_path (cr);
cairo_fill(cr)
cairo_restore(cr)
else
cairo_save(cr)
cairo_rotate(cr,angle0)
if gradient_effect then
local pat = cairo_pattern_create_radial (0,0, radius_int, 0,0,radius)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
else
cairo_set_source_rgba(cr,rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
end
cairo_move_to(cr,0,-radius_int)
cairo_line_to(cr,0,-radiuspc)
cairo_rotate(cr,-math.pi/2)
cairo_arc(cr,0,0,radiuspc,0,angle1)
cairo_rotate(cr,angle1-math.pi/2)
cairo_line_to(cr,0,radius_int)
cairo_rotate(cr,math.pi/2)
cairo_arc_negative(cr,0,0,radius_int,0,-angle1)
cairo_close_path (cr);
cairo_fill(cr)
cairo_restore(cr)
end
end
local function draw_lines(idx,nbArcs,angle,table_colors,idx_color,adjust,line_length,length_txt,txt_offset,radius,line_thickness,line_space,font_color,font_alpha)
--draw lines
local x0=radiuspc*math.sin(lastAngle+angle/2)
local y0=-radiuspc*math.cos(lastAngle+angle/2)
local x1=1.2*radius*math.sin(lastAngle+angle/2)
local y1=-1.2*radius*math.cos(lastAngle+angle/2)
local x2=line_length
local y2=y1
local x3,y3=nil,nil
if x0<=0 then
x2=-x2
end
if adjust then
if x0>0 and x2-x1<length_txt then x2=x1+length_txt end
if x0<=0 and x1-x2<length_txt then x2=x1-length_txt end
end
if idx>1 then
local dY = math.abs(y2-lastPt2[2])
if dY < line_space and lastPt2[1]*x1>0 then
if x0>0 then
y2 = line_space+lastPt2[2]
else
y2 = -line_space+lastPt2[2]
end
if (y2>y1 and x0>0) or (y2<y1 and x0<0 ) then
--x3 is for vertical segment if needed
x3,y3=x2,y2
x2=x1
if x3>0 then x3=x3+txt_offset end
else
local Z=intercept({x0,y0},{x1,y1},{0,y2},{1,y2})
x1,y1=Z[1],Z[2]
end
end
else
--remind x2,y2 of first value
--x2first,y2first = x2,y2
end
if font_color==nil then
cairo_set_source_rgba(cr,rgb_to_r_g_b(table_colors[idx_color][1],table_colors[idx_color][2]))
else
local pat = cairo_pattern_create_linear (x2,y2, x0,y0)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(font_color,font_alpha))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(table_colors[idx_color][1],table_colors[idx_color][2]))
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
end
cairo_move_to(cr,x0,y0)
cairo_line_to(cr,x1,y1)
cairo_line_to(cr,x2,y2)
if x3~=nil then
cairo_line_to(cr,x3,y3)
x2,y2=x3,y3
end
cairo_set_line_width(cr,line_thickness)
cairo_stroke(cr)
--lastAngle=lastAngle+angle
return {x2,y2}
end
local function intercept(p11,p12,p21,p22)
--calculate interscetion of two lines and return coordinates
local a1=(p12[2]-p11[2])/(p12[1]-p11[1])
local a2=(p22[2]-p21[2])/(p22[1]-p21[1])
local b1=p11[2]-a1*p11[1]
local b2=p21[2]-a2*p21[1]
local X=(b2-b1)/(a1-a2)
local Y=a1*X+b1
return {X,Y}
end
--some checks
if t.first_angle>=t.last_angle then
local tmp_angle=t.last_angle
t.last_angle=t.first_angle
t.first_angle=tmp_angle
print ("inversed angles")
end
if t.last_angle-t.first_angle>360 and t.first_angle>0 then
t.last_angle=360+t.first_angle
print ("reduce angles")
end
if t.last_angle+t.first_angle>360 and t.first_angle<=0 then
t.last_angle=360+t.first_angle
print ("reduce angles")
end
if t.radius_int<0 then t.radius_int =0 end
if t.radius_int>t.radius_ext then
local tmp_radius=t.radius_ext
t.radius_ext = t.radius_int
t.radius_int = tmp_radius
print ("inversed angles")
end
if t.radius_int==t.radius_ext then
t.radius_int=0
print ("int radius_ext set to 0")
end
--end of checks
cairo_save(cr)
cairo_translate(cr,t.xc,t.yc)
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND)
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND)
local nbArcs=#tableV
local anglefull= (t.last_angle-t.first_angle)*math.pi/180
local fullsize = 0
for i= 1,nbArcs do
fullsize=fullsize+tableV[i][4]
end
local cb,cf,angle=0,0,anglefull/nbArcs
lastAngle=t.first_angle*math.pi/180
lastPt2={nil,nil}
for i =1, nbArcs do
if t.proportional then
angle=tableV[i][4]/fullsize*anglefull
end
--set colours
cb,cf=cb+1,cf+1
if cb>#t.tablebg then cb=1 end
if cf>#t.tablefg then cf=1 end
local str
if tableV[i][2]~="" then
str=string.format('${%s %s}',tableV[i][2],tableV[i][3])
else
str = tableV[i][3]
end
str=conky_parse(str)
local value=tonumber(str)
if value==nil then value=0 end
--draw sectors
draw_sector(t.tablebg,cb,1,lastAngle,angle,t.radius_ext,t.radius_int,t.gradient_effect,t.type_arc,t.inverse_l_arc)
draw_sector(t.tablefg,cf,value/tableV[i][4],lastAngle,angle,t.radius_ext,t.radius_int,t.gradient_effect,t.type_arc,t.inverse_l_arc)
if t.show_text then
--draw text
local txt_l = tableV[i][1]
local txt_opc = round(100*value/tableV[i][4],t.nb_decimals).."%%"
local txt_fpc = round(100*(tableV[i][4]-value/tableV[i][4]),t.nb_decimals).."%%"
local txt_ov,txt_fv,txt_max
if tableV[i][5]==true then
txt_ov = size_to_text(value,t.nb_decimals)
txt_fv = size_to_text(tableV[i][4]-value,t.nb_decimals)
txt_max = size_to_text(tableV[i][4],t.nb_decimals)
else
if tableV[i][5]=="%" then tableV[i][5]="%%" end
txt_ov=string.format("%."..t.nb_decimals.."f ",value)..tableV[i][5]
txt_fv=string.format("%."..t.nb_decimals.."f",tableV[i][4]-value)..tableV[i][5]
txt_max=string.format("%."..t.nb_decimals.."f",tableV[i][4])..tableV[i][5]
end
local txt_pc = string.format("%."..t.nb_decimals.."f",100*tableV[i][4]/fullsize).."%%"
local txt_out = t.txt_format
txt_out = string.gsub(txt_out,"&l",txt_l) --label
txt_out = string.gsub(txt_out,"&o",txt_opc)--occ. %
txt_out = string.gsub(txt_out,"&f",txt_fpc)--free %
txt_out = string.gsub(txt_out,"&v",txt_ov) --occ. value
txt_out = string.gsub(txt_out,"&n",txt_fv) --free value
txt_out = string.gsub(txt_out,"&m",txt_max)--max
txt_out = string.gsub(txt_out,"&p",txt_pc)--percent
local te=cairo_text_extents_t:create()
tolua.takeownership(te)
cairo_set_font_size(cr,t.font_size)
cairo_select_font_face(cr, t.font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_text_extents (cr,txt_out,te)
--draw lines
lastPt2=draw_lines(i,nbArcs,angle,t.tablefg,cf,t.extend_line,t.line_length+t.radius_ext,
te.width + te.x_bearing,t.txt_offset,t.radius_ext,t.line_thickness,t.line_space,t.font_color,t.font_alpha)
local xA=lastPt2[1]
local yA=lastPt2[2]-t.line_thickness-t.txt_offset
if xA>0 then xA = xA-(te.width + te.x_bearing) end
cairo_move_to(cr,xA,yA)
cairo_show_text(cr,txt_out)
end
lastAngle=lastAngle+angle
end
lastAngle = nil
lastPt2 = nil
cairo_restore(cr)
end
--[[END OF PIE CHART WIDGET]]
cpu
# Conky settings #
background no
update_interval 1
cpu_avg_samples 2
net_avg_samples 2
override_utf8_locale yes
double_buffer yes
no_buffers yes
text_buffer_size 2048
imlib_cache_size 0
# Window specifications #
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
border_inner_margin 10
border_outer_margin 10
minimum_size 175 175
maximum_width 175
alignment tr
gap_x 375
gap_y 110
# Graphics settings #
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
# Text settings #
use_xft yes
xftfont caviar dreams:size=8
xftalpha 0.5
uppercase no
# Lua Load #
lua_load ~/conky/script/cpu.lua
lua_draw_hook_pre main_bars
text
${font encient bold Video:size=10}${color 0e95fd}${goto 100}CPU
${goto 50}1 ${goto 85}2 ${goto 120}3 ${goto 155}4
${voffset 120}${goto 50}${color #FF6E00}${cpu cpu1}% ${goto 80}${color #CB0C29}${cpu cpu2}% ${goto 120}${color #49A835}${cpu cpu3}% ${goto 160}${color #872DB3}${cpu cpu4}%
cpu.lua
--[[ BARGRAPH WIDGET
v2.1 by wlourf (07 Jan. 2011)
this widget draws a bargraph with different effects
http://u-scripts.blogspot.com/2010/07/bargraph-widget.html
To call the script in a conky, use, before TEXT
lua_load /path/to/the/script/bargraph.lua
lua_draw_hook_pre main_rings
and add one line (blank or not) after TEXT
Parameters are :
3 parameters are mandatory
name - the name of the conky variable to display, for example for {$cpu cpu0}, just write name="cpu"
arg - the argument of the above variable, for example for {$cpu cpu0}, just write arg="cpu0"
arg can be a numerical value if name=""
max - the maximum value the above variable can reach, for example, for {$cpu cpu0}, just write max=100
Optional parameters:
x,y - coordinates of the starting point of the bar, default = middle of the conky window
cap - end of cap line, ossibles values are r,b,s (for round, butt, square), default="b"
http://www.cairographics.org/samples/set_line_cap/
angle - angle of rotation of the bar in degress, default = 0 (i.e. a vertical bar)
set to 90 for an horizontal bar
skew_x - skew bar around x axis, default = 0
skew_y - skew bar around y axis, default = 0
blocks - number of blocks to display for a bar (values >0) , default= 10
height - height of a block, default=10 pixels
width - width of a block, default=20 pixels
space - space between 2 blocks, default=2 pixels
angle_bar - this angle is used to draw a bar on a circular way (ok, this is no more a bar !) default=0
radius - for cicular bars, internal radius, default=0
with radius, parameter width has no more effect.
Colours below are defined into braces {colour in hexadecimal, alpha}
fg_colour - colour of a block ON, default= {0x00FF00,1}
bg_colour - colour of a block OFF, default = {0x00FF00,0.5}
alarm - threshold, values after this threshold will use alarm_colour colour , default=max
alarm_colour - colour of a block greater than alarm, default=fg_colour
smooth - (true or false), create a gradient from fg_colour to bg_colour, default=false
mid_colour - colours to add to gradient, with this syntax {position into the gradient (0 to1), colour hexa, alpha}
for example, this table {{0.25,0xff0000,1},{0.5,0x00ff00,1},{0.75,0x0000ff,1}} will add
3 colurs to gradient created by fg_colour and alarm_colour, default=no mid_colour
led_effect - add LED effects to each block, default=no led_effect
if smooth=true, led_effect is not used
possibles values : "r","a","e" for radial, parallelel, perdendicular to the bar (just try!)
led_effect has to be used with theses colours :
fg_led - middle colour of a block ON, default = fg_colour
bg_led - middle colour of a block OFF, default = bg_colour
alarm_led - middle colour of a block > ALARM, default = alarm_colour
reflection parameters, not avaimable for circular bars
reflection_alpha - add a reflection effect (values from 0 to 1) default = 0 = no reflection
other values = starting opacity
reflection_scale - scale of the reflection (default = 1 = height of text)
reflection_length - length of reflection, define where the opacity will be set to zero
calues from 0 to 1, default =1
reflection - position of reflection, relative to a vertical bar, default="b"
possibles values are : "b","t","l","r" for bottom, top, left, right
draw_me - if set to false, text is not drawn (default = true or 1)
it can be used with a conky string, if the string returns 1, the text is drawn :
example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",
v1.0 (10 Feb. 2010) original release
v1.1 (13 Feb. 2010) numeric values can be passed instead conky stats with parameters name="", arg = numeric_value
v1.2 (28 Feb. 2010) just renamed the widget to bargraph
v1.3 (03 Mar. 2010) added parameters radius & angle_bar to draw the bar in a circular way
v2.0 (12 Jul. 2010) rewrite script + add reflection effects and parameters are now set into tables
v2.1 (07 Jan. 2011) Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation version 3 (GPLv3)
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-- MA 02110-1301, USA.
]]
require 'cairo'
----------------START OF PARAMETERS ----------
function conky_main_bars()
local bars_settings={
{
name="cpu",
arg="cpu1",
max=60,
bg_colour={0xA6F49F,0},
fg_colour={0x00ff00,0},
x=50,y=170,
blocks=20,
height=4,width=15,
led_effect="r",
fg_led={0xFF6E00,1},
bg_led={0x79c4fd,0.5},
draw_me=true,
},
{
name="cpu",
arg="cpu2",
max=60,
bg_colour={0xA6F49F,0},
fg_colour={0x00ff00,0},
x=85,y=170,
blocks=20,
height=4,width=15,
led_effect="r",
fg_led={0xCB0C29,1},
bg_led={0x79c4fd,0.5},
draw_me=true,
},
{
name="cpu",
arg="cpu3",
max=60,
bg_colour={0xA6F49F,0},
fg_colour={0x00ff00,0},
x=120,y=170,
blocks=20,
height=4,width=15,
led_effect="r",
fg_led={0x49A835,1},
bg_led={0x79c4fd,0.5},
draw_me=true,
},
{
name="cpu",
arg="cpu4",
max=60,
bg_colour={0xA6F49F,0},
fg_colour={0x00ff00,0},
x=155,y=170,
blocks=20,
height=4,width=15,
led_effect="r",
fg_led={0x872DB3,1},
bg_led={0x79c4fd,0.5},
draw_me=true,
},
}
-----------END OF PARAMETERS--------------
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)
cr = cairo_create(cs)
--prevent segmentation error when reading cpu state
if tonumber(conky_parse('${updates}'))>3 then
for i in pairs(bars_settings) do
draw_multi_bar_graph(bars_settings[i])
end
end
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end
function draw_multi_bar_graph(t)
cairo_save(cr)
--check values
if t.draw_me == true then t.draw_me = nil end
if t.draw_me ~= nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end
if t.name==nil and t.arg==nil then
print ("No input values ... use parameters 'name' with 'arg' or only parameter 'arg' ")
return
end
if t.max==nil then
print ("No maximum value defined, use 'max'")
return
end
if t.name==nil then t.name="" end
if t.arg==nil then t.arg="" end
--set default values
if t.x == nil then t.x = conky_window.width/2 end
if t.y == nil then t.y = conky_window.height/2 end
if t.blocks == nil then t.blocks=10 end
if t.height == nil then t.height=10 end
if t.angle == nil then t.angle=0 end
t.angle = t.angle*math.pi/180
--line cap style
if t.cap==nil then t.cap = "b" end
local cap="b"
for i,v in ipairs({"s","r","b"}) do
if v==t.cap then cap=v end
end
local delta=0
if t.cap=="r" or t.cap=="s" then delta = t.height end
if cap=="s" then cap = CAIRO_LINE_CAP_SQUARE
elseif cap=="r" then
cap = CAIRO_LINE_CAP_ROUND
elseif cap=="b" then
cap = CAIRO_LINE_CAP_BUTT
end
--end line cap style
--if t.led_effect == nil then t.led_effect="r" end
if t.width == nil then t.width=20 end
if t.space == nil then t.space=2 end
if t.radius == nil then t.radius=0 end
if t.angle_bar == nil then t.angle_bar=0 end
t.angle_bar = t.angle_bar*math.pi/360 --halt angle
--colours
if t.bg_colour == nil then t.bg_colour = {0x00FF00,0.5} end
if #t.bg_colour~=2 then t.bg_colour = {0x00FF00,0.5} end
if t.fg_colour == nil then t.fg_colour = {0x00FF00,1} end
if #t.fg_colour~=2 then t.fg_colour = {0x00FF00,1} end
if t.alarm_colour == nil then t.alarm_colour = t.fg_colour end
if #t.alarm_colour~=2 then t.alarm_colour = t.fg_colour end
if t.mid_colour ~= nil then
for i=1, #t.mid_colour do
if #t.mid_colour[i]~=3 then
print ("error in mid_color table")
t.mid_colour[i]={1,0xFFFFFF,1}
end
end
end
if t.bg_led ~= nil and #t.bg_led~=2 then t.bg_led = t.bg_colour end
if t.fg_led ~= nil and #t.fg_led~=2 then t.fg_led = t.fg_colour end
if t.alarm_led~= nil and #t.alarm_led~=2 then t.alarm_led = t.fg_led end
if t.led_effect~=nil then
if t.bg_led == nil then t.bg_led = t.bg_colour end
if t.fg_led == nil then t.fg_led = t.fg_colour end
if t.alarm_led == nil then t.alarm_led = t.fg_led end
end
if t.alarm==nil then t.alarm = t.max end --0.8*t.max end
if t.smooth == nil then t.smooth = false end
if t.skew_x == nil then
t.skew_x=0
else
t.skew_x = math.pi*t.skew_x/180
end
if t.skew_y == nil then
t.skew_y=0
else
t.skew_y = math.pi*t.skew_y/180
end
if t.reflection_alpha==nil then t.reflection_alpha=0 end
if t.reflection_length==nil then t.reflection_length=1 end
if t.reflection_scale==nil then t.reflection_scale=1 end
--end of default values
local function rgb_to_r_g_b(col_a)
return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
end
--functions used to create patterns
local function create_smooth_linear_gradient(x0,y0,x1,y1)
local pat = cairo_pattern_create_linear (x0,y0,x1,y1)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
if t.mid_colour ~=nil then
for i=1, #t.mid_colour do
cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
end
end
return pat
end
local function create_smooth_radial_gradient(x0,y0,r0,x1,y1,r1)
local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(t.fg_colour))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(t.alarm_colour))
if t.mid_colour ~=nil then
for i=1, #t.mid_colour do
cairo_pattern_add_color_stop_rgba (pat, t.mid_colour[i][1], rgb_to_r_g_b({t.mid_colour[i][2],t.mid_colour[i][3]}))
end
end
return pat
end
local function create_led_linear_gradient(x0,y0,x1,y1,col_alp,col_led)
local pat = cairo_pattern_create_linear (x0,y0,x1,y1) ---delta, 0,delta+ t.width,0)
cairo_pattern_add_color_stop_rgba (pat, 0.0, rgb_to_r_g_b(col_alp))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1.0, rgb_to_r_g_b(col_alp))
return pat
end
local function create_led_radial_gradient(x0,y0,r0,x1,y1,r1,col_alp,col_led,mode)
local pat = cairo_pattern_create_radial (x0,y0,r0,x1,y1,r1)
if mode==3 then
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_alp))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))
else
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(col_led))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(col_alp))
end
return pat
end
local function draw_single_bar()
--this fucntion is used for bars with a single block (blocks=1) but
--the drawing is cut in 3 blocks : value/alarm/background
--not zvzimzblr for circular bar
local function create_pattern(col_alp,col_led,bg)
local pat
if not t.smooth then
if t.led_effect=="e" then
pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
elseif t.led_effect=="a" then
pat = create_led_linear_gradient (t.width/2, 0,t.width/2,-t.height,col_alp,col_led)
elseif t.led_effect=="r" then
pat = create_led_radial_gradient (t.width/2, -t.height/2, 0, t.width/2,-t.height/2,t.height/1.5,col_alp,col_led,2)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
else
if bg then
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.bg_colour))
else
pat = create_smooth_linear_gradient(t.width/2, 0, t.width/2,-t.height)
end
end
return pat
end
local y1=-t.height*pct/100
local y2,y3
if pct>(100*t.alarm/t.max) then
y1 = -t.height*t.alarm/100
y2 = -t.height*pct/100
if t.smooth then y1=y2 end
end
if t.angle_bar==0 then
--block for fg value
local pat = create_pattern(t.fg_colour,t.fg_led,false)
cairo_set_source(cr,pat)
cairo_rectangle(cr,0,0,t.width,y1)
cairo_fill(cr)
cairo_pattern_destroy(pat)
-- block for alarm value
if not t.smooth and y2 ~=nil then
pat = create_pattern(t.alarm_colour,t.alarm_led,false)
cairo_set_source(cr,pat)
cairo_rectangle(cr,0,y1,t.width,y2-y1)
cairo_fill(cr)
y3=y2
cairo_pattern_destroy(pat)
else
y2,y3=y1,y1
end
-- block for bg value
cairo_rectangle(cr,0,y2,t.width,-t.height-y3)
pat = create_pattern(t.bg_colour,t.bg_led,true)
cairo_set_source(cr,pat)
cairo_pattern_destroy(pat)
cairo_fill(cr)
end
end --end single bar
local function draw_multi_bar()
--function used for bars with 2 or more blocks
for pt = 1,t.blocks do
--set block y
local y1 = -(pt-1)*(t.height+t.space)
local light_on=false
--set colors
local col_alp = t.bg_colour
local col_led = t.bg_led
if pct>=(100/t.blocks) or pct>0 then --ligth on or not the block
if pct>=(pcb*(pt-1)) then
light_on = true
col_alp = t.fg_colour
col_led = t.fg_led
if pct>=(100*t.alarm/t.max) and (pcb*pt)>(100*t.alarm/t.max) then
col_alp = t.alarm_colour
col_led = t.alarm_led
end
end
end
--set colors
--have to try to create gradients outside the loop ?
local pat
if not t.smooth then
if t.angle_bar==0 then
if t.led_effect=="e" then
pat = create_led_linear_gradient (-delta, 0,delta+ t.width,0,col_alp,col_led)
elseif t.led_effect=="a" then
pat = create_led_linear_gradient (t.width/2, -t.height/2+y1,t.width/2,0+t.height/2+y1,col_alp,col_led)
elseif t.led_effect=="r" then
pat = create_led_radial_gradient (t.width/2, y1, 0, t.width/2,y1,t.width/1.5,col_alp,col_led,2)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
else
if t.led_effect=="a" then
pat = create_led_radial_gradient (0, 0, t.radius+(t.height+t.space)*(pt-1),
0, 0, t.radius+(t.height+t.space)*(pt),
col_alp,col_led,3)
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(col_alp))
end
end
else
if light_on then
if t.angle_bar==0 then
pat = create_smooth_linear_gradient(t.width/2, t.height/2, t.width/2,-(t.blocks-0.5)*(t.height+t.space))
else
pat = create_smooth_radial_gradient(0, 0, (t.height+t.space), 0,0,(t.blocks+1)*(t.height+t.space),2)
end
else
pat = cairo_pattern_create_rgba (rgb_to_r_g_b(t.bg_colour))
end
end
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
--draw a block
if t.angle_bar==0 then
cairo_move_to(cr,0,y1)
cairo_line_to(cr,t.width,y1)
else
cairo_arc( cr,0,0,
t.radius+(t.height+t.space)*(pt)-t.height/2,
-t.angle_bar -math.pi/2 ,
t.angle_bar -math.pi/2)
end
cairo_stroke(cr)
end
end
local function setup_bar_graph()
--function used to retrieve the value to display and to set the cairo structure
if t.blocks ~=1 then t.y=t.y-t.height/2 end
local value = 0
if t.name ~="" then
value = tonumber(conky_parse(string.format('${%s %s}', t.name, t.arg)))
--$to_bytes doesn't work when value has a decimal point,
--https://garage.maemo.org/plugins/ggit/browse.php/?p=monky;a=commitdiff;h=174c256c81a027a2ea406f5f37dc036fac0a524b;hp=d75e2db5ed3fc788fb8514121f67316ac3e5f29f
--http://sourceforge.net/tracker/index.php?func=detail&aid=3000865&group_id=143975&atid=757310
--conky bug?
--value = (conky_parse(string.format('${%s %s}', t.name, t.arg)))
--if string.match(value,"%w") then
-- value = conky_parse(string.format('${to_bytes %s}',value))
--end
else
value = tonumber(t.arg)
end
if value==nil then value =0 end
pct = 100*value/t.max
pcb = 100/t.blocks
cairo_set_line_width (cr, t.height)
cairo_set_line_cap (cr, cap)
cairo_translate(cr,t.x,t.y)
cairo_rotate(cr,t.angle)
local matrix0 = cairo_matrix_t:create()
tolua.takeownership(matrix0)
cairo_matrix_init (matrix0, 1,t.skew_y,t.skew_x,1,0,0)
cairo_transform(cr,matrix0)
--call the drawing function for blocks
if t.blocks==1 and t.angle_bar==0 then
draw_single_bar()
if t.reflection=="t" or t.reflection=="b" then cairo_translate(cr,0,-t.height) end
else
draw_multi_bar()
end
--dot for reminder
--[[
if t.blocks ~=1 then
cairo_set_source_rgba(cr,1,0,0,1)
cairo_arc(cr,0,t.height/2,3,0,2*math.pi)
cairo_fill(cr)
else
cairo_set_source_rgba(cr,1,0,0,1)
cairo_arc(cr,0,0,3,0,2*math.pi)
cairo_fill(cr)
end]]
--call the drawing function for reflection and prepare the mask used
if t.reflection_alpha>0 and t.angle_bar==0 then
local pat2
local matrix1 = cairo_matrix_t:create()
tolua.takeownership(matrix1)
if t.angle_bar==0 then
pts={-delta/2,(t.height+t.space)/2,t.width+delta,-(t.height+t.space)*(t.blocks)}
if t.reflection=="t" then
cairo_matrix_init (matrix1,1,0,0,-t.reflection_scale,0,-(t.height+t.space)*(t.blocks-0.5)*2*(t.reflection_scale+1)/2)
pat2 = cairo_pattern_create_linear (t.width/2,-(t.height+t.space)*(t.blocks),t.width/2,(t.height+t.space)/2)
elseif t.reflection=="r" then
cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,delta+2*t.width,0)
pat2 = cairo_pattern_create_linear (delta/2+t.width,0,-delta/2,0)
elseif t.reflection=="l" then
cairo_matrix_init (matrix1,-t.reflection_scale,0,0,1,-delta,0)
pat2 = cairo_pattern_create_linear (-delta/2,0,delta/2+t.width,-0)
else --bottom
cairo_matrix_init (matrix1,1,0,0,-1*t.reflection_scale,0,(t.height+t.space)*(t.reflection_scale+1)/2)
pat2 = cairo_pattern_create_linear (t.width/2,(t.height+t.space)/2,t.width/2,-(t.height+t.space)*(t.blocks))
end
end
cairo_transform(cr,matrix1)
if t.blocks==1 and t.angle_bar==0 then
draw_single_bar()
cairo_translate(cr,0,-t.height/2)
else
draw_multi_bar()
end
cairo_set_line_width(cr,0.01)
cairo_pattern_add_color_stop_rgba (pat2, 0,0,0,0,1-t.reflection_alpha)
cairo_pattern_add_color_stop_rgba (pat2, t.reflection_length,0,0,0,1)
if t.angle_bar==0 then
cairo_rectangle(cr,pts[1],pts[2],pts[3],pts[4])
end
cairo_clip_preserve(cr)
cairo_set_operator(cr,CAIRO_OPERATOR_CLEAR)
cairo_stroke(cr)
cairo_mask(cr,pat2)
cairo_pattern_destroy(pat2)
cairo_set_operator(cr,CAIRO_OPERATOR_OVER)
end --reflection
pct,pcb=nil
end --setup_bar_graph()
--start here !
setup_bar_graph()
cairo_restore(cr)
end
net
# Conky settings #
background no
update_interval 1
cpu_avg_samples 2
net_avg_samples 2
override_utf8_locale yes
double_buffer yes
no_buffers yes
text_buffer_size 2048
imlib_cache_size 0
# Window specifications #
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
border_inner_margin 10
border_outer_margin 10
minimum_size 175 175
maximum_width 175
alignment tr
gap_x 1120
gap_y 110
# Graphics settings #
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
# Text settings #
use_xft yes
xftfont caviar dreams:size=8
xftalpha 0.5
uppercase no
# Lua Load #
lua_load /home/maestroom/conky/script/net.lua
lua_draw_hook_pre main_pie
text
${font caviar dreams:size=12}
${voffset 50}${color 85cb8d}${goto 15}down:${color ec5f0a}${goto 130}up:
${goto 15}${color 85cb8d}${downspeed eth2}${goto 130}${color ec5f0a}${upspeed eth2}
net.lua
--[[PIE CHART WIDGET by Wlourf v1.3 07 Jan. 2011
This widget draw a pie chart or a ring in a conky window.
More info on the parameters with pictures on this page :
http://u-scripts.blogspot.com/2010/04/pie-chart-widget.html
To call the script in a conky, use, before TEXT
lua_load /path/to/the/script/piechart.lua
lua_draw_hook_pre main_rings
and add one line (blank or not) after TEXT
Parameters are :
tableV -- table of labels and values {{label,conky_variable,conky_argument,convert to Go-Mo-Ko units (true/false) or unit}, ...}
-- this table is mandatory, others parameters are optionals
-- example :
tableV={
{"cpu 0","cpu","cpu0",100,"%"},
{"cpu 1","cpu","cpu1",100,"%"},
},
-- to know disk space, use this line :
tableV=read_df(false,true),
1st argument : show _media
2nd argument : sort output array
xc -- x center of the pie, default = conky_window.width/2
yc, -- y center of the pie, default = conky_window.height/2
radius_int -- internal radius in pixel, default = conky_window.width/6
radius_ext -- external radius in pixel, default = conky_window.width/4
first_angle -- first angle of the pie (in degrees), default=0
last_angle -- last angle of the pie (in degrees), default=360
type_arc, -- fill the arc in a linear way (ring) or radial way (pie), values l or r, default=l
inverse_l_arc -- inverse arc for rings (true/false), default=false
proportional -- display proportional sectors (true/false); default =false
gradient_effect -- gradient effect (true/false), default=true
line_length -- length for horizontal line (from radius_ext to end of line), default=radius_ext
line_thickness -- thickness of line, default=1
line_space -- vertical space between two lines, default=10 pixels
extend_line -- grow up the line (true/false) if length of text> line_length, default=true
nb_decimals -- number of decimals for numbers, default=1
show_text -- display text (true/false), default=true
font_name -- font, default "Japan"
font_size -- font size, default=12
font_color -- font color (for gradient) or nil (for constant color), default = nil
font_alpha -- font alpha, default=1
txt_offset -- space between text and line, default=1
txt_format -- string for formatting text, possibles values are : default = "&l : &v"
-- &l for label
-- &o for occupied percentage
-- &f for free percentage
-- &v for value
-- &n for free value (non-occupied)
-- &m for max value
-- &p for percentage value of full graph
tablebg -- table of tables of colours for background {colors,alpha}
tablefg -- table of tables of colours for foreground {colors,alpha}
draw_me -- if set to false, text is not drawn (default = true or 1)
it can be used with a conky string, if the string returns 1, the text is drawn :
example : "${if_empty ${wireless_essid wlan0}}${else}1$endif",
v1.0 10/04/2010 original release
v1.1 15/05/2010 the parameters are in a table (pie_settings), only the values in pie_settings.tableV are mandatory
added an option to draw values like a ring (type_arc="l")
v1.2 26/05/2010 add inverse_l parameter (for type_arc="l")
bug fix : line_length problem
read_df function improved
v1.21 26/06/2010 rename some parameters and write more infos
v1.3 07/01/2011 Add draw_me parameter and correct memory leaks, thanks to "Creamy Goodness"
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation version 3 (GPLv3)
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-- MA 02110-1301, USA.
]]
require 'cairo'
--main function
function conky_main_pie()
--flag used in this script to display or not text informations
local file = io.open("/tmp/flag-conky-pie","r")
io.close()
local flag_show_text=(file == nil)
-- ------------------PARAMETERS TO SET-----------------------
--theses parameters are called many times so I put them into variables
local rad0,rad1=50,75
local lgth=75
local font_name,font_size="FreeSans",14
local col0,col1,col2=0x85cb8d,0xc90016,0xec5f0a
local h=conky_window.height
--for the clock
local temp = os.date("*t")
local hour = temp.hour
if hour>12 then hour=hour-12 end
local hpc,mpc,spc=hour/12,temp.min/60,temp.sec/60
local pie_settings= {
{--CIRCLE 1 : ARCS 1 & 2 INTERNET SPEED
tableV={
{"dl","downspeedf","eth2",800,"kb/s"},
{"ul","upspeedf","eth2",300,"kb/s"},
},
xc=105,
yc=h-135,
radius_int=40,
radius_ext=rad1,
first_angle=-90,
last_angle=90,
type_arc="r",
line_length=30,
show_text=false,
txt_format="&l : &v",
tablebg={
{0x79c4fd,0.5},
},
tablefg={
{col0,1},
{col1,1},
}
},
}
-------------------END OF PARAMETERS ---------------
local w=conky_window.width
local h=conky_window.height
local cs=cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, w, h)
local cr = cairo_create(cs)
if tonumber(conky_parse('${updates}'))>5 then
for i in pairs(pie_settings) do
draw_pie(cr,pie_settings[i])
end
end
cairo_surface_destroy(cs)
cairo_destroy(cr)
cr=nil
end
function string:split(delimiter)
--source for the split function : http://www.wellho.net/resources/ex.php4?item=u108/split
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end
function rgb_to_r_g_b(colour, alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
function size_to_text(size,nb_dec)
local txt_v
if nb_dec<0 then nb_dec=0 end
size = tonumber(size)
if size>1024*1024*1024 then
txt_v=string.format("%."..nb_dec.."f Go",size/1024/1024/1024)
elseif size>1024*1024 then
txt_v=string.format("%."..nb_dec.."f Mo",size/1024/1024)
elseif size>1024 then
txt_v=string.format("%."..nb_dec.."f Ko",size/1024)
else
txt_v=string.format("%."..nb_dec.."f o",size)
end
return txt_v
end
function read_df(show_media,sort_table)
--read output of command df and return arrays of value for files systems
--reurn array of table {file syst, "", occupied space , total space , convert to G, M, K ...}
local f = io.popen("df")
local results={}
while true do
local line = f:read("*l")
if line == nil then break end
while string.match(line," ") do
line=string.gsub(line," "," ")
end
local arr_l=string.split(line," ")
local match = string.match(arr_l[1],"/")
if string.match(arr_l[1],"/") then
-- if not show_media then arr_l[6]=string.gsub(arr_l[6],"/media/","",1) end
-- table.insert(results,{arr_l[6],"",(arr_l[2]-arr_l[4])*1024,arr_l[2]*1024,true})
end
end
f:close()
if sort_table then
--how to sort table into table?
local flagS=true
while flagS do
for k=2, #results do
flagS=false
if tonumber(results[1][3])>tonumber(results[2][3]) then
local tmpV = results[1]
results[1] = results[2]
results[2] = tmpV
flagS=true
end
if tonumber(results[k][3])<tonumber(results[k-1][3]) then
local tmpV = results[k-1]
results[k-1] = results[k]
results[k] = tmpV
flagS=true
end
end
end
end
return results --array {file syst, occupied space , total space }
end
function draw_pie(cr,t)
if t.draw_me == true then t.draw_me = nil end
if t.draw_me ~= nil and conky_parse(tostring(t.draw_me)) ~= "1" then return end
local lastAngle
local lastPt2
local tableV
if t.tableV==nil then
print ("No input values ...")
return
else
tableV=t.tableV
end
if t.xc==nil then t.xc=conky_window.width/2 end
if t.yc==nil then t.yc=conky_window.height/2 end
if t.radius_int==nil then t.radius_int =conky_window.width/6 end
if t.radius_ext==nil then t.radius_ext =conky_window.width/4 end
if t.first_angle==nil then t.first_angle =0 end
if t.last_angle==nil then t.last_angle=360 end
if t.proportional==nil then t.proportional=false end
if t.tablebg==nil then t.tablebg={{0xFFFFFF,0.5},{0xFFFFFF,0.5}} end
if t.tablefg==nil then t.tablefg={{0xFF0000,1},{0x00FF00,1}} end
if t.gradient_effect==nil then t.gradient_effect=true end
if t.show_text==nil then t.show_text=true end
if t.line_length==nil then t.line_length=t.radius_int end
if t.line_space==nil then t.line_space=10 end
if t.line_thickness==nil then t.line_thickness=1 end
if t.extend_line==nil then t.extend_line=true end
if t.font_name==nil then t.font_name="Japan" end
if t.font_size==nil then t.font_size=12 end
--if t.font_color==nil then t.font_color=0xFFFFFF end
if t.font_alpha==nil then t.font_alpha = 1 end
if t.txt_offset==nil then t.txt_offset = 1 end
if t.txt_format==nil then t.txt_format = "&l : &v" end
if t.nb_decimals==nil then t.nb_decimals=1 end
if t.type_arc==nil then t.type_arc="l" end
if t.inverse_l_arc==nil then t.inverse_l_arc=false end
local radiuspc
local angle0
local function draw_sector(tablecolor,colorindex,pc,lastAngle,angle,radius,radius_int,gradient_effect,type_arc,inverse_l_arc)
--draw a portion of arc
radiuspc=(radius-radius_int)*pc+radius_int
angle0=lastAngle
local val=1
if type_arc=="l" then
val=pc;radiuspc=radius
end
local angle1=angle*val
if type_arc=="l" and inverse_l_arc then
cairo_save(cr)
cairo_rotate(cr,angle0+angle)
if gradient_effect then
local pat = cairo_pattern_create_radial (0,0, radius_int, 0,0,radius)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
else
cairo_set_source_rgba(cr,rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
end
cairo_move_to(cr,0,-radius_int)
cairo_line_to(cr,0,-radiuspc)
cairo_rotate(cr,-math.pi/2)
cairo_arc_negative(cr,0,0,radiuspc,0,-angle1)
cairo_rotate(cr,-math.pi/2-angle1)
cairo_line_to(cr,0,radius_int)
cairo_rotate(cr,math.pi/2)
cairo_arc(cr,0,0,radius_int,0,angle1)
cairo_close_path (cr);
cairo_fill(cr)
cairo_restore(cr)
else
cairo_save(cr)
cairo_rotate(cr,angle0)
if gradient_effect then
local pat = cairo_pattern_create_radial (0,0, radius_int, 0,0,radius)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_pattern_add_color_stop_rgba (pat, 0.5, rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(tablecolor[colorindex][1],0))
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
else
cairo_set_source_rgba(cr,rgb_to_r_g_b(tablecolor[colorindex][1],tablecolor[colorindex][2]))
end
cairo_move_to(cr,0,-radius_int)
cairo_line_to(cr,0,-radiuspc)
cairo_rotate(cr,-math.pi/2)
cairo_arc(cr,0,0,radiuspc,0,angle1)
cairo_rotate(cr,angle1-math.pi/2)
cairo_line_to(cr,0,radius_int)
cairo_rotate(cr,math.pi/2)
cairo_arc_negative(cr,0,0,radius_int,0,-angle1)
cairo_close_path (cr);
cairo_fill(cr)
cairo_restore(cr)
end
end
local function draw_lines(idx,nbArcs,angle,table_colors,idx_color,adjust,line_length,length_txt,txt_offset,radius,line_thickness,line_space,font_color,font_alpha)
--draw lines
local x0=radiuspc*math.sin(lastAngle+angle/2)
local y0=-radiuspc*math.cos(lastAngle+angle/2)
local x1=1.2*radius*math.sin(lastAngle+angle/2)
local y1=-1.2*radius*math.cos(lastAngle+angle/2)
local x2=line_length
local y2=y1
local x3,y3=nil,nil
if x0<=0 then
x2=-x2
end
if adjust then
if x0>0 and x2-x1<length_txt then x2=x1+length_txt end
if x0<=0 and x1-x2<length_txt then x2=x1-length_txt end
end
if idx>1 then
local dY = math.abs(y2-lastPt2[2])
if dY < line_space and lastPt2[1]*x1>0 then
if x0>0 then
y2 = line_space+lastPt2[2]
else
y2 = -line_space+lastPt2[2]
end
if (y2>y1 and x0>0) or (y2<y1 and x0<0 ) then
--x3 is for vertical segment if needed
x3,y3=x2,y2
x2=x1
if x3>0 then x3=x3+txt_offset end
else
local Z=intercept({x0,y0},{x1,y1},{0,y2},{1,y2})
x1,y1=Z[1],Z[2]
end
end
else
--remind x2,y2 of first value
--x2first,y2first = x2,y2
end
if font_color==nil then
cairo_set_source_rgba(cr,rgb_to_r_g_b(table_colors[idx_color][1],table_colors[idx_color][2]))
else
local pat = cairo_pattern_create_linear (x2,y2, x0,y0)
cairo_pattern_add_color_stop_rgba (pat, 0, rgb_to_r_g_b(font_color,font_alpha))
cairo_pattern_add_color_stop_rgba (pat, 1, rgb_to_r_g_b(table_colors[idx_color][1],table_colors[idx_color][2]))
cairo_set_source (cr, pat)
cairo_pattern_destroy(pat)
end
cairo_move_to(cr,x0,y0)
cairo_line_to(cr,x1,y1)
cairo_line_to(cr,x2,y2)
if x3~=nil then
cairo_line_to(cr,x3,y3)
x2,y2=x3,y3
end
cairo_set_line_width(cr,line_thickness)
cairo_stroke(cr)
--lastAngle=lastAngle+angle
return {x2,y2}
end
local function intercept(p11,p12,p21,p22)
--calculate interscetion of two lines and return coordinates
local a1=(p12[2]-p11[2])/(p12[1]-p11[1])
local a2=(p22[2]-p21[2])/(p22[1]-p21[1])
local b1=p11[2]-a1*p11[1]
local b2=p21[2]-a2*p21[1]
local X=(b2-b1)/(a1-a2)
local Y=a1*X+b1
return {X,Y}
end
--some checks
if t.first_angle>=t.last_angle then
local tmp_angle=t.last_angle
t.last_angle=t.first_angle
t.first_angle=tmp_angle
print ("inversed angles")
end
if t.last_angle-t.first_angle>360 and t.first_angle>0 then
t.last_angle=360+t.first_angle
print ("reduce angles")
end
if t.last_angle+t.first_angle>360 and t.first_angle<=0 then
t.last_angle=360+t.first_angle
print ("reduce angles")
end
if t.radius_int<0 then t.radius_int =0 end
if t.radius_int>t.radius_ext then
local tmp_radius=t.radius_ext
t.radius_ext = t.radius_int
t.radius_int = tmp_radius
print ("inversed angles")
end
if t.radius_int==t.radius_ext then
t.radius_int=0
print ("int radius_ext set to 0")
end
--end of checks
cairo_save(cr)
cairo_translate(cr,t.xc,t.yc)
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND)
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND)
local nbArcs=#tableV
local anglefull= (t.last_angle-t.first_angle)*math.pi/180
local fullsize = 0
for i= 1,nbArcs do
fullsize=fullsize+tableV[i][4]
end
local cb,cf,angle=0,0,anglefull/nbArcs
lastAngle=t.first_angle*math.pi/180
lastPt2={nil,nil}
for i =1, nbArcs do
if t.proportional then
angle=tableV[i][4]/fullsize*anglefull
end
--set colours
cb,cf=cb+1,cf+1
if cb>#t.tablebg then cb=1 end
if cf>#t.tablefg then cf=1 end
local str
if tableV[i][2]~="" then
str=string.format('${%s %s}',tableV[i][2],tableV[i][3])
else
str = tableV[i][3]
end
str=conky_parse(str)
local value=tonumber(str)
if value==nil then value=0 end
--draw sectors
draw_sector(t.tablebg,cb,1,lastAngle,angle,t.radius_ext,t.radius_int,t.gradient_effect,t.type_arc,t.inverse_l_arc)
draw_sector(t.tablefg,cf,value/tableV[i][4],lastAngle,angle,t.radius_ext,t.radius_int,t.gradient_effect,t.type_arc,t.inverse_l_arc)
if t.show_text then
--draw text
local txt_l = tableV[i][1]
local txt_opc = round(100*value/tableV[i][4],t.nb_decimals).."%%"
local txt_fpc = round(100*(tableV[i][4]-value/tableV[i][4]),t.nb_decimals).."%%"
local txt_ov,txt_fv,txt_max
if tableV[i][5]==true then
txt_ov = size_to_text(value,t.nb_decimals)
txt_fv = size_to_text(tableV[i][4]-value,t.nb_decimals)
txt_max = size_to_text(tableV[i][4],t.nb_decimals)
else
if tableV[i][5]=="%" then tableV[i][5]="%%" end
txt_ov=string.format("%."..t.nb_decimals.."f ",value)..tableV[i][5]
txt_fv=string.format("%."..t.nb_decimals.."f",tableV[i][4]-value)..tableV[i][5]
txt_max=string.format("%."..t.nb_decimals.."f",tableV[i][4])..tableV[i][5]
end
local txt_pc = string.format("%."..t.nb_decimals.."f",100*tableV[i][4]/fullsize).."%%"
local txt_out = t.txt_format
txt_out = string.gsub(txt_out,"&l",txt_l) --label
txt_out = string.gsub(txt_out,"&o",txt_opc)--occ. %
txt_out = string.gsub(txt_out,"&f",txt_fpc)--free %
txt_out = string.gsub(txt_out,"&v",txt_ov) --occ. value
txt_out = string.gsub(txt_out,"&n",txt_fv) --free value
txt_out = string.gsub(txt_out,"&m",txt_max)--max
txt_out = string.gsub(txt_out,"&p",txt_pc)--percent
local te=cairo_text_extents_t:create()
tolua.takeownership(te)
cairo_set_font_size(cr,t.font_size)
cairo_select_font_face(cr, t.font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_text_extents (cr,txt_out,te)
--draw lines
lastPt2=draw_lines(i,nbArcs,angle,t.tablefg,cf,t.extend_line,t.line_length+t.radius_ext,
te.width + te.x_bearing,t.txt_offset,t.radius_ext,t.line_thickness,t.line_space,t.font_color,t.font_alpha)
local xA=lastPt2[1]
local yA=lastPt2[2]-t.line_thickness-t.txt_offset
if xA>0 then xA = xA-(te.width + te.x_bearing) end
cairo_move_to(cr,xA,yA)
cairo_show_text(cr,txt_out)
end
lastAngle=lastAngle+angle
end
lastAngle = nil
lastPt2 = nil
cairo_restore(cr)
end
--[[END OF PIE CHART WIDGET]]
et pour finir le flag-pie.sh
#!/bin/bash
flag="/tmp/flag-conky-pie"
if [ -f $flag ]; then
rm $flag
else
echo > $flag
fi
CM: Asus Maximus extreme VI/ cpu: intel Core I7-4770 /carte graphique: nvidia rtx3060 oc edition 12gb /os: linux Mint cinnamon
Hors ligne