domingo, 25 de enero de 2015

El código de Conky

El día de hoy fue un día entretenido, por la mañana volví a modificar un poco el código de Conky que programé ayer.

El día de hoy, mi escritorio luce así:


No ha sido un cambio "muy grande", pero al menos ha servido para hacer que ocupe menos espacio en el wallpaper y para hacerlo que muestre unos pocos datos extra. Eso sí, ya no pienso moverle para nada.

Por si están interesados, el código para programar esto en conky es el siguiente:

#Use Background
background yes
# Use Xft?
use_xft yes
xftfont ITC Avant Garde Gothic Pro:bold:size=9
xftalpha 0.9
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)
## no compositor
#own_window_type override
## xcompmgr
#own_window_type override
own_window yes
own_window_transparent no
## cairo-compmgr
own_window_type dock
own_window_argb_visual yes
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager

# Use double buffering (reduces flicker, may not work for everyone)
double_buffer yes

# Minimum size of text area
minimum_size 395 460
maximum_width 410

# Draw shades?
draw_shades no

# Draw outlines?
draw_outline no

# Draw borders around text
draw_borders no

# Draw borders around graphs
draw_graph_borders no

# Stippled borders?
stippled_borders 0

# border margins
border_margin 1

# border width
border_width 0

# Default colors and also border colors
default_color ffffff
default_shade_color 000000
default_outline_color 000000
own_window_colour 000000
#blanco
color1 FFFFFF
#Cian
color2 2EFEF7
#Verde
color3 00FF00
#negro
color4 000000
#naranja
color5 ffff00
#rojo
color6 ff0000
#amarillo
color7 f08500

# 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 965
gap_y 30

# 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 2

# number of net samples to average
# set to 1 to disable averaging
net_avg_samples 2

# short units
short_units yes

# 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

own_window_argb_value 74

lua_load rings-v1.2.1.lua
lua_draw_hook_pre ring_stats

TEXT
#Reloj en minuto
${font ITC Avant Garde Gothic Pro:size=90}${time %I}${color3}${time %M}${color1}
${goto 87}${voffset -80}${font ITC Avant Garde Gothic Pro:bold:size=20} ${time %A}
${goto 106}${voffset 5}${font ITC Avant Garde Gothic Pro:bold:size=25} ${time %b} 
${goto 198}${voffset -40}${color3}${font ITC Avant Garde Gothic Pro:bold:size=35}${time %d}${color1}
${goto 275}${voffset -175}${font ITC Avant Garde Gothic Pro:bold:size=13}Cpu${color5} ${cpu cpu0}%${color1}

${goto 275}${voffset 53}Ram ${color2}$memperc%${color1}${font ITC Avant Garde Gothic Pro:bold:size=14}

${goto 275}${voffset 25}${color1}Wifi ${voffset -5}${font ITC Avant Garde Gothic Pro:bold:size=10}${color3}${upspeed wlan0}${color2}

${goto 295}${voffset -10}${color6}${downspeed wlan0}${color3} 
##Weather

${texeci 1300 curl -s "http://weather.yahooapis.com/forecastrss?w=poner codigo de 6 digitos de tu ciudad aqui, directamente de yahoo weather&u=c" -o ~/.cache/weather.xml}
${voffset -70}${offset 12}${font ITC Avant Garde Gothic Pro:bold:size=20}${execi 1300 grep "yweather:condition" ~/.cache/weather.xml | grep -o "temp=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*"}${font ITC Avant Garde Gothic Pro:bold:size=8}${voffset -16}o${voffset 14}${font}${color1}
${execi 1300 cp -f red/$(grep "yweather:condition" ~/.cache/weather.xml | grep -o "code=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*").png ~/.cache/weather.png}${image ~/.cache/weather.png -p 7,95 -s 80x80}

# Conditions in textual form("partly cloudy" etc.) #
\
${font ITC Avant Garde Gothic Pro:bold:size=15}${offset 57}${voffset -45}${execi 300 grep "yweather:condition" ~/.cache/weather.xml | grep -o "text=\"[^\"]*\"" | grep -o "\"[^\"]*\"" | grep -o "[^\"]*"}${font ITC Avant Garde Gothic Pro:bold:size=12}
     ${offset 01}${voffset 01}

${goto 85}${voffset -97}${font Dark Times:pixelsize=10} 
${color3}${voffset 40}${alignc 65}POWERED BY K${voffset 28}${font ITC Avant Garde Gothic Pro:bold:pixelsize=13}
${goto 19}${color1}Actualizaciones${hr 2}${voffset 4}
${goto 19}${color3}Puedes instalar ${execi 3600 aptitude search "~U" | wc -l} Actualizaciones.
${voffset 4}${goto 19}${color1}Sistema${hr 2}${voffset 4}
${goto 19}${color6}${nodename}
${goto 19}${color6}${pre_exec lsb_release -i -s}
${goto 19}${color6}Versión ${pre_exec lsb_release -r -s} (${pre_exec lsb_release -c -s})
${goto 19}${color6}Kernel ${sysname} ${kernel}
${voffset 4}${goto 19}${color1}Recursos ${hr 2}${voffset 4}
${goto 19}${color5}CPU1 ${cpu cpu1}%${alignc -70}${color5}${cpubar cpu1 10,200}
#${goto 19}${color5}CPU2 ${cpu cpu2}%${alignc -70}${color5}${cpubar cpu2 10,200}
${goto 19}${color5}Ram ${mem}/${memmax}${alignc -70}${color5}${membar 10,200}
${goto 19}${color5}Swap ${swap}/${swapmax}${alignc -70}${color5}${swapbar 10,200}
#${goto 19}${color5}Recibiendo ${downspeedf wlan0} KB/s ${alignc -70}${color5}${downspeedgraph wlan0 10,200}
${goto 19}${color5}Total Recibido${alignc -70}${totaldown wlan0}
#${goto 19}${color5}Enviando   ${upspeedf wlan0} KB/s ${alignr 140}${color5}${upspeedgraph wlan0 10,200}
${goto 19}${color5}Total Envíado${alignc -70}${totalup wlan0}
${voffset 4}${goto 19}${color1}Almacenamiento ${hr 2}${voffset 4}
${goto 19}${color7}Linux ${fs_used /}/${fs_size /}${alignc -70}${color7}${fs_bar 10,200 /}
${goto 19}${color7}Windows ${fs_used /media/K/Windows}/${fs_size /media/K/Windows}${alignc -70}${color7}${fs_bar 10,200 /media/K/Windows}
${goto 19}${color7}Datos ${fs_used /media/K/Data}/${fs_size /media/K/Data}${alignc -70}${color7}${fs_bar 10,200 /media/K/Data}
#${goto 19}${color}sdb1 ${fs_used /media/Downloads}/${fs_size /media/Downloads}${alignc -70}${color CF2765}${fs_bar 10,200 /media/Downloads}
${voffset 4}${goto 19}${color1}Procesos ${hr 2}${voffset 4}
${goto 19}${color2}Aplicación${alignc -70}% Uso CPU
${goto 19}${color5}${top name 1}${alignc -70}${top cpu 1}
${goto 19}${color5}${top name 2}${alignc -70}${top cpu 2}
${goto 19}${color5}${top name 3}${alignc -70}${top cpu 3}
${goto 19}${color5}${top name 4}${alignc -70}${top cpu 4}
${goto 19}${color5}${top name 5}${alignc -70}${top cpu 5}
${goto 19}${color1}${voffset 4}${hr 2}${voffset 4}
${goto 19}${color2}Aplicación${alignc -70}RAM utilizada
${goto 19}${color6}${top_mem name 1}${alignc -70}${top_mem mem_res 1}
${goto 19}${color6}${top_mem name 2}${alignc -70}${top_mem mem_res 2}
${goto 19}${color6}${top_mem name 3}${alignc -70}${top_mem mem_res 3}
${goto 19}${color6}${top_mem name 4}${alignc -70}${top_mem mem_res 4}
${goto 19}${color6}${top_mem name 5}${alignc -70}${top_mem mem_res 5}
${goto 19}${color3}${voffset 4}${hr 2}


Como pueden ver, son bastantes líneas de código...y éste a su vez manda llamar un script en lua para las gráficas de aros:


--[[
This script draws percentage meters as rings. It is fully customisable; all options are described in the script.

IMPORTANT: if you are using the 'cpu' function, it will cause a segmentation fault if it tries to draw a ring straight away. The if statement near the end of the script uses a delay to make sure that this doesn't happen. It calculates the length of the delay by the number of updates since Conky started. Generally, a value of 5s is long enough, so if you update Conky every 1s, use update_num > 5 in that if statement (the default). If you only update Conky every 2s, you should change it to update_num > 3; conversely if you update Conky every 0.5s, you should use update_num > 10. ALSO, if you change your Conky, is it best to use "killall conky; conky" to update it, otherwise the update_num will not be reset and you will get an error.

To call this script in Conky, use the following (assuming that you save this script to ~/scripts/rings.lua):
 lua_load ~/scripts/rings-v1.2.1.lua
 lua_draw_hook_pre ring_stats
]]

settings_table = {
 
 {
        name='cpu',
        arg='cpu0',
        max=100,
        bg_colour=0x0efef0,
        bg_alpha=0.3,
        fg_colour=0xffff00,
        fg_alpha=0.9,
        x=363, y=50,
        radius=30,
        thickness=22,
        start_angle=0,
        end_angle=270
    },
    {
        name='memperc',
        arg='',
        max=100,
        bg_colour=0x0efef0,
        bg_alpha=0.3,
        fg_colour=0x00ffff,
        fg_alpha=0.9,
        x=363, y=140,
        radius=30,
        thickness=22,
        start_angle=0,
        end_angle=270
    },
        {
        name='downspeedf',
        arg='wlan0',
        max=1000,
        bg_colour=0x0efef0,
        bg_alpha=0.3,
        fg_colour=0x00ff00,
        fg_alpha=0.9,
        x=363, y=220,
        radius=26,
        thickness=10,
        start_angle=0,
        end_angle=270
    },
        {
        name='upspeedf',
        arg='wlan0',
        max=100,
        bg_colour=0x0efef0,
        bg_alpha=0.3,
        fg_colour=0xff0000,
        fg_alpha=0.9,
        x=363, y=220,
        radius=14,
        thickness=10,
        start_angle=0,
        end_angle=270
    },
}

require 'cairo'

function rgb_to_r_g_b(colour,alpha)
 return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end

function draw_ring(cr,t,pt)
 local w,h=conky_window.width,conky_window.height
 
 local xc,yc,ring_r,ring_w,sa,ea=pt['x'],pt['y'],pt['radius'],pt['thickness'],pt['start_angle'],pt['end_angle']
 local bgc, bga, fgc, fga=pt['bg_colour'], pt['bg_alpha'], pt['fg_colour'], pt['fg_alpha']

 local angle_0=sa*(2*math.pi/360)-math.pi/2
 local angle_f=ea*(2*math.pi/360)-math.pi/2
 local t_arc=t*(angle_f-angle_0)

 -- Draw background ring

 cairo_arc(cr,xc,yc,ring_r,angle_0,angle_f)
 cairo_set_source_rgba(cr,rgb_to_r_g_b(bgc,bga))
 cairo_set_line_width(cr,ring_w)
 cairo_stroke(cr)
 
 -- Draw indicator ring

 cairo_arc(cr,xc,yc,ring_r,angle_0,angle_0+t_arc)
 cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga))
 cairo_stroke(cr)  
end

function conky_ring_stats()
 local function setup_rings(cr,pt)
  local str=''
  local value=0
  
  str=string.format('${%s %s}',pt['name'],pt['arg'])
  str=conky_parse(str)
  
  value=tonumber(str)
  if value == nil then value = 0 end
  pct=value/pt['max']
  
  draw_ring(cr,pct,pt)
 end

 if conky_window==nil then return end
 local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)
 
 local cr=cairo_create(cs) 
 
 local updates=conky_parse('${updates}')
 update_num=tonumber(updates)
 
 if update_num>5 then
  for i in pairs(settings_table) do
   setup_rings(cr,settings_table[i])
  end
 end
end

Al final, la primera parte del código esta basada en codigo fuente del tema Red Smooth Rings para conky, del cual tomé también los iconos para el clima.

En fin, espero les sea útil. En el primer código, en azul están las partes que hay que modificar, para hacerlas funcionar acorde a sus computadoras. Cualquier duda, ya saben que será resuelta vía comentarios.

Saludos!

No hay comentarios.:

Publicar un comentario