Code: Select all
--[[
2023 Bleys
]]
require 'cairo'
require "imlib2"
home_path = os.getenv ('HOME')
function rgb_to_rgba(color,alpha)
if color == nil then color=0xFF0000 end
if alpha == nil then alpha=1 end
return ((color / 0x10000) % 0x100) / 255., ((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end
function write_text(cr, x, y, text, f)
--write_text(cr, x, y, text, {})
--font attributes (Schriftattribute zuweisen oder default Werte annehmen)
local font=f.font or "Neon 80s"
local size=f.size or 12
local align=f.align or 'l'
local bold=f.bold or false
local ital=f.italic or false
local color=f.color or "0xffffff"
local slant=CAIRO_FONT_SLANT_NORMAL
if ital then slant=CAIRO_FONT_SLANT_ITALIC end
local weight=CAIRO_FONT_WEIGHT_NORMAL
if bold then weight=CAIRO_FONT_WEIGHT_BOLD end
--Text Size (Textgröße für die Plazierung bestimmen.)
local x_a=0
local y_a=0
local te = cairo_text_extents_t:create()
tolua.takeownership(te)
cairo_select_font_face (cr, font, slant, weight)
cairo_set_font_size (cr, size)
cairo_text_extents (cr, text, te)
--Text Position
if align=='c' then
x_a = -(te.width/2+te.x_bearing)
y_a = -(te.height/2+te.y_bearing)
end
if align=='r' then
x_a = -(te.width+te.x_bearing)
end
--Schadow 1 Pixel (Schatten für den Text um 1 Pixel versetzt)
cairo_set_source_rgba(cr, rgb_to_rgba(0x000000,1))
cairo_move_to (cr, x+1+x_a, y+1+y_a)
cairo_show_text (cr, text)
cairo_stroke(cr)
-- Now Text on Top (nun den Text oben drauf)
cairo_set_source_rgba(cr, rgb_to_rgba(color,1))
cairo_move_to (cr, x+x_a, y+y_a)
cairo_show_text (cr, text)
cairo_stroke(cr)
end
function mysplit (inputstr, sep)
if sep == nil then
sep = ","
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
function fDrawImage(cr,path,xx,yy,ww,hh,arc)
cairo_save (cr)
local img = cairo_image_surface_create_from_png(path)
local w_img, h_img = cairo_image_surface_get_width(img), cairo_image_surface_get_height(img)
cairo_translate (cr, xx, yy)
if arc then
cairo_rotate (cr, arc)
end
cairo_scale (cr, ww/w_img, hh/h_img)
cairo_set_source_surface (cr, img, -w_img/2, -h_img/2)
cairo_paint (cr)
cairo_surface_destroy (img)
collectgarbage ()
cairo_restore (cr)
end
function conky_main()
if conky_window==nil then return end
local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)
local cr=cairo_create(cs)
local updates=conky_parse('${updates}')
update_num=tonumber(updates)
if update_num>4 then
wetter = mysplit (conky_parse('${execi 60 sh '..home_path..'/.conky/wetter.sh}')) --1-text, 2-temperatur, 3-wind, 4-humidity,5-icon, 6-sunrise, 7-sunset,8-updated,9-air pressure,10-gust,11-deg
-- Wetter (Weather)
if wetter[1]~=nil then
write_text(cr, 20,20,wetter[1], {align="l", size=14, bold=true, color="0xff0000"})
write_text(cr, 20,70,"Humidity: ", {align="l", size=12, color="0xff0000"})
write_text(cr, 120,70,wetter[4].."%", {align="r", size=12, color="0xffffff"})
write_text(cr, 20,86,"Air pressure: ", {align="l", size=12, color="0xff0000", font="Neon 80s"})
write_text(cr, 100,86,wetter[9].." hPa", {size=12, color="0xffffff"})
write_text(cr, 20,102,"Wind Spd: ",{align="l", size=12, color="0xff0000", font="Neon 80s"})
write_text(cr, 100,102, " (Gusts: ",{size=12, color="0xff0000", font="Neon 80s"})
write_text(cr, 82,102,wetter[3],{align="l", font="Neon 80s", size=12, color="0xffffff"})
write_text(cr, 144,102,wetter[10],{align="l", font="Neon 80s", size=12, color="0xffffff"})
write_text(cr, 172,102, ")", {align="l", size=12, color="0xff0000", font="Neon 80s"})
write_text(cr, 178,102,"mph", {align="l", size=12, color="0xffffff", font="Neon 80s"})
write_text(cr, 20,50,wetter[2].."°F", {font="Neon 80s", bold=false, size=20, align="l", color="0xffffff"})
write_text(cr, 20,50,wetter[2].."°F", {font="Neon 80s", bold=false, size=20, align="l", color="0xffffff"})
write_text(cr, 326,146,"updated: ", {font="Neon 80s", size=10, color = "0xff0000", align="r"})
write_text(cr, 368,146,wetter[8], {font="Neon 80s", bold=false, size=10, align="r"})
write_text(cr, 20,136,"Sunrise:", {align="l", font="Neon 80s", size=12, color="0xff0000"})
write_text(cr, 20,152,"Sunset:", {align="l", font="Neon 80s", size=12, color="0xff0000"})
write_text(cr, 64,136,wetter[6], {font="Neon 80s", size=12})
write_text(cr, 64,152,wetter[7], {font="Neon 80s", size=12})
write_text(cr, 20,120, "Wind Dir:", {font="Neon 80s", size=12, color="0xff0000"})
write_text(cr, 82,120,wetter[10].."°",{align="l", font="Neon 80s", size=12, color="0xffffff"})
-- {exec echo $(awk 'BEGIN{dir[1]="N";dir[2]="NE";dir[3]="E";dir[4]="SE";dir[5]="S";dir[6]="SW";dir[7]="W";dir[8]="NW";for(i in dir) if(i*45-45<$wetter[10] && $wetter[10]<=i*45) print dir[i]}')} > /home/logansfury/.conky/Bleys\ Weather/direction}
fDrawImage(cr,home_path..'/.conky/wettericons/'..wetter[5]..'.png',312,40,116,80) -- Adapt path to your own paths
end
end
cairo_surface_destroy(cs)
cairo_destroy(cr)
end[/code}
[/quote]