Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[TEXT WIDGET v1.. by Wlourf 25/06/2010
- This widget can drawn texts set in the "text_settings" table with some parameters
- http://u-scripts.blogspot.com/2010/06/text-widget.html
- The parameters (all optionals) are :
- text - text to display, default = "Conky is good for you"
- use conky_parse to display conky value ie text=conly_parse("${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
- Needs conky 1.8.0
- To call this script in the conkyrc, in before-TEXT section:
- lua_load /path/to/the/lua/script/text.lua
- lua_draw_hook_pre draw_text
- 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"
- ]]
- require 'cairo'
- function conky_draw_text()
- --DEBUT DES PARAMETRES
- --couleurs utilisées plusieurs fois placées dans des variables
- local col0,col1,col2=0x00ffff,0x00ff00,0x0000ff -- 0xFFFFCC,0xCCFF99,0x99FF00
- local colbg=0xffff00--99CCFF
- text_settings={
- {
- text="О СИСТЕМЕ...",
- font_name="Ubuntu",
- font_size=16,
- bold=true,
- h_align="l",
- x=0,
- y=20,
- colour={{0,0xc62222,1}},
- },
- {
- text=conky_parse("$sysname $kernel"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=20,
- y=40,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("$nodename / $user_names"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=20,
- y=60,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("В работе: $uptime"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=20,
- y=80,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text="ЧАСОВЫЕ ПОЯСА",
- font_name="Ubuntu",
- font_size=16,
- bold=true,
- h_align="l",
- x=200,
- y=20,
- colour={{0,0xc62222,1}},
- },
- {
- text="UTC",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=220,
- y=40,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${tztime UTC %l:%M:%S %P, %d.%m.%y}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=450,
- y=40,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text="Киев",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=220,
- y=60,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${tztime Europe/Kiev %l:%M:%S %P, %d.%m.%y}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=450,
- y=60,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text="Минск",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=220,
- y=80,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${tztime Europe/Minsk %l:%M:%S %P, %d.%m.%y}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=450,
- y=80,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text="Москва",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=220,
- y=100,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${tztime Europe/Moscow %l:%M:%S %P, %d.%m.%y}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=450,
- y=100,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text="Баку",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=220,
- y=120,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${tztime Asia/Baku %l:%M:%S %P, %d.%m.%y}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=450,
- y=120,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text="ЗАГРУЗКА СИСТЕМЫ",
- font_name="Ubuntu",
- font_size=16,
- bold=true,
- h_align="l",
- x=0,
- y=160,
- colour={{0,0xc62222,1}},
- },
- {
- text="Процессор",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=10,
- y=180,
- colour={{0,0x0ca425,1}},
- },
- {
- text="Память",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=300,
- y=180,
- colour={{0,0x0ca425,1}},
- },
- {
- text="ПОТРЕБЛЕНИЕ РЕСУРСОВ",
- font_name="Ubuntu",
- font_size=16,
- bold=true,
- h_align="l",
- x=0,
- y=280,
- colour={{0,0xc62222,1}},
- },
- {
- text="Процессор",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=10,
- y=300,
- colour={{0,0x0ca425,1}},
- },
- {
- text="Память",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=235,
- y=300,
- colour={{0,0x0ca425,1}},
- },
- {
- text=conky_parse("${top name 1}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=20,
- y=320,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${top cpu 1}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=210,
- y=320,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${top name 2}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=20,
- y=340,
- colour={{0,0xcccccc,1}},
- },
- {
- text=conky_parse("${top cpu 2}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=210,
- y=340,
- colour={{0,0xcccccc,1}},
- },
- {
- text=conky_parse("${top name 3}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=20,
- y=360,
- colour={{0,0xa8a8a8,1}},
- },
- {
- text=conky_parse("${top cpu 3}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=210,
- y=360,
- colour={{0,0xa8a8a8,1}},
- },
- {
- text=conky_parse("${top name 4}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=20,
- y=380,
- colour={{0,0x999999,1}},
- },
- {
- text=conky_parse("${top cpu 4}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=210,
- y=380,
- colour={{0,0x999999,1}},
- },
- {
- text=conky_parse("${top name 5}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=20,
- y=400,
- colour={{0,0x999999,1}},
- },
- {
- text=conky_parse("${top cpu 5}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=210,
- y=400,
- colour={{0,0x999999,1}},
- },
- {
- text=conky_parse("${top_mem name 1}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=245,
- y=320,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${top_mem mem 1}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=445,
- y=320,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${top_mem name 2}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=245,
- y=340,
- colour={{0,0xcccccc,1}},
- },
- {
- text=conky_parse("${top_mem mem 2}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=445,
- y=340,
- colour={{0,0xcccccc,1}},
- },
- {
- text=conky_parse("${top_mem name 3}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=245,
- y=360,
- colour={{0,0xa8a8a8,1}},
- },
- {
- text=conky_parse("${top_mem mem 3}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=445,
- y=360,
- colour={{0,0xa8a8a8,1}},
- },
- {
- text=conky_parse("${top_mem name 4}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=245,
- y=380,
- colour={{0,0x999999,1}},
- },
- {
- text=conky_parse("${top_mem mem 4}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=445,
- y=380,
- colour={{0,0x999999,1}},
- },
- {
- text=conky_parse("${top_mem name 5}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=245,
- y=400,
- colour={{0,0x999999,1}},
- },
- {
- text=conky_parse("${top_mem mem 5}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=445,
- y=400,
- colour={{0,0x999999,1}},
- },
- {
- text="ИСПОЛЬЗОВАНИЕ СЕТИ",
- font_name="Ubuntu",
- font_size=16,
- bold=true,
- h_align="l",
- x=0,
- y=420,
- colour={{0,0xc62222,1}},
- },
- {
- text="Eth0",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=10,
- y=440,
- colour={{0,0x0ca425,1}},
- },
- {
- text=conky_parse("Приём: ${downspeed eth0}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=20,
- y=460,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("Всего принято: ${totaldown}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=450,
- y=460,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("Передача: ${upspeed eth0}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=20,
- y=480,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("Всего передано: ${totalup}"),
- font_name="Ubuntu",
- font_size=14,
- h_align="r",
- x=450,
- y=480,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text="ИСПОЛЬЗОВАНИЕ ДИСКОВ",
- font_name="Ubuntu",
- font_size=16,
- bold=true,
- h_align="l",
- x=0,
- y=500,
- colour={{0,0xc62222,1}},
- },
- {
- text="/",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=75,
- y=520,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text="/home",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=225,
- y=520,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text="userdata",
- font_name="Ubuntu",
- font_size=14,
- h_align="l",
- x=375,
- y=520,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${fs_used_perc /}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="c",
- x=40,
- y=548,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${fs_used_perc /home}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="c",
- x=190,
- y=548,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("${fs_used_perc /mnt/userdata}%"),
- font_name="Ubuntu",
- font_size=14,
- h_align="c",
- x=340,
- y=548,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("Всего: ${fs_size /}"),
- font_name="Ubuntu",
- font_size=12,
- h_align="l",
- x=60,
- y=560,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("Занято: ${fs_used /}"),
- font_name="Ubuntu",
- font_size=12,
- h_align="l",
- x=60,
- y=575,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("Всего: ${fs_size /home}"),
- font_name="Ubuntu",
- font_size=12,
- h_align="l",
- x=210,
- y=560,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("Занято: ${fs_used /home}"),
- font_name="Ubuntu",
- font_size=12,
- h_align="l",
- x=210,
- y=575,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("Всего: ${fs_size /mnt/userdata}"),
- font_name="Ubuntu",
- font_size=12,
- h_align="l",
- x=360,
- y=560,
- colour={{0,0xf0f0f0,1}},
- },
- {
- text=conky_parse("Занято: ${fs_used /mnt/userdata}"),
- font_name="Ubuntu",
- font_size=12,
- h_align="l",
- x=360,
- y=575,
- colour={{0,0xf0f0f0,1}},
- },
- }
- --------------FIN DES PARAMETERES----------------
- 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)
- end
- cairo_surface_destroy(cs)
- end
- function rgb_to_r_g_b2(tcolour)
- colour,alpha=tcolour[2],tcolour[3]
- return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
- end
- function display_text(t)
- local function set_pattern()
- --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)
- 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.rotx==nil then t.rotx=0 end
- if t.roty==nil then t.roty=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()
- rotx,roty=t.rotx/t.font_size,t.roty/t.font_size
- cairo_matrix_init (matrix0, 1,roty,rotx,1,0,0)
- cairo_transform(cr,matrix0)
- cairo_set_font_size(cr,t.font_size)
- te=cairo_text_extents_t:create()
- cairo_text_extents (cr,t.text,te)
- set_pattern()
- mx,my=0,0
- if t.h_align=="c" then
- mx=-te.width/2
- 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()
- 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=cairo_text_extents_t:create()
- cairo_text_extents (cr,t.text,te)
- cairo_transform(cr,matrix1)
- set_pattern()
- 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)
- cairo_set_line_width(cr,0)
- 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)
- 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
- 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 vorientation=="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
Advertisement
Add Comment
Please, Sign In to add comment