domingo, 17 de junho de 2012

ConkyBr3-Lua Atualização

Saudações!

A versão atualizada do ConkyBr3-Lua já está disponível!


Este modelo é um dos mais populares Conkys que utilizam o BrWeather:


Nome: ConkyBR3-Lua
Características: Baseado no Conky Lua, apenas incluindo a previsão do tempo.

Download:  Conky3-lua.tar.gz

Funciona também no modo Google: Sim

Instalação: Descompacte o arquivo tar.gz, e rode o script de instalação:

$ sh installconky.sh

Este script confere se você possui o BrWeather instalado corretamente. Se tudo estiver OK, ele instala o Conky na pasta /home/seu_usuário/.brweather/conky3.


Arquivo conkyrc:

# ConkyBrWeather
# Criado por LeandroNKZ
# Necessário o uso do BrWeather:
# http://brweatherproject.blogspot.com/
# Instruções e instalação: 
# http://va.mu/V59f

# -- Conky settings -- #
background yes
update_interval 1

cpu_avg_samples 1
net_avg_samples 2

override_utf8_locale yes

double_buffer yes
no_buffers yes

text_buffer_size 2048
imlib_cache_size 0

# -- Window specifications -- #

# -- GNOME -- #
own_window yes
own_window_type override
own_window_transparent yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below

# -- Openbox -- #
#own_window yes
#own_window_transparent yes
#own_window_type desktop


# -- Alignment -- # 

#alignment top_left
alignment top_right
#alignment bottom_left
#alignment bottom_right

border_inner_margin 0
border_outer_margin 0

minimum_size 230 250
maximum_width 300

gap_x 10
gap_y 55

# -- Graphics settings -- #
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders yes

# -- Text settings -- #
use_xft yes
xftfont FreeSans:size=8
xftalpha 0.4
uppercase no

# -- Colors -- #
default_color 8B8B8B
color0 FFFFFF
color1 007C75

# -- Lua Load -- #
lua_load ~/.brweather/conky3/rings.lua
lua_draw_hook_pre clock_rings

TEXT
${voffset 0}${color1}${font FreeSans:size=16}${exec date +%A | sed -r 's/\b[a-z]{3,}/\u&/g'}${font}${voffset -8}${alignr 50}${color0}${font FreeSans:size=38}${time %d}${font}
${color0}${voffset -30}${font FreeSans:size=18}${time %b}${font}${voffset -3} ${font FreeSans:size=20}${time %Y}${font}${color1}${hr}
# lua
${color0}${goto 0}${voffset 204}${cpu cpu0}%
${color1}${goto 0}${font FreeSans:size=8}CPU${font}
${color0}${goto 47}${voffset -30}${memperc}%
${color1}${goto 45}${font FreeSans:size=8}RAM${font}
${color0}${goto 92}${voffset -30}${swapperc}%
${color1}${goto 90}${font FreeSans:size=8}Swap${font}
${color0}${goto 135}${voffset -30}${fs_used_perc /}%
${color1}${goto 135}${font FreeSans:size=8}Disk${font}
${color0}${goto 182}${voffset -30}${downspeed eth0}
${color1}${goto 182}${font FreeSans:size=8}Net${font}
${color0}${goto 182}${upspeed eth0}
#
# Previsão do tempo
# Sua cidade
${voffset 10}${color1}${font FreeSans:size=12}City:${color0}${goto 80}${execi 3600 brweather --option=city}
# Humidade
${voffset 0}${color1}${font FreeSans:size=12}Humidity:${color0}${goto 80}${execi 3600 brweather --option=umid}
# Temperatura atual
${voffset 30}${font FreeSans:size=20}${color0}${goto 120}${execi 3600 brweather --option=TN}C
# Amanhã
${voffset 20}${font FreeSans:size=15}${color1}${goto 10}${execi 3600 brweather --option=Day1}
# Terceiro dia
${voffset -25}${font FreeSans:size=15}${color1}${goto 92}${execi 3600 brweather --option=Day2}
# Quarto dia
${voffset -27}${font FreeSans:size=15}${color1}${goto 172}${execi 3600 brweather --option=Day3}
# Temperatura 2 dia
${voffset 50}${font FreeSans:size=8}${color0}${goto 0}${execi 3600 brweather --option=LT1}C${color1}/${font FreeSans:size=8}${color0}${execi 3600 brweather --option=HT1}C
# Temperatura 3 dia
${voffset -15}${font FreeSans:size=8}${color0}${goto 85}${execi 3600 brweather --option=LT2}C${color1}/${font FreeSans:size=8}${color0}${execi 3600 brweather --option=HT2}C
# Temperatura 4 dia
${voffset -15}${font FreeSans:size=8}${color0}${goto 165}${execi 3600 brweather --option=LT3}C${color1}/${font FreeSans:size=8}${color0}${execi 3600 brweather --option=HT3}C
# Last update
${voffset 0}${goto 15}${font FreeSans:size=8}${alignr}${color1}Last update:${font FreeSans:size=8}${color0}${execi 3600 brweather --option=LU}
# System
${voffset 10}${color1}${font FreeSans:size=8}Uptime: ${color0}${uptime_short}
${color1}${font FreeSans:size=8}${alignr}${nodename}
${color1}${font FreeSans:size=8}${alignr}${pre_exec cat /etc/issue.net}  $machine
${color1}${font FreeSans:size=8}${alignr}Kernel: ${kernel}
# Condições atuais 
#(lembre-se: para adicionar imagens, usa-se o execpi no lugar do execi)
${execpi 3600 brweather --imagem1=CN -p 0,375 -s 70x70}
# Amanhã
${execpi 3600 brweather --imagem1=C1 -p 0,485 -s 60x60}
# Terceiro dia
${execpi 3600 brweather --imagem1=C2 -p 85,485 -s 60x60}
# quarto
${execpi 3600 brweather --imagem1=C3 -p 165,485 -s 60x60}
#
###############################################################
# Logo da sua distribuição.
# Descomente a linha referente à sua distro e deixe as demais comentadadas.
#Debian:
${image ~/.brweather/conky3/imagens/debian-logo.png -p 85,120 -s 60x60}
#Fedora:
#${image ~/.brweather/conky3/imagens/fedora-logo.png -p 85,130 -s 60x30}
# Linux mint-versão 1
#${image ~/.brweather/conky3/imagens/linuxmint1.png -p 85,130 -s 60x30}
# Linux mint versão 2 (a que melhor se encaixa neste conky)
#${image ~/.brweather/conky3/imagens/linuxmint2.png -p 85,120 -s 60x60}
# Lubuntu
#${image ~/.brweather/conky3/imagens/lubuntu-logo.png -p 85,135 -s 55x25}
# Ubuntu
#${image ~/.brweather/conky3/imagens/ubuntu-logo.png -p 85,135 -s 55x25}
# openSUSE
#${image ~/.brweather/conky3/imagens/open-suse-logo.png -p 85,130 -s 60x40}


Script Lua:

--[[
Clock Rings by Linux Mint (2011) reEdited by despot77 E editado novamente por LeandroNKZ.

This script draws percentage meters as rings, and also draws clock hands if you want! It is fully customisable; all options are described in the script. This script is based off a combination of my clock.lua script and my rings.lua 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 on line 145 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/clock_rings.lua
    lua_draw_hook_pre clock_rings
    
Changelog:
+ v1.0 -- Original release (30.09.2009)
   v1.1p -- Jpope edit londonali1010 (05.10.2009)
*v 2011mint -- reEdit despot77 (18.02.2011)
vBrWeather -- modificado por leandroNKZ
]]

settings_table = {
    {
        -- Edit this table to customise your rings.
        -- You can create more rings simply by adding more elements to settings_table.
        -- "name" is the type of stat to display; you can choose from 'cpu', 'memperc', 'fs_used_perc', 'battery_used_perc'.
        name='time',
        -- "arg" is the argument to the stat type, e.g. if in Conky you would write ${cpu cpu0}, 'cpu0' would be the argument. If you would not use an argument in the Conky variable, use ''.
        arg='%I.%M',
        -- "max" is the maximum value of the ring. If the Conky variable outputs a percentage, use 100.
        max=12,
        -- "bg_colour" is the colour of the base ring.
        bg_colour=0xFFFFFF,
        -- "bg_alpha" is the alpha value of the base ring.
        bg_alpha=0.1,
        -- "fg_colour" is the colour of the indicator part of the ring.
        fg_colour=0x0007CAF,
        -- "fg_alpha" is the alpha value of the indicator part of the ring.
        fg_alpha=0.2,
        -- "x" and "y" are the x and y coordinates of the centre of the ring, relative to the top left corner of the Conky window.
        x=115, y=150,
        -- "radius" is the radius of the ring.
        radius=35,
        -- "thickness" is the thickness of the ring, centred around the radius.
        thickness=5,
        -- "start_angle" is the starting angle of the ring, in degrees, clockwise from top. Value can be either positive or negative.
        start_angle=0,
        -- "end_angle" is the ending angle of the ring, in degrees, clockwise from top. Value can be either positive or negative, but must be larger than start_angle.
        end_angle=360
    },
    {
        name='time',
        arg='%M.%S',
        max=60,
        bg_colour=0xffffff,
        bg_alpha=0.1,
        fg_colour=0x007CAF,
        fg_alpha=0.4,
        x=115, y=150,
        radius=45,
        thickness=5,
        start_angle=0,
        end_angle=360
    },
    {
        name='time',
        arg='%S',
        max=60,
        bg_colour=0xffffff,
        bg_alpha=0.1,
        fg_colour=0x007CAF,
        fg_alpha=0.6,
        x=115, y=150,
        radius=55,
        thickness=5,
        start_angle=0,
        end_angle=360
    },
    {
        name='time',
        arg='%m',
        max=12,
        bg_colour=0xffffff,
        bg_alpha=0.1,
        fg_colour=0x007CAF,
        fg_alpha=0.8,
        x=115, y=150,
        radius=65,
        thickness=5,
        start_angle=180,
        end_angle=360
    },
    {
        name='time',
        arg='%d',
        max=31,
        bg_colour=0xffffff,
        bg_alpha=0.1,
        fg_colour=0x007CAF,
        fg_alpha=1,
        x=115, y=150,
        radius=75,
        thickness=5,
        start_angle=0,
        end_angle=180
    },
    {
        name='cpu',
        arg='cpu0',
        max=100,
        bg_colour=0xffffff,
        bg_alpha=0.2,
        fg_colour=0x007CAF,
        fg_alpha=0.8,
        x=25, y=275,
        radius=20,
        thickness=5,
        start_angle=-90,
        end_angle=180
    },
    {
        name='memperc',
        arg='',
        max=100,
        bg_colour=0xffffff,
        bg_alpha=0.2,
        fg_colour=0x007CAF,
        fg_alpha=0.8,
        x=70, y=275,
        radius=20,
        thickness=5,
        start_angle=-90,
        end_angle=180
    },
    {
        name='swapperc',
        arg='',
        max=100,
        bg_colour=0xffffff,
        bg_alpha=0.2,
        fg_colour=0x007CAF,
        fg_alpha=0.8,
        x=115, y=275,
        radius=20,
        thickness=5,
        start_angle=-90,
        end_angle=180
    },
    {
        name='fs_used_perc',
        arg='/',
        max=100,
        bg_colour=0xffffff,
        bg_alpha=0.2,
        fg_colour=0x007CAF,
        fg_alpha=0.8,
        x=160, y=275,
        radius=20,
        thickness=5,
        start_angle=-90,
        end_angle=180
    },
        {
        name='downspeedf',
        arg='eth0',
        max=100,
        bg_colour=0xffffff,
        bg_alpha=0.2,
        fg_colour=0x007CAF,
        fg_alpha=0.8,
        x=205, y=275,
        radius=20,
        thickness=4,
        start_angle=-90,
        end_angle=180
    },
        {
        name='upspeedf',
        arg='eth0',
        max=100,
        bg_colour=0xffffff,
        bg_alpha=0.2,
        fg_colour=0x007CAF,
        fg_alpha=0.8,
        x=205, y=275,
        radius=15,
        thickness=4,
        start_angle=-90,
        end_angle=180
    },
}

-- Use these settings to define the origin and extent of your clock.

clock_r=65

-- "clock_x" and "clock_y" are the coordinates of the centre of the clock, in pixels, from the top left of the Conky window.

clock_x=115
clock_y=150

show_seconds=true

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 draw_clock_hands(cr,xc,yc)
    local secs,mins,hours,secs_arc,mins_arc,hours_arc
    local xh,yh,xm,ym,xs,ys
    
    secs=os.date("%S")    
    mins=os.date("%M")
    hours=os.date("%I")
        
    secs_arc=(2*math.pi/60)*secs
    mins_arc=(2*math.pi/60)*mins+secs_arc/60
    hours_arc=(2*math.pi/12)*hours+mins_arc/12
        
    -- Draw hour hand
    
    xh=xc+0.7*clock_r*math.sin(hours_arc)
    yh=yc-0.7*clock_r*math.cos(hours_arc)
    cairo_move_to(cr,xc,yc)
    cairo_line_to(cr,xh,yh)
    
    cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
    cairo_set_line_width(cr,5)
    cairo_set_source_rgba(cr,1.0,1.0,1.0,1.0)
    cairo_stroke(cr)
    
    -- Draw minute hand
    
    xm=xc+clock_r*math.sin(mins_arc)
    ym=yc-clock_r*math.cos(mins_arc)
    cairo_move_to(cr,xc,yc)
    cairo_line_to(cr,xm,ym)
    
    cairo_set_line_width(cr,3)
    cairo_stroke(cr)
    
    -- Draw seconds hand
    
    if show_seconds then
        xs=xc+clock_r*math.sin(secs_arc)
        ys=yc-clock_r*math.cos(secs_arc)
        cairo_move_to(cr,xc,yc)
        cairo_line_to(cr,xs,ys)
    
        cairo_set_line_width(cr,1)
        cairo_stroke(cr)
    end
end

function conky_clock_rings()
    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)
        pct=value/pt['max']
        
        draw_ring(cr,pct,pt)
    end
    
    -- Check that Conky has been running for at least 5s

    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
    
    draw_clock_hands(cr,clock_x,clock_y)
end

Até a próxima!

6 comentários:

  1. Olá, Leandro!
    Parabéns pela iniciativa! Achei o máximo o seu projeto!
    Gostaria de te dar uma sugestão:
    Não seria possível usar as próprias imagens do INPE como padrão de um conky? Pergunto isso porque a previsão aqui era de "pancadas de chuva" e a imagem no site do INPE era um sol entre nuvens chuvosas. Mas no conky estava aparecendo a maior chuva.
    Entrei nos arquivos de configuração do conky (mesmo sem entender nada direito) e vi que a cada categoria do INPE ("cl", "n", "np", etc) você atribuía uma imagem. Mas há muito mais categorias ou imagens no INPE do que as que estão na pasta "imagens 1" por exemplo.
    Se para cada categoria do INPE tivesse uma imagem correspondente na pasta de imagens, não precisaria "juntar previsões parecidas" para aparecerem sob a mesma imagem.
    Ah, outro exemplo: nublado para o INPE é céu com muitas nuvens com poucas aberturas de sol. E encoberto é céu sem abertura de sol. As imagens estão aparecendo ao contrário. :)
    Cara, isso são só sugestões... fiquei fã do teu trabalho, por isso que resolvi escrever tudo isso aqui! :)
    Abraços!
    Daniel

    ResponderExcluir
  2. Opa, valeu Daniel. :)

    Quanto às imagens, é uma história que começou lá na versão beta 3.
    Esta versão foi a primeira a contar com estas imagens. E, ainda utilizava o Climatempo para prover as condições atuais.

    Porém, diferente do INPE, o Climatempo (pelo menos na época, antes da reformulação), contava com apenas 18 variações de ícones para as previsões (9 para dia e 9 para noite). Desse modo, surgiram os problemas:

    - Poucas variações de ícones para a previsão atual e para o modo Google;
    - Como os temas de ícones não são idênticos, um tema pode ter muito menos variações de ícones do que outro (ex.: compare os temas 1 e 2).

    O que fiz foi "nivelar" os ícones para que possam ter um certo "padrão".
    Mas, esqueci de atualizá-los agora, uma vez que não o BrWeather não usa mais o Climatempo. hehe.

    Vou atualizar os ícones, acrescentando mais opções. No entanto, elas podem mudar dependendo das opções do tema utilizado. Vou acrescentar os ícones do INPE e corrigir a opção "nublado", também.

    Mas isso ficará para a próxima versão. Estou testando algumas modificações nos scripts, para que ele execute mais rápido (a versão atual está muuuuito lenta).

    Abraço e obrigado!

    ResponderExcluir
    Respostas
    1. Valeu, Leandro! Então vou ficar antenado aqui no teu blog esperando as próximas versões! ;)
      Novamente, parabéns aí!
      Abraços,
      Daniel

      Excluir
    2. Estou implementando novidades na instalação, além da já citada melhora na performance. Se nenhum problema ocorrer com esta versão atual, o que pode adiantar o lançamento, a próxima versão será lançada mais ou menos em novembro, quando o BrWeather completará 1 ano.

      Abraço e obrigado.

      Excluir
  3. Olá Leandro, primeiramente parabéns pelo excelente projeto. Até eu que sou leigo no linux consegui colocar pra rodar sem problemas. Só passei pra agradecer o empenho de deixar o projeto tão intuitivo e gigante. Sei que não é fácil manter tantas atualizações e novidades. Aproveitando a oportunidade, gostaria de informar que o link do download do conky lua está quebrado, e que o site http://www.cptec.inpe.br/ passará a ser este: https://www2.cptec.inpe.br/. Se possível, atualiza pra gente como ficará os novos códigos. Abraço.

    ResponderExcluir
    Respostas
    1. Olá!
      Obrigado pelo apoio.
      Infelizmente, este projeto se encontra descontinuado. Não consegui mais ter tempo livre para mantê-lo atualizado. =/
      Quanto ao link de download do Conky Lua, você pode acessar também aqui: https://sourceforge.net/projects/conkywfc/files/Conkys/

      Um abraço.

      Excluir