Календарик выводит только день недели, дату и название месяца.
Мной добавлена возможность выводить календарь как на английском так и на русском языках
Скрипт
--[[ SHINY CALENDAR PAGE WIDGET ]]
--[[ v1.0 by londonali1010 (2009) ]]
-- Options (xc, yc, size, bg_colour, fg_colour, alpha)
-- "xc" and "yc" are the x and y coordinates of the centre of the widget, in pixels, relative to the top left of the Conky window.
-- "size" is the width of the widget (which is square).
-- "bg_colour" is the colour, in format 0xRRGGBB, of the widget's background.
-- "fg_colour" is the colour of the widget's text.
-- "alpha" is the opacity (0.0 -> 1.0) of the widget.
require 'cairo'
function calpage(cr, xc, yc, size, font_name, bgc, fgc, alpha, lang)
-- функция перекодировки цвета
local function rgb_to_r_g_b(colour, alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
-- рисуем фон для календаря
local function rrect()
cairo_move_to(cr, x0 + 0.1*size, y0)
cairo_line_to(cr, x0 + 0.9*size, y0)
cairo_curve_to(cr, x0 + size, y0, x0 + size, y0, x0 + size, y0 + 0.1*size)
cairo_line_to(cr, x0 + size, y0 + 0.9*size)
cairo_curve_to(cr, x0 + size, y0 + size, x0 + size, y0 + size, x0 + 0.9*size, y0 + size)
cairo_line_to(cr, x0 + 0.1*size, y0 + size)
cairo_curve_to(cr, x0, y0 + size, x0, y0 + size, x0, y0 + 0.9*size)
cairo_line_to(cr, x0, y0 + 0.1*size)
cairo_curve_to(cr, x0, y0, x0, y0, x0 + 0.1*size, y0)
cairo_close_path(cr)
end
local function background()
local r, g, b, a = rgb_to_r_g_b(bgc, alpha)
rrect()
cairo_set_source_rgba(cr, r, g, b, a)
cairo_fill_preserve(cr)
linpat = cairo_pattern_create_linear(xc, yc, xc, yc + size)
cairo_pattern_add_color_stop_rgba(linpat, 0, 1.0, 1.0, 1.0, 0.2*a)
cairo_pattern_add_color_stop_rgba(linpat, 1, 1.0, 1.0, 1.0, 0)
cairo_set_source(cr, linpat)
cairo_fill_preserve(cr)
cairo_clip(cr)
rrect()
cairo_set_source_rgba(cr, r, g, b, a)
cairo_set_line_width(cr, 0.05*size)
cairo_stroke_preserve(cr)
cairo_new_path(cr)
cairo_arc(cr, xc, yc - size, size, 0, 2*math.pi)
radpat = cairo_pattern_create_radial(xc, yc - size, 0, xc, yc - size, size)
cairo_pattern_add_color_stop_rgba(radpat, 0, 1.0, 1.0, 1.0, a)
cairo_pattern_add_color_stop_rgba(radpat, 1, 1.0, 1.0, 1.0, 0.2*a)
cairo_set_source(cr, radpat)
cairo_fill(cr)
end
-- расчет величины шрифта
local function set_font_sizes()
day_size = 1000.0
date_size = 1000.0
month_size = 1000.0
-- устанавливаем шрифт
local extents = cairo_text_extents_t:create()
cairo_select_font_face(cr, font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_font_size(cr, day_size)
cairo_text_extents(cr, day, extents)
local w = math.abs(extents.width)
local h = math.abs(extents.y_bearing)
local scale_w = 0.8*size / w
local scale_h = 0.1*size / h
local scale
if scale_w < scale_h then scale = scale_w else scale = scale_h end
day_size = scale * day_size
cairo_set_font_size(cr, date_size)
cairo_text_extents(cr, date, extents)
w = math.abs(extents.width)
h = math.abs(extents.y_bearing)
scale_w = 0.6*size / w
scale_h = 0.6*size / h
if scale_w < scale_h then scale = scale_w else scale = scale_h end
date_size = scale * date_size
cairo_set_font_size(cr, month_size)
cairo_text_extents(cr, month, extents)
w = math.abs(extents.width)
h = math.abs(extents.y_bearing)
scale_w = 0.8*size / w
scale_h = 0.1*size / h
if scale_w < scale_h then scale = scale_w else scale = scale_h end
month_size = scale * month_size
return day_size, date_size, month_size
end
-- выводим текст
local function draw_text()
local extents = cairo_text_extents_t:create()
cairo_set_source_rgba(cr, rgb_to_r_g_b(fgc, alpha))
cairo_set_font_size(cr, day_size)
cairo_text_extents(cr, day, extents)
cairo_move_to(cr, x0 + size/2 - extents.x_advance/2, y0 + 0.2*size)
cairo_show_text(cr, day)
cairo_set_font_size(cr, date_size)
cairo_text_extents(cr, date, extents)
cairo_move_to(cr, x0 + size/2 - extents.x_advance/2, y0 + 0.5*size - extents.y_bearing/2)
cairo_show_text(cr, date)
cairo_set_font_size(cr, month_size)
cairo_text_extents(cr, month, extents)
cairo_move_to(cr, x0 + size/2 - extents.x_advance/2, y0 + 0.9*size)
cairo_show_text(cr, month)
end
x0, y0 = xc - size/2, yc - size/2
-- переключения календаря с английского языка на русский
if lang == "ru" then
-- для вывода календаря на русском языке
day = conky_parse("${time %A}")
date = conky_parse ("${time %d}")
month = conky_parse ("${time %B}")
else
-- для вывода календаря на английском языке
day = os.date("%A")
date = os.date("%d")
month = os.date("%B")
end
background()
day_size, date_size, month_size = set_font_sizes()
draw_text(day_size, date_size, month_size)
end
--[[ END SHINY CALENDAR WIDGET ]]
function conky_widgets()
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)
calpage(cr, 150, 150, 100, "Petita Medium", 0x000000, 0xffffff, 1, "ru")
cairo_destroy(cr)
end
Для запуска скрипта необходимо в conkyrc выше слова TEXT добавить следующие строки
lua_load ~/путь_до_скрипта/shiny_calendar.lua
lua_draw_hook_pre conky_widgets
Скрипт можно взять здесь
Мной добавлена возможность выводить календарь как на английском так и на русском языках
Скрипт
--[[ SHINY CALENDAR PAGE WIDGET ]]
--[[ v1.0 by londonali1010 (2009) ]]
-- Options (xc, yc, size, bg_colour, fg_colour, alpha)
-- "xc" and "yc" are the x and y coordinates of the centre of the widget, in pixels, relative to the top left of the Conky window.
-- "size" is the width of the widget (which is square).
-- "bg_colour" is the colour, in format 0xRRGGBB, of the widget's background.
-- "fg_colour" is the colour of the widget's text.
-- "alpha" is the opacity (0.0 -> 1.0) of the widget.
require 'cairo'
function calpage(cr, xc, yc, size, font_name, bgc, fgc, alpha, lang)
-- функция перекодировки цвета
local function rgb_to_r_g_b(colour, alpha)
return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
end
-- рисуем фон для календаря
local function rrect()
cairo_move_to(cr, x0 + 0.1*size, y0)
cairo_line_to(cr, x0 + 0.9*size, y0)
cairo_curve_to(cr, x0 + size, y0, x0 + size, y0, x0 + size, y0 + 0.1*size)
cairo_line_to(cr, x0 + size, y0 + 0.9*size)
cairo_curve_to(cr, x0 + size, y0 + size, x0 + size, y0 + size, x0 + 0.9*size, y0 + size)
cairo_line_to(cr, x0 + 0.1*size, y0 + size)
cairo_curve_to(cr, x0, y0 + size, x0, y0 + size, x0, y0 + 0.9*size)
cairo_line_to(cr, x0, y0 + 0.1*size)
cairo_curve_to(cr, x0, y0, x0, y0, x0 + 0.1*size, y0)
cairo_close_path(cr)
end
local function background()
local r, g, b, a = rgb_to_r_g_b(bgc, alpha)
rrect()
cairo_set_source_rgba(cr, r, g, b, a)
cairo_fill_preserve(cr)
linpat = cairo_pattern_create_linear(xc, yc, xc, yc + size)
cairo_pattern_add_color_stop_rgba(linpat, 0, 1.0, 1.0, 1.0, 0.2*a)
cairo_pattern_add_color_stop_rgba(linpat, 1, 1.0, 1.0, 1.0, 0)
cairo_set_source(cr, linpat)
cairo_fill_preserve(cr)
cairo_clip(cr)
rrect()
cairo_set_source_rgba(cr, r, g, b, a)
cairo_set_line_width(cr, 0.05*size)
cairo_stroke_preserve(cr)
cairo_new_path(cr)
cairo_arc(cr, xc, yc - size, size, 0, 2*math.pi)
radpat = cairo_pattern_create_radial(xc, yc - size, 0, xc, yc - size, size)
cairo_pattern_add_color_stop_rgba(radpat, 0, 1.0, 1.0, 1.0, a)
cairo_pattern_add_color_stop_rgba(radpat, 1, 1.0, 1.0, 1.0, 0.2*a)
cairo_set_source(cr, radpat)
cairo_fill(cr)
end
-- расчет величины шрифта
local function set_font_sizes()
day_size = 1000.0
date_size = 1000.0
month_size = 1000.0
-- устанавливаем шрифт
local extents = cairo_text_extents_t:create()
cairo_select_font_face(cr, font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_font_size(cr, day_size)
cairo_text_extents(cr, day, extents)
local w = math.abs(extents.width)
local h = math.abs(extents.y_bearing)
local scale_w = 0.8*size / w
local scale_h = 0.1*size / h
local scale
if scale_w < scale_h then scale = scale_w else scale = scale_h end
day_size = scale * day_size
cairo_set_font_size(cr, date_size)
cairo_text_extents(cr, date, extents)
w = math.abs(extents.width)
h = math.abs(extents.y_bearing)
scale_w = 0.6*size / w
scale_h = 0.6*size / h
if scale_w < scale_h then scale = scale_w else scale = scale_h end
date_size = scale * date_size
cairo_set_font_size(cr, month_size)
cairo_text_extents(cr, month, extents)
w = math.abs(extents.width)
h = math.abs(extents.y_bearing)
scale_w = 0.8*size / w
scale_h = 0.1*size / h
if scale_w < scale_h then scale = scale_w else scale = scale_h end
month_size = scale * month_size
return day_size, date_size, month_size
end
-- выводим текст
local function draw_text()
local extents = cairo_text_extents_t:create()
cairo_set_source_rgba(cr, rgb_to_r_g_b(fgc, alpha))
cairo_set_font_size(cr, day_size)
cairo_text_extents(cr, day, extents)
cairo_move_to(cr, x0 + size/2 - extents.x_advance/2, y0 + 0.2*size)
cairo_show_text(cr, day)
cairo_set_font_size(cr, date_size)
cairo_text_extents(cr, date, extents)
cairo_move_to(cr, x0 + size/2 - extents.x_advance/2, y0 + 0.5*size - extents.y_bearing/2)
cairo_show_text(cr, date)
cairo_set_font_size(cr, month_size)
cairo_text_extents(cr, month, extents)
cairo_move_to(cr, x0 + size/2 - extents.x_advance/2, y0 + 0.9*size)
cairo_show_text(cr, month)
end
x0, y0 = xc - size/2, yc - size/2
-- переключения календаря с английского языка на русский
if lang == "ru" then
-- для вывода календаря на русском языке
day = conky_parse("${time %A}")
date = conky_parse ("${time %d}")
month = conky_parse ("${time %B}")
else
-- для вывода календаря на английском языке
day = os.date("%A")
date = os.date("%d")
month = os.date("%B")
end
background()
day_size, date_size, month_size = set_font_sizes()
draw_text(day_size, date_size, month_size)
end
--[[ END SHINY CALENDAR WIDGET ]]
function conky_widgets()
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)
calpage(cr, 150, 150, 100, "Petita Medium", 0x000000, 0xffffff, 1, "ru")
cairo_destroy(cr)
end
Для запуска скрипта необходимо в conkyrc выше слова TEXT добавить следующие строки
lua_load ~/путь_до_скрипта/shiny_calendar.lua
lua_draw_hook_pre conky_widgets
Скрипт можно взять здесь
Комментариев нет:
Отправить комментарий