SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-01-17 17:59:29

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

HOW TO : using lua scripts in conky

lua_load
lua_draw_hook

Last edited by mrpeachy (2012-11-06 21:19:56)

Offline

Be excellent to each other!

#2 2012-01-17 18:25:52

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: HOW TO : using lua scripts in conky

that is very peachy Mr Peachy! great how-to which will doubtlessly be useful to many a Conky-warrior.

Offline

#3 2012-01-17 18:26:23

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

text="hello world"
print (text) --> hello world (in terminal)

Last edited by mrpeachy (2012-11-09 05:58:35)

Offline

#4 2012-01-17 20:10:20

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

thanks rhowaldt, hopefully someone will find it useful!

and if im being too simplistic or not explaining things as full enough to make sense let me know!

Last edited by mrpeachy (2012-01-17 20:31:04)

Offline

#5 2012-01-17 22:52:03

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

cairo_set_line_width (cr,1)

Last edited by mrpeachy (2012-01-18 02:41:22)

Offline

#6 2012-01-17 23:48:43

VastOne
#! Ranger
From: V-Ger
Registered: 2011-04-26
Posts: 10,165
Website

Re: HOW TO : using lua scripts in conky

I solemnly swear to read all of this and absorb it.... My first new years resolution!

Nice work mrpeachy!

Offline

#7 2012-01-18 00:40:19

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

Offline

#8 2012-01-18 00:54:56

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,727

Re: HOW TO : using lua scripts in conky

Printed this 6 page monster out!!

Offline

#9 2012-01-18 00:57:41

VastOne
#! Ranger
From: V-Ger
Registered: 2011-04-26
Posts: 10,165
Website

Re: HOW TO : using lua scripts in conky

@ Mr P - I believe Sector11 took sole responsibility and ownership of pushing you down this highway!

Offline

#10 2012-01-18 01:23:11

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

cairo_rectangle (cr, x, y, width, height)

Last edited by mrpeachy (2012-01-18 20:25:41)

Offline

#11 2012-01-18 05:30:43

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: HOW TO : using lua scripts in conky

Wow - I feel such an idiot reading this. Guess I might never be a "real" programmer, but now subscribed, and will get down and try and make something one of these days...

Meanwhile, thank you very much for making it possible!

Offline

#12 2012-01-18 14:52:40

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

Offline

#13 2012-01-18 15:27:09

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: HOW TO : using lua scripts in conky

where's part 5? tongue

Offline

#14 2012-01-18 21:06:52

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

--SETTINGS FOR CPU INDICATOR BAR
bar_bottom_left_x= 50
bar_bottom_left_y= 200
bar_width= 30
bar_height= 100
--set bar background colors, 1,0,0,1 = fully opaque red
bar_bg_red=1
bar_bg_green=0
bar_bg_blue=0
bar_bg_alpha=1
--set indicator colors, 1,1,1,1 = fully opaque white
bar_in_red=1
bar_in_green=1
bar_in_blue=1
bar_in_alpha=1

Last edited by mrpeachy (2012-01-19 01:04:11)

Offline

#15 2012-01-18 21:43:42

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: HOW TO : using lua scripts in conky

Offline

#16 2012-01-18 23:02:07

zuperkoleoptera
Member
Registered: 2012-01-11
Posts: 30

Re: HOW TO : using lua scripts in conky

Well I ve tried to implement the v9000 but with no luck, maybe not enough persistence....
I think after this series of howto I need to get back to the v9000 script and make it work!!!

Thank you for your work....


If you break it, you get to keep all pieces.

Offline

#17 2012-01-19 00:59:37

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

Last edited by mrpeachy (2012-01-19 01:00:55)

Offline

#18 2012-01-19 02:54:51

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

--SETTINGS FOR CPU INDICATOR BAR
bar_bottom_left_x= 750
bar_bottom_left_y= 200
bar_width= 30
bar_height= 100
bar_value=tonumber(conky_parse("${cpu}"))
bar_max_value=100
--set bar background colors, 1,0,0,1 = fully opaque red
bar_bg_red=1
bar_bg_green=0
bar_bg_blue=0
bar_bg_alpha=1
--set indicator colors, 1,1,1,1 = fully opaque white
bar_in_red=1
bar_in_green=1
bar_in_blue=1
bar_in_alpha=1
--END OF SETTINGS

--DRAW BAR INDICATOR
--draw background
cairo_set_source_rgba (cr,bar_bg_red,bar_bg_green,bar_bg_blue,bar_bg_alpha)
cairo_rectangle (cr,bar_bottom_left_x,bar_bottom_left_y,bar_width,-bar_height)
cairo_fill (cr)
--draw indicator
cairo_set_source_rgba (cr,bar_in_red,bar_in_green,bar_in_blue,bar_in_alpha)--set indicator color
scale=bar_height/bar_max_value
indicator_height=scale*bar_value
cairo_rectangle (cr,bar_bottom_left_x,bar_bottom_left_y,bar_width,-indicator_height)
cairo_fill (cr)

Last edited by mrpeachy (2012-01-19 03:07:43)

Offline

#19 2012-01-19 11:19:03

rhowaldt
#!*$%:)
Registered: 2011-03-09
Posts: 4,396

Re: HOW TO : using lua scripts in conky

i wanted to say 'where is part 7?', but i am sure you're going to make that as well, and i am in awe with the amount of info you have here. awesomeness!

Offline

#20 2012-01-19 20:17:27

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: HOW TO : using lua scripts in conky

if updates>5 then
--##############################
print ("hello world")
--##############################
end-- if updates>5

Last edited by Sector11 (2012-01-19 20:18:31)

Offline

#21 2012-01-19 20:38:44

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

actually ive been meaning to write a short bit about spaces and such...
lua seems to be pretty forgiving in terms of allowing spaces and tabs

for example

value=16
print (value) -->16
value = 16--with spaces
print (value) -->16
value    =    16--tabbed
print (value) -->16
    value    =                     16--any kind of spacing you want
print (value) -->16

this also applies to things like the rectangle command

cairo_rectangle (cr,50,50,60,40)
cairo_rectangle (cr, 50 ,50 ,60 ,40 )
    cairo_rectangle     (cr,     50 ,    50 ,60         ,40 )

all give you the same rectangle

my preference is to keep everything tight together

so to answer you comment question specifically, you can have any amount of spaces before the -- without a problem

ill update part 1 with a section about spacing

Last edited by mrpeachy (2012-01-19 20:41:14)

Offline

#22 2012-01-19 23:56:40

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

--set alarm value, this is the value at which bar color will change
alarm_value=80
--set alarm bar color, 1,0,0,1 = red fully opaque
ar,ag,ab,aa=1,0,0,1

Last edited by mrpeachy (2012-01-20 00:10:45)

Offline

#23 2012-01-20 22:05:54

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

--[[this lua script draws vertical bar indicators]]

require 'cairo'

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)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if updates>5 then
--#########################################################################################################
--SETTINGS FOR INDICATOR BAR
bar_bottom_left_x= 100
bar_bottom_left_y= 100
bar_width= 30
bar_height= 100
bar_value=tonumber(conky_parse("${cpu}"))
bar_max_value=100
--set bar background colors, 0.5,0.5,0.5,1 = fully opaque grey
bar_bg_red=0.5
bar_bg_green=0.5
bar_bg_blue=0.5
bar_bg_alpha=1
--bar border settings
bar_border=1 --set 1 for border or 0 for no border
--set border color rgba
border_red=0
border_green=1
border_blue=1
border_alpha=1
--set border thickness
border_width=10
--color change
--set value for first color change, low cpu usage to mid cpu usage
mid_value=50
--set "low" cpu usage color and alpha, ie bar color below 50% - 0,1,0,1=fully opaque green
lr,lg,lb,la=0,1,0,1
--set "mid" cpu usage color, between 50 and 79 - 1,1,0,1=fully opaque yellow
mr,mg,mb,ma=1,1,0,1
--set alarm value, this is the value at which bar color will change
alarm_value=80
--set alarm bar color, 1,0,0,1 = red fully opaque
ar,ag,ab,aa=1,0,0,1
--end of settings
--draw bar
--draw background
cairo_set_source_rgba (cr,bar_bg_red,bar_bg_green,bar_bg_blue,bar_bg_alpha)
cairo_rectangle (cr,bar_bottom_left_x,bar_bottom_left_y,bar_width,-bar_height)
cairo_fill (cr)
--draw indicator
if bar_value>=alarm_value then --ie if value is greater or equal to 50
cairo_set_source_rgba (cr,ar,ag,ab,aa)--yellow
elseif bar_value>=mid_value then --ie if bar_value is greater or equal to 80
cairo_set_source_rgba (cr,mr,mg,mb,ma)--red
else
cairo_set_source_rgba (cr,lr,lg,lb,la)--green
end
scale=bar_height/bar_max_value
indicator_height=scale*bar_value
cairo_rectangle (cr,bar_bottom_left_x,bar_bottom_left_y,bar_width,-indicator_height)
cairo_fill (cr)
--draw border
cairo_set_source_rgba (cr,border_red,border_green,border_blue,border_alpha)
cairo_set_line_width (cr,border_width)
border_bottom_left_x=bar_bottom_left_x-(border_width/2)
border_bottom_left_y=bar_bottom_left_y+(border_width/2)
brec_width=bar_width+border_width
brec_height=bar_height+border_width--remember that we need to make this value negative at some point because we are drawing up
cairo_rectangle (cr,border_bottom_left_x,border_bottom_left_y,brec_width,-brec_height)
cairo_stroke (cr)
--#########################################################################################################
end-- if updates>5
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end-- end main function

Last edited by mrpeachy (2012-01-21 17:11:59)

Offline

#24 2012-01-21 18:19:38

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

indicator_bar(100,100,30,100,tonumber(conky_parse("${cpu}")),100,0.5,0.5,0.5,1,1,0,1,1,1,10,50,0,1,0,1,1,1,0,1,80,1,0,0,1)

Last edited by mrpeachy (2012-01-21 20:15:15)

Offline

Be excellent to each other!

#25 2012-01-21 20:16:24

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: HOW TO : using lua scripts in conky

just want to mention that i added a new section to part 9 about using function within functions

this post will eventually be about tables

anyone still reading lol

Last edited by mrpeachy (2012-01-21 20:24:55)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.
Server: bleh

Debian Logo