SEARCH

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

You are not logged in.

#76 2013-03-08 11:10:06

dk75
#! Junkie
Registered: 2012-06-14
Posts: 250

Re: HOW TO : using lua scripts in conky

borntwisted wrote:

Thanks for taking the time to explain all this mrpeachy, used lua in conky for quite a while but not fully understood it apart from minor modification to other people's scripts, so really appreciate it being explained smile

There might be a minor typo in the first post, think you meant string1*string2, otherwise it would be a loop?

mrpeachy wrote:

Using Lua scripts in conky

eg

string1=5
string2=9
string3=string1*string3

in this case string3 holds the value 45

Actually it it's completely genuine (apart from "in this case string3 holds the value 45" tongue ).
It will not raise any "loop" event, because every variable manipulation is done on it's copy in memory before assigning results:

string3 = 'copy of string1' * 'copy of string3'

That's why

value = value + 1

works alright too.


Debian Sid (Minted) x86_64/3.12-10, Conky 2.0_pre, Xorg 7.7/1.15.0, KDE 4.11.5, Intel X3100
Lenovo T61, HITACHI HTS722010K9SA00 100GB, WDC_WD5000BEVT 500GB
Linux user No.: 483055 | Conky Pitstop

Offline

Help fund CrunchBang, donate to the project!

#77 2013-06-30 11:07:57

v4let3
Member
Registered: 2013-06-08
Posts: 23

Re: HOW TO : using lua scripts in conky

Hey dude can u point it out where did u learn all this x)?
Plz i rly like to know more about this.

Offline

#78 2013-07-01 11:34:47

dk75
#! Junkie
Registered: 2012-06-14
Posts: 250

Re: HOW TO : using lua scripts in conky

It's hard for me to point out one place to learn.
Most of my knowledge come with time of using computers and scripting with various languages.

Need to copy variable in order to add it to other and store the result in original one is long time forgotten.

If you want to learn more about LUA then there's tons of LUA tutorials. Including official one where they state that you could make manipulations and storage it on same variable.

If you want to learn how incorporate LUA into Conky then there is "Monster Conky Thread" here, or at Ubuntu forum, there is ConkyPitstop from my sig with a ton of scripts and tutorials.
There is also Cairographics site with LUA Cairo tutorials and manual.


Debian Sid (Minted) x86_64/3.12-10, Conky 2.0_pre, Xorg 7.7/1.15.0, KDE 4.11.5, Intel X3100
Lenovo T61, HITACHI HTS722010K9SA00 100GB, WDC_WD5000BEVT 500GB
Linux user No.: 483055 | Conky Pitstop

Offline

#79 2013-07-01 12:44:39

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

Re: HOW TO : using lua scripts in conky

And you forgot this very thread ... see post #1  big_smile


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#80 2013-07-02 09:21:12

lionhead
#! Junkie
From: Dagobah / Germany
Registered: 2011-01-22
Posts: 459

Re: HOW TO : using lua scripts in conky

i just found this code from mrpeachy:

require 'cairo'

function conky_draw_fig()
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
--##############################################################################
--##############################################################################
--setup bars
ad=15

rootbar=tonumber(conky_parse("${fs_used_perc /}"))
pass={bnum=rootbar,barx=7,bary=316+ad,bhigh=10,blong=194,bout=0};bar(pass)

homebar=tonumber(conky_parse("${fs_used_perc /home}"))
pass={bnum=homebar,barx=7,bary=350+ad,bhigh=10,blong=194,bout=0};bar(pass)

--##############################################################################
--##############################################################################
end-- if updates>5
end-- end main function

function bar(t)
local bnum=t.bnum
if t.bmax==nil then bmax=100 else bmax=t.bmax end
local barx=t.barx+0.5
local bary=t.bary+0.5
local bhigh=t.bhigh
local blong=t.blong
local bout=t.bout
local length=((bnum/bmax)*blong)
cairo_rectangle (cr,barx,bary,length,-bhigh)
cairo_set_source_rgba (cr,0,1,0,1)
cairo_fill (cr)
if bout==1 then
cairo_rectangle (cr,barx,bary,blong,-bhigh)
cairo_set_source_rgba (cr,1,1,1,1)
cairo_set_line_width (cr,1)
cairo_stroke (cr)
end
end

this is a screenshot: http://conky.pitstop.free.fr/wiki/image … achy-1.jpg

it seems that it only works with older versions of conky. if i try this code it only displays 'normal' bars sad

i use conky 1.9.0.2.

Offline

#81 2013-07-02 10:47:00

dk75
#! Junkie
Registered: 2012-06-14
Posts: 250

Re: HOW TO : using lua scripts in conky

Sector11 wrote:

And you forgot this very thread ... see post #1  big_smile

Maybe because I didn't used it as my tutorial...   ]:D


Debian Sid (Minted) x86_64/3.12-10, Conky 2.0_pre, Xorg 7.7/1.15.0, KDE 4.11.5, Intel X3100
Lenovo T61, HITACHI HTS722010K9SA00 100GB, WDC_WD5000BEVT 500GB
Linux user No.: 483055 | Conky Pitstop

Offline

#82 2013-12-19 22:01:37

chalkyjoe
New Member
Registered: 2013-12-19
Posts: 1

Re: HOW TO : using lua scripts in conky

Hey Peachy, great tutorials! Although I was wondering, is there any way to use newlines from within the LUA file? I am making a timetable script for my classes, and want it to be vaguely something like:

first class name
first class room
first class time
first class teacher

second class name
second class room
second class time
second class teacher


etc.

But on different days I have different amount of classes, so I can't just put each line in an individual variable and move the ypos down a few pixels.

When I did something like "timetable = "lesson1 \n lesson2"" the \n just appeared as a square character.

Thanks for your time smile

Offline

#83 2014-03-03 10:33:05

tbk515
New Member
From: Pld, BG, EU, EA, SS, MW
Registered: 2014-03-03
Posts: 2

Re: HOW TO : using lua scripts in conky

Hi to all!
How to add more watch hands with Lua? I want 3 more for:
- numeric representation of the day of the week (%u);
- two-digit day of the month (with leading zeros) (%d);
- general example for other functions.
Is it possible?
I want to make chronograph watch. The clock background will be image from Conky, and I need only from watch hands.
Here are my lua file, which is in the process of editing:

--[[
Clock Rings by Linux Mint (2011) reEdited by despot77

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)
]]

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,
        -- "fg_colour" is the colour of the indicator part of the ring.
        fg_colour=0xFF6600,
        -- "fg_alpha" is the alpha value of the indicator part of the ring.
        fg_alpha=0,
        -- "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=100, y=150,
        -- "radius" is the radius of the ring.
        radius=50,
        -- "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='%S',
        max=60,
        bg_colour=0xffffff,
        bg_alpha=0.1,
        fg_colour=0xFF6600,
        fg_alpha=0.6,
        x=100, y=150,
        radius=20,
        thickness=5,
        start_angle=0,
        end_angle=360
    },
    {
        name='time',
        arg='%u',
        max=7,
        bg_colour=0xffffff,
        bg_alpha=0.1,
        fg_colour=0xFF6600,
        fg_alpha=0.8,
        x=100, y=250,
        radius=15,
        thickness=50,
        start_angle=0,
        end_angle=360
    },
    {
        name='time',
        arg='%d',
        max=31,
        bg_colour=0xffffff,
        bg_alpha=0.1,
        fg_colour=0xFF6600,
        fg_alpha=0.8,
        x=100, y=350,
        radius=25,
        thickness=49,
        start_angle=90,
        end_angle=270
    },
}

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

clock_r=96

-- "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=96
clock_y=96

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

Excuse me for my bad English is not my native language!
Thanks in advance!

Offline

#84 2014-03-03 13:51:18

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

Re: HOW TO : using lua scripts in conky

tbk515 wrote:

Hi to all!
Is it possible?
I want to make chronograph watch. The clock background will be image from Conky, and I need only from watch hands.

Excuse me for my bad English is not my native language!
Thanks in advance!

Your English is fine.

What you want is already done.
2014_02_23_16_14_07_312x966_Sector11.jpg White.jpg The_S11_Clock_x4.jpg
circle and ring backgrounds done with draw-bg.lua


Code available two versions: Version One, Version Two and Version Two (2)

Last edited by Sector11 (2014-03-03 13:59:44)


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#85 2014-03-03 16:37:22

tbk515
New Member
From: Pld, BG, EU, EA, SS, MW
Registered: 2014-03-03
Posts: 2

Re: HOW TO : using lua scripts in conky

@Sector11, Thank you!
I appreciate your suggestions, but but I do not want the entire code!
I desire something like this:
2014_02_03_08_17_51_352x352_Sector11.jpg

but only the hands. How to edit my lua file to add 3 more hands?
Again, Thanks in advance!

Offline

#86 2014-03-03 18:04:05

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

Re: HOW TO : using lua scripts in conky

tbk515 wrote:

@Sector11, Thank you!
I appreciate your suggestions, but but I do not want the entire code!
I desire something like this:
http://s20.postimg.org/r9enhqg0d/2014_0 … ctor11.jpg

but only the hands. How to edit my lua file to add 3 more hands?
Again, Thanks in advance!

I'm not lua literate .. I can't 'create' lua code ... I can tweak it though.  The original idea for the chronograph I came up with was because of mrpeachy's 4clocks.lua script.  The memory leak from the original clock.lua was plugged and it has 4 clocks in one script ... so there you are - 4 sets of hands.  The idea of changing them to day names, day numbers and month names came later.  When I showed you where the code was it was for you to look at and see how to do what you wanted.

Maybe looking at 4clocks.lua by mrpeachy will lead you in the right direction:
2014_03_03_14_34_57_612x162_Sector11.jpg
4clocks.lua

--[[multiple analogue clocks by mrpeachy - 18 Jun 2012
in conkyrc
lua_load /path/4clocks.lua
lua_draw_hook_pre main
TEXT
--]]

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)
--#########################################################################################################
--CLOCK SETTINGS
--set border options
clock_border_width=0
--set color and alpha for clock border
cbr,cbg,cbb,cba=1,1,1,1--full opaque white
--gap from clock border to hour marks
b_to_m=5
--set mark length
m_length=5
--set mark line width
m_width=2
--set mark line cap type
m_cap=CAIRO_LINE_CAP_ROUND
--set mark color and alpha,red blue green alpha
mr,mg,mb,ma=1,1,1,1--opaque white
--seconds hand setup
--set length of seconds hand
sh_length=50
--set hand width
sh_width=1
--set hand line cap
sh_cap=CAIRO_LINE_CAP_ROUND
--set seconds hand color
shr,shg,shb,sha=1,0,0,1--fully opaque red
--minues hand setup
--set length of minutes hand
mh_length=50
--set hand width
mh_width=2
--set hand line cap
mh_cap=CAIRO_LINE_CAP_ROUND
--set minute hand color
mhr,mhg,mhb,mha=1,1,1,1--fully opaque white
--hour hand setup
--set length of hour hand
hh_length=30
--set hand width
hh_width=2
--set hand line cap
hh_cap=CAIRO_LINE_CAP_ROUND
--set hour hand color
hhr,hhg,hhb,hha=1,1,1,1--fully opaque white


--CURRENT TIME
clock_radius=60
clock_centerx=100
clock_centery=75
--DRAWING CODE
--draw border
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
--draw marks
--stuff that can be moved outside of the loop, needs only be set once
--calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length
--set line cap type
cairo_set_line_cap  (cr, m_cap)
--set line width
cairo_set_line_width (cr,m_width)
--set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
--start for loop
for i=1,12 do
--drawing code uisng the value of i to calculate degrees
--calculate start point for 12 oclock mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
--calculate end point for 12 oclock mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--draw the line
cairo_stroke (cr)
end--of for loop
--[[ --time calculations###########################
hours=tonumber(os.date("%I"))--12 hour clock
--convert hours to seconds
h_to_s=hours*60*60
minutes=tonumber(os.date("%M"))
--convert minutes to seconds
m_to_s=minutes*60
--get current seconds
seconds=tonumber(os.date("%S"))
]]
--time calculations ### not local ############
hours=tonumber(conky_parse("${tztime Canada/Pacific %l}"))
--convert hours to seconds
h_to_s=hours*60*60
minutes=tonumber(conky_parse("${tztime Canada/Pacific %M}"))
--convert minutes to seconds
m_to_s=minutes*60
--get current seconds
seconds=tonumber(conky_parse("${tztime Canada/Pacific %S}"))
--draw hour hand ############################
--get hours minutes seconds as just seconds
hsecs=h_to_s+m_to_s+seconds
--calculate degrees for the hand each second
hsec_degs=hsecs*(360/(60*60*12))--im using an equation instead of typing the calculation straight in because the result of 360/43200 gave us decimal places
--set radius we will use to calculate hand points
radius=hh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,hh_width)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
--draw minutes hand
--get minutes and seconds just as seconds
msecs=m_to_s+seconds
--calculate degrees for the hand each second
msec_degs=msecs*0.1
--set radius we will use to calculate hand points
radius=mh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,mh_width)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
--draw seconds hand #############################
--calculate degrees for the hand each second
sec_degs=seconds*6
--set radius we will use to calculate hand points
radius=sh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes
cairo_set_line_width (cr,sh_width)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr)
--###################################################

--ALTERNATE TIME 1 ##################################
--CLOCK SETTINGS
clock_radius=60
clock_centerx=240
clock_centery=75
--DRAWING CODE
--draw border
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
--draw marks
--stuff that can be moved outside of the loop, needs only be set once
--calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length
--set line cap type
cairo_set_line_cap  (cr, m_cap)
--set line width
cairo_set_line_width (cr,m_width)
--set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
--start for loop
for i=1,12 do
--drawing code uisng the value of i to calculate degrees
--calculate start point for 12 oclock mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
--calculate end point for 12 oclock mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--draw the line
cairo_stroke (cr)
end--of for loop
--time calculations###########################
hours=tonumber(conky_parse("${tztime Canada/Central %l}"))
--convert hours to seconds
h_to_s=hours*60*60
minutes=tonumber(conky_parse("${tztime Canada/Central %M}"))
--convert minutes to seconds
m_to_s=minutes*60
--get current seconds
seconds=tonumber(conky_parse("${tztime Canada/Central %S}"))
--draw hours hand ############################
--get hours minutes seconds as just seconds
hsecs=h_to_s+m_to_s+seconds
--calculate degrees for the hand each second
hsec_degs=hsecs*(360/(60*60*12))--im using an equation instead of typing the calculation straight in because the result of 360/43200 gave us decimal places
--set radius we will use to calculate hand points
radius=hh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,hh_width)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
--draw minutes hand
--get minutes and seconds just as seconds
msecs=m_to_s+seconds
--calculate degrees for the hand each second
msec_degs=msecs*0.1
--set radius we will use to calculate hand points
radius=mh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,mh_width)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
--draw seconds hand #############################
--calculate degrees for the hand each second
sec_degs=seconds*6
--set radius we will use to calculate hand points
radius=sh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes
cairo_set_line_width (cr,sh_width)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr)
--###################################################

--ALTERNATE TIME 2 ##################################
--CLOCK SETTINGS
clock_radius=60
clock_centerx=380
clock_centery=75
--DRAWING CODE
--draw border
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
--draw marks
--stuff that can be moved outside of the loop, needs only be set once
--calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length
--set line cap type
cairo_set_line_cap  (cr, m_cap)
--set line width
cairo_set_line_width (cr,m_width)
--set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
--start for loop
for i=1,12 do
--drawing code uisng the value of i to calculate degrees
--calculate start point for 12 oclock mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
--calculate end point for 12 oclock mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--draw the line
cairo_stroke (cr)
end--of for loop
--time calculations###########################
hours=tonumber(conky_parse("${tztime Canada/Atlantic %l}"))
--convert hours to seconds
h_to_s=hours*60*60
minutes=tonumber(conky_parse("${tztime Canada/Atlantic %M}"))
--convert minutes to seconds
m_to_s=minutes*60
--get current seconds
seconds=tonumber(conky_parse("${tztime Canada/Atlantic %S}"))
--draw hours hand ############################
--get hours minutes seconds as just seconds
hsecs=h_to_s+m_to_s+seconds
--calculate degrees for the hand each second
hsec_degs=hsecs*(360/(60*60*12))--im using an equation instead of typing the calculation straight in because the result of 360/43200 gave us decimal places
--set radius we will use to calculate hand points
radius=hh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,hh_width)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
--draw minutes hand
--get minutes and seconds just as seconds
msecs=m_to_s+seconds
--calculate degrees for the hand each second
msec_degs=msecs*0.1
--set radius we will use to calculate hand points
radius=mh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,mh_width)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
--draw seconds hand #############################
--calculate degrees for the hand each second
sec_degs=seconds*6
--set radius we will use to calculate hand points
radius=sh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes
cairo_set_line_width (cr,sh_width)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr)
--###################################################

--ALTERNATE TIME 1 ##################################
--CLOCK SETTINGS
clock_radius=60
clock_centerx=520
clock_centery=75
--DRAWING CODE
--draw border
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
--draw marks
--stuff that can be moved outside of the loop, needs only be set once
--calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length
--set line cap type
cairo_set_line_cap  (cr, m_cap)
--set line width
cairo_set_line_width (cr,m_width)
--set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
--start for loop
for i=1,12 do
--drawing code uisng the value of i to calculate degrees
--calculate start point for 12 oclock mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
--calculate end point for 12 oclock mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*30)
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--draw the line
cairo_stroke (cr)
end--of for loop
--time calculations###########################
hours=tonumber(conky_parse("${tztime GMT %l}"))
--convert hours to seconds
h_to_s=hours*60*60
minutes=tonumber(conky_parse("${tztime GMT %M}"))
--convert minutes to seconds
m_to_s=minutes*60
--get current seconds
seconds=tonumber(conky_parse("${tztime GMT %S}"))
--draw hours hand ############################
--get hours minutes seconds as just seconds
hsecs=h_to_s+m_to_s+seconds
--calculate degrees for the hand each second
hsec_degs=hsecs*(360/(60*60*12))--im using an equation instead of typing the calculation straight in because the result of 360/43200 gave us decimal places
--set radius we will use to calculate hand points
radius=hh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,hh_width)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
--draw minutes hand
--get minutes and seconds just as seconds
msecs=m_to_s+seconds
--calculate degrees for the hand each second
msec_degs=msecs*0.1
--set radius we will use to calculate hand points
radius=mh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of minutes hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes and draw line
cairo_set_line_width (cr,mh_width)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
--draw seconds hand #############################
--calculate degrees for the hand each second
sec_degs=seconds*6
--set radius we will use to calculate hand points
radius=sh_length
--set our starting line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
--calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
--describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
--set up line attributes
cairo_set_line_width (cr,sh_width)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr)
--###################################################
--#########################################################################################################
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end-- end main function

The code for the image you showed has a lot of comments added by me. The index is user friendly with 'highlight the line' and use find and was my 'development' lua script for the 22 versions I have of "the chronograph" lua script (various stages of development):
chrono_mix.lua

--[[ multiple analogue clocks by mrpeachy - 18 Jun 2012
 21 Jun 2012 - Chronograph modifications by Sector11
 22 Jun 2012 - again with mrpeachy's help day names, numbers and month names
 23 Jun 2012 - crono.lua by mrprachy - modified by Sector11 23/24 Jun 2012
 24 Jun 2012 - crono_mix - combination of Cronograph.lua and modified crono.lua

use in conkyrc

lua_load /path/crono_mix.lua
lua_draw_hook_pre main
TEXT

-- INDEX (use find with):

-- ###### 12 OR 24 CLOCK FACE
-- SET BORDER OPTIONS ######  ALL CLOCKS

-- ### START CLOCK A ######################################
-- MARKS AROUND CLOCK A -- Large Main 24 HR Clock
-- CLOCK A HOUR HAND
-- CLOCK A MINUTE HAND SETUP
-- CLOCK A SECOND HAND SETUP
-- CLOCK A ###### 24 HR TIME

-- ### START DIAL B ### Top - Week Day Names Dial #########
-- ### START DIAL C ### Right - Month Names Dial ##########
-- ### START DIAL D ### Left - Day Numbers Dial ###########

-- ### START CLOCK E ######################################
-- MARKS AROUND CLOCK E -- Bottom - 12 HR Clock
-- CLOCK E HOUR HAND
-- CLOCK E MINUTE HAND SETUP
-- CLOCK E SECOND HAND SETUP
-- CLOCK E ###### 12 HR TIME

TO GET MONTH NAME WHERE THE HOUR # IS FOR THAT MONTH
 mrpeachy wrote:

    the numbers are drawn using a for loop somewhere, like this

    for i=1,12 do
    calculate position of number
    move_to(x,y)
    show_text(i)
    end

    change it to something like this

    for i=1,12 do
    calculate position of number
      if i==month_number then
      move_to(x,y)
      show_text(month_number)
      else
      move_to(x,y)
      show_text(i)
      end
    end ]]


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 extents=cairo_text_extents_t:create()
tolua.takeownership(extents)
-- ### SETTINGS AREA ######################################
-- ###### 12 OR 24 CLOCK FACE #############################
local clock_type_A=24 -- Large Main 24 HR Clock
local clock_type_E=12 -- Bottom - 12 HR Clock

-- ###### CLOCK SETTINGS ##################################
-- SET BORDER OPTIONS FOR "CLOCKS" ########################
local clock_border_width=0
-- set color and alpha for clock border
local cbr,cbg,cbb,cba=1,1,1,1  -- full opaque white
-- gap from clock border to minute marks
local b_to_m=1

-- ########################################################
-- ### START CLOCK A ######################################
-- MARKS AROUND CLOCK A -- Large Main 24 HR Clock
local number_marks_A=24
-- set mark length
local m_length_A=0
-- set mark width
local m_width_A=0
-- set mark line cap type
local m_cap=CAIRO_LINE_CAP_ROUND
-- set mark color and alpha,red blue green alpha
local mr,mg,mb,ma=1,1,1,1-- opaque white
-- SETUP HOUR HANDS
-- CLOCK A HOUR HAND
-- set length of hour hand
hh_length_A=130
-- set hour hand width
hh_width_A=3
-- set hour hand line cap
hh_cap=CAIRO_LINE_CAP_ROUND
-- set hour hand color
hhr,hhg,hhb,hha=1,1,1,1-- fully opaque white
-- SETUP MINUTE HANDS
-- CLOCK A MINUTE HAND SETUP
-- set length of minute hand
mh_length_A=145
-- set minute hand width
mh_width_A=2
-- set minute hand line cap
mh_cap=CAIRO_LINE_CAP_ROUND
-- set minute hand color
mhr,mhg,mhb,mha=1,1,1,1-- fully opaque white
-- SETUP SECOND HANDS
-- CLOCK A SECOND HAND SETUP
-- set length of seconds hand
sh_length_A=160
-- set hour hand width
sh_width_A=1
-- set hour hand line cap
sh_cap=CAIRO_LINE_CAP_ROUND
-- set seconds hand color
shr,shg,shb,sha=1,0,0,1-- fully opaque red
-- CLOCK A ###### 24 HR TIME
-- CLOCK SETTINGS
clock_radius=200
clock_centerx=175
clock_centery=175
-- DRAWING CODE
-- DRAW BORDER
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
-- DRAW MARKS
-- stuff that can be moved outside of the loop, needs only be set once
-- calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length_A
-- set line cap type
cairo_set_line_cap  (cr, m_cap)
-- set line width
cairo_set_line_width (cr,m_width_A)
-- set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
-- START LOOP FOR HOUR MARKS
for i=1,number_marks_A do
-- drawing code using the value of i to calculate degrees
-- calculate start point for 12/24 hour mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*(360/number_marks_A))
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
-- calculate end point for 12/24 hour mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*(360/number_marks_A))
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- draw the line
cairo_stroke (cr)
end-- of for loop
-- HOUR MARKS
-- TIME CALCULATIONS CLOCK A
if clock_type_A==12 then
hours=tonumber(os.date("%I"))
-- convert hours to seconds
h_to_s=hours*60*60
elseif clock_type_A==24 then
hours=tonumber(os.date("%H"))
-- convert hours to seconds
h_to_s=hours*60*60
end
minutes=tonumber(os.date("%M"))
-- convert minutes to seconds
m_to_s=minutes*60
-- get current seconds
seconds=tonumber(os.date("%S"))
-- DRAW HOUR HAND
-- get hours minutes seconds as just seconds
hsecs=h_to_s+m_to_s+seconds
-- calculate degrees for each second
hsec_degs=hsecs*(360/(60*60*clock_type_A))-- use equation ~ eliminate decimals
-- set radius to calculate hand points
radius=hh_length_A
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of hour hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes and draw line
cairo_set_line_width (cr,hh_width_A)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
-- DRAW MINUTE HAND
-- get minutes and seconds just as seconds
msecs=m_to_s+seconds
-- calculate degrees for each second
msec_degs=msecs*0.1
-- set radius to calculate hand points
radius=mh_length_A
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of minute hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes and draw line
cairo_set_line_width (cr,mh_width_A)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
--[[ DRAW SECOND HAND
-- calculate degrees for each second
sec_degs=seconds*6
-- set radius to calculate hand points
radius=sh_length_A
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes
cairo_set_line_width (cr,sh_width_A)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr) ]]
-- POSITION FOR TEXT HOUR NUMBERS
local center_x=175
local center_y=175
local radius=160
-- FONT
cairo_select_font_face (cr, "CorporateMonoExtraBold", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 10)
cairo_set_source_rgba (cr,1,1,1,1)
-- TABLE OF TEXT -- in order
text_days={"00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23",}
for i=1,24 do
-- OUTTER POINTS POSTION FOR TEXT
local point=(math.pi/180)*((360/24)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
-- CALCULATE CENTRE OF TEXT
local text=text_days[i]--gets text from table
cairo_text_extents(cr,text,extents)
local width=extents.width
local height=extents.height
cairo_move_to(cr,center_x+x-(width/2),center_y+y+(height/2))
cairo_show_text (cr, text)
cairo_stroke (cr)
end
-- INNER POINTS POSITION, radius smaller than text circle
local radius=150
for i=1,24 do
local point=(math.pi/180)*((360/24)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,1,0,2*math.pi)
cairo_stroke (cr)
end
-- ### END CLOCK A ########################################

-- ########################################################
-- ### START DIAL B ### Top - Week Day Names Dial #########
-- days of week
-- positioning
local center_x=175
local center_y=95
local radius=50
cairo_select_font_face (cr, "CorporateMonoExtraBold", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 10)
cairo_set_source_rgba (cr,1,1,1,1)
-- table holds text you want to see in order
text_days={"SUN","MON","TUE","WED","THR","FRI","SAT",}
-- draw days
local tx_deg=30
for i=1,7 do
start=((360/7)*(i-1))-(tx_deg/2)
circlewriting (text_days[i], "CorporateMonoExtraBold", 10, radius, center_x, center_y, {0xffffff,1}, start, start+tx_deg)
end
--draw points, radius smaller than text circle

local radius=45
for i=1,7 do
local point=(math.pi/180)*((360/7)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,1,0,2*math.pi)
cairo_stroke (cr)
end
--draw hand pointing to current day
local hand_length=40--radius for this calculation
local day_number=tonumber(os.date("%w"))
local point=(math.pi/180)*((360/7)*(day_number))
local x=0+hand_length*(math.sin(point))
local y=0-hand_length*(math.cos(point))
cairo_move_to (cr,center_x,center_y)
cairo_line_to (cr,center_x+x,center_y+y)
cairo_stroke (cr)
-- ### END CLOCK B ########################################

-- ########################################################
-- ### START DIAL C ### Right - Month Names Dial ##########
-- DIAL POSITION FOR TEXT
local center_x=260
local center_y=175
local radius=45
cairo_select_font_face (cr, "CorporateMonoExtraBold", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 10)
cairo_set_source_rgba (cr,1,1,1,1)
-- table holds text you want to see in order
text_days={"DEC","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV",}
-- draw days
local tx_deg=20
for i=1,12 do
start=((360/12)*(i-1))-(tx_deg/2)
circlewriting (text_days[i], "CorporateMonoExtraBold", 10, radius, center_x, center_y, {0xffffff,1}, start, start+tx_deg)
end
--draw points, radius smaller than text circle

local radius=40
for i=1,12 do
local point=(math.pi/180)*((360/12)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,1,0,2*math.pi)
cairo_stroke (cr)
end
--draw hand pointing to current day
local hand_length=35 --radius for this calculation
local day_number=tonumber(os.date("%m"))
local point=(math.pi/180)*((360/12)*(day_number))
local x=0+hand_length*(math.sin(point))
local y=0-hand_length*(math.cos(point))
cairo_move_to (cr,center_x,center_y)
cairo_line_to (cr,center_x+x,center_y+y)
cairo_stroke (cr)
-- ### END CLOCK C ########################################

-- ### START DIAL D ### Left - Day Numbers Dial ###########
-- GET NUMBER OF DAYS IN CURRENT MONTH
-- calculate Feb, then set up table
year4num=os.date("%Y")
t1=os.time({year=year4num,month=03,day=01,hour=00,min=0,sec=0});
t2=os.time({year=year4num,month=02,day=01,hour=00,min=0,sec=0});
febdaynum=tonumber((os.difftime(t1,t2))/(24*60*60))
-- MONTH TABLE
monthdays={31,febdaynum,31,30,31,30,31,31,30,31,30,31}
this_month=tonumber(os.date("%m"))
number_days=monthdays[this_month]
-- TEXT positioning
local center_x=95
local center_y=175
local radius=50
cairo_select_font_face (cr, "CorporateMonoExtraBold", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 8)
cairo_set_source_rgba (cr,1,1,1,1)
for i=1,number_days do
-- OUTTER POINTS POSTION FOR TEXT
local point=(math.pi/180)*((360/number_days)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
-- CALCULATE CENTRE OF TEXT
local text=i
cairo_text_extents(cr,text,extents)
local width=extents.width
local height=extents.height
cairo_move_to(cr,center_x+x-(width/2),center_y+y+(height/2))
cairo_show_text (cr, text)
cairo_stroke (cr)
end
-- INNER POINTS POSITION, radius smaller than text circle
local radius=40
for i=1,number_days do
local point=(math.pi/180)*((360/number_days)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,1,0,2*math.pi)
cairo_stroke (cr)
end
-- DRAW HAND -- snaps to current DAY
local this_day=tonumber(os.date("%d"))
local hand_length=35--radius for this calculation
local point=(math.pi/180)*((360/number_days)*(this_day-1))
local x=0+hand_length*(math.sin(point))
local y=0-hand_length*(math.cos(point))
cairo_move_to (cr,center_x,center_y)
cairo_line_to (cr,center_x+x,center_y+y)
cairo_stroke (cr)
-- ### END CLOCK D ########################################

-- ########################################################
-- ### START CLOCK E ######################################
-- MARKS AROUND CLOCK E -- Bottom - 12 HR Clock
local number_marks_E=12
-- set mark length
local m_length_E=0
-- set mark width
local m_width_E=0
-- set mark line cap type
local m_cap=CAIRO_LINE_CAP_ROUND
-- set mark color and alpha,red blue green alpha
local mr,mg,mb,ma=1,1,0,1-- opaque white
-- SETUP HOUR HAND
-- CLOCK E HOUR HAND
-- set length of hour hand
hh_length_E=22
-- set hour hand width
hh_width_E=4
-- set hour hand line cap
hh_cap=CAIRO_LINE_CAP_ROUND
-- set hour hand color
hhr,hhg,hhb,hha=0.3,  0.6,  0.9  ,1 -- fully opaque lightblue
-- SETUP MINUTE HAND
-- CLOCK E MINUTE HAND SETUP
-- set length of minute hand
mh_length_E=37
-- set minute hand width
mh_width_E=2
-- set minute hand line cap
mh_cap=CAIRO_LINE_CAP_ROUND
-- set minute hand color
mhr,mhg,mhb,mha=0.0,  0.6,  0.9  ,1 -- fully opaque lightblue
-- SETUP SECOND HAND
-- CLOCK E SECOND HAND SETUP
-- set length of seconds hand
sh_length_E=40
-- set hour hand width
sh_width_E=1
-- set hour hand line cap
sh_cap=CAIRO_LINE_CAP_ROUND
-- set seconds hand color
shr,shg,shb,sha=1,0,0,1 -- fully opaque red
-- CLOCK E ###### 12 HR TIME
-- CLOCK SETTINGS
clock_radius=45
clock_centerx=175
clock_centery=260
-- DRAWING CODE
-- DRAW BORDER
cairo_set_source_rgba (cr,cbr,cbg,cbb,cba)
cairo_set_line_width (cr,clock_border_width)
cairo_arc (cr,clock_centerx,clock_centery,clock_radius,0,2*math.pi)
cairo_stroke (cr)
-- DRAW MARKS
-- stuff that can be moved outside of the loop, needs only be set once
-- calculate end and start radius for marks
m_end_rad=clock_radius-b_to_m
m_start_rad=m_end_rad-m_length_E
-- set line cap type
cairo_set_line_cap  (cr, m_cap)
-- set line width
cairo_set_line_width (cr,m_width_E)
-- set color and alpha for marks
cairo_set_source_rgba (cr,mr,mg,mb,ma)
-- START LOOP FOR SECOND MARKS
for i=1,number_marks_E do
-- drawing code using the value of i to calculate degrees
-- calculate start point for 12/24 hour mark
radius=m_start_rad
point=(math.pi/180)*((i-1)*(360/number_marks_E))
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- set start point for line
cairo_move_to (cr,clock_centerx+x,clock_centery+y)
-- calculate end point for 12/24 hour mark
radius=m_end_rad
point=(math.pi/180)*((i-1)*(360/number_marks_E))
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- set path for line
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- draw the line
cairo_stroke (cr)
end-- of for loop
-- TIME CALCULATIONS CLOCK E
if clock_type_E==12 then
hours=tonumber(os.date("%I"))
-- convert hours to seconds
h_to_s=hours*60*60
elseif clock_type_E==24 then
hours=tonumber(os.date("%H"))
-- convert hours to seconds
h_to_s=hours*60*60
end
minutes=tonumber(os.date("%M"))
-- convert minutes to seconds
m_to_s=minutes*60
-- get current seconds
seconds=tonumber(os.date("%S"))
-- DRAW HOUR HAND
-- get hours minutes seconds as just seconds and draw it
hsecs=h_to_s+m_to_s+seconds
-- calculate degrees for each second
hsec_degs=hsecs*(360/(60*60*clock_type_E))-- use equation ~ eliminate decimals
-- set radius to calculate hand points
radius=hh_length_E
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of minute hand
point=(math.pi/180)*hsec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes and draw line
cairo_set_line_width (cr,hh_width_E)
cairo_set_source_rgba (cr,hhr,hhg,hhb,hha)
cairo_set_line_cap  (cr, hh_cap)
cairo_stroke (cr)
-- DRAW MINUTE HAND
-- get minutes and seconds as seconds
msecs=m_to_s+seconds
-- calculate degrees for each second
msec_degs=msecs*0.1
-- set radius to calculate hand points
radius=mh_length_E
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of minute hand
point=(math.pi/180)*msec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes and draw line
cairo_set_line_width (cr,mh_width_E)
cairo_set_source_rgba (cr,mhr,mhg,mhb,mha)
cairo_set_line_cap  (cr, mh_cap)
cairo_stroke (cr)
-- DRAW SECOND HAND
-- calculate degrees for each second
sec_degs=seconds*6
-- set radius to calculate hand points
radius=sh_length_E
-- set start line coordinates, the center of the circle
cairo_move_to (cr,clock_centerx,clock_centery)
-- calculate coordinates for end of seconds hand
point=(math.pi/180)*sec_degs
x=0+radius*(math.sin(point))
y=0-radius*(math.cos(point))
-- describe the line we will draw
cairo_line_to (cr,clock_centerx+x,clock_centery+y)
-- set up line attributes
cairo_set_line_width (cr,sh_width_E)
cairo_set_source_rgba (cr,shr,shg,shb,sha)
cairo_set_line_cap  (cr, sh_cap)
cairo_stroke (cr)
-- POSITION FOR TEXT HOUR NUMBERS
local center_x=175
local center_y=260
local radius=45
-- FONT
cairo_select_font_face (cr, "CorporateMonoExtraBold", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 10)
cairo_set_source_rgba (cr,1,1,1,1)
-- TABLE OF TEXT -- in order
--text_days={"12","01","02","03","04","05","06","07","08","09","10","11",}
-- FOR A 12 HOUR CLOCK WITH THE NUMBERS 13-00
text_days={"00","13","14","15","16","17","18","19","20","21","22","23",}
for i=1,12 do
-- OUTTER POINTS POSTION FOR TEXT
local point=(math.pi/180)*((360/12)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
-- CALCULATE CENTRE OF TEXT
local text=text_days[i]--gets text from table
cairo_text_extents(cr,text,extents)
local width=extents.width
local height=extents.height
cairo_move_to(cr,center_x+x-(width/2),center_y+y+(height/2))
cairo_show_text (cr, text)
cairo_stroke (cr)
end
-- INNER POINTS POSITION, radius smaller than text circle
local radius=32
for i=1,12 do
local point=(math.pi/180)*((360/12)*(i-1))
local x=0+radius*(math.sin(point))
local y=0-radius*(math.cos(point))
cairo_arc (cr,center_x+x,center_y+y,1,0,2*math.pi)
cairo_stroke (cr)
end
-- ### END CLOCK E ########################################

-- ########################################################
end-- end main function

function circlewriting(text, font, fsize, radi, horiz, verti, text_color, start, finish)
local function rgb_to_r_g_b(col_a)
return ((col_a[1] / 0x10000) % 0x100) / 255, ((col_a[1] / 0x100) % 0x100) / 255, (col_a[1] % 0x100) / 255, col_a[2]
end
cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fsize)
cairo_set_source_rgba (cr,rgb_to_r_g_b(text_color));
local inum=string.len(text)
local deg=(finish-start)/(inum)
local r2d=(math.pi/180)
	for i=1,inum do
	local cha=string.sub(text,i,i)
	local interval=(r2d*(start+(deg*(i-1))))
	local txs=0+radi*(math.sin(interval))
	local tys=0-radi*(math.cos(interval))
	cairo_move_to (cr, txs+horiz, tys+verti);
	cairo_rotate (cr, interval)
	cairo_show_text (cr, cha)
	cairo_stroke (cr)
	cairo_rotate (cr, -interval)
	end
end--of function

Basically for each set of hands you need a new complete "function" for each 'clock', not just hands ...

Last edited by Sector11 (2014-03-03 18:07:57)


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#87 2014-03-03 20:38:10

dk75
#! Junkie
Registered: 2012-06-14
Posts: 250

Re: HOW TO : using lua scripts in conky

That's why moving every small part to separate functions is better.
If you have one function to calculate time, one function to calculate angle of hand for set time and function to draw hand as separate, you can reuse it for as much as you need.

My 2 cents.  ]:D


Debian Sid (Minted) x86_64/3.12-10, Conky 2.0_pre, Xorg 7.7/1.15.0, KDE 4.11.5, Intel X3100
Lenovo T61, HITACHI HTS722010K9SA00 100GB, WDC_WD5000BEVT 500GB
Linux user No.: 483055 | Conky Pitstop

Offline

#88 2014-03-03 22:43:30

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

Re: HOW TO : using lua scripts in conky

dk75 wrote:

That's why moving every small part to separate functions is better.
If you have one function to calculate time, one function to calculate angle of hand for set time and function to draw hand as separate, you can reuse it for as much as you need.

My 2 cents.  ]:D

this is indeed true big_smile

for me, doing the code in one large block or distributing the parts to functions depends on the complexity and purpose of the script...
while writing i typically write in a block, then when i see bits of the script that i am re using i move them to their own functions

but if a piece of code is a demonstration of principle, ie can i do this... oh look i can!
then it typically doesn't make it to the function distribution stage ]:D

Offline

#89 2014-03-03 22:54:29

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

Re: HOW TO : using lua scripts in conky

... and along comes a lua illiterate user, namely one Sector11, and I just use what I get my hands on ... tweaking the highly obvious. lol

If it works ... why fix it?  Just my 2½¢ worth.

Last edited by Sector11 (2014-03-03 22:55:44)


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

#90 2014-12-14 18:30:48

hecate
Member
Registered: 2014-11-05
Posts: 11

Re: HOW TO : using lua scripts in conky

I am trying to fetch data from a web page into a conky. I have read the first post on this thread and got the 'Hello World' printing out in a terminal and then followed this post but am having trouble ending the section I want to pull in  sad

The lua script - tidesrss.lua

--this is a lua script for use in conky
require 'cairo'

function conky_main()
updates=tonumber(conky_parse("${updates}"))
interval=100
timer=(updates % interval)
if timer==0 or conky_start==1 then
used_table={}
local web="https://www.tidetimes.org.uk/ferryside-tide-times"
local file = io.popen("curl "..web)
output=file:read("*a")
file:close()
local s,f,tides=string.find(output,"20px%p%p>([%d%a%p%s]*)</div>")
conky_start=nil
print (tides)
end
end

The generated source of the webpage section I want to pull is

<div style="float:left; margin:10px 0px 0px 20px;">
<table id="tide_summary">
<tbody><tr>
 <td class="high-tide">Low Tide</td>
 <td class="low-tide"><span>05:36</span> (0.80m)</td></tr><tr>
 <td class="high-tide" style="padding-top:35px;">High Tide</td>
 <td class="low-tide"><span>10:53</span> (5.00m)</td></tr><tr>
 <td class="high-tide" style="padding-top:35px;">Low Tide</td>
 <td class="low-tide"><span>18:00</span> (0.80m)</td></tr><tr>
 <td class="high-tide" style="padding-top:35px;">High Tide</td>
 <td class="low-tide"><span>23:28</span> (4.60m)</td></tr></tbody></table>
</div>

The "20px;">" at the end of the first line only occurs once in the generated code, so that's great to start it off but I can't work out how to stop it in the right place - my tidesrss.lua brings in the whole of the rest of the page into the terminal (probably because there are lots of </div>'s):

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 20130    0 20130    0     0  54177      0 --:--:-- --:--:-- --:--:-- 54112

<table id="tide_summary">
<tr>
 <td class="high-tide">Low Tide</td>
 <td class="low-tide"><span>05:36</span> (0.80m)</td></tr><tr>
 <td class="high-tide" style="padding-top:35px;">High Tide</td>
 <td class="low-tide"><span>10:53</span> (5.00m)</td></tr><tr>
 <td class="high-tide" style="padding-top:35px;">Low Tide</td>
 <td class="low-tide"><span>18:00</span> (0.80m)</td></tr><tr>
 <td class="high-tide" style="padding-top:35px;">High Tide</td>
 <td class="low-tide"><span>23:28</span> (4.60m)</td></tr></table>
</div>

<div style="float:left; margin:10px 0px 0px 30px;">
<table id="tide-calendar">
<tr><td id="cal-head" colspan="7">December 2014</td></tr>
<tr id="cal-days">
 <td>Sun</td>
 <td>Mon</td>
 <td>Tue</td>
 <td>Wed</td>
 <td>Thu</td>
 <td>Fri</td>
 <td>Sat</td>
</tr>
<tr>
<td colspan="1" class="cal-grey">&nbsp;</td> <td class="cal-day"><a href="/ferryside-tide-times-20141201" style="color:#3183AF" title="Ferryside Tide Times for 1 December 2014">1</a></td>

... AND ON TO THE END OF THE PAGE (which is very long!!)

Is there an lua magic character for an end bracket ')' - like the %s used for a space? If so I might be able to try

local s,f,tides=string.find(output,"20px%p%p>([%d%a%p%s]*)m)</td></tr></table>")

by replacing the ) after the m with the right character??? If I use the code above I just get

Conky: llua_do_call: function conky_main execution failed: attempt to call a nil value

Any help would be most appreciated!

Offline

#91 2014-12-14 19:23:28

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 987

Re: HOW TO : using lua scripts in conky

hecate wrote:

Is there an lua magic character for an end bracket ')' - like the %s used for a space? If so I might be able to try by replacing the ) after the m with the right character???

Yes it is

%)

You escape the control characters with a % followed by the character you need to escape.
You can find a good explanation of the rules on Lua pattern matching here to see some of the other less obvious things about how it works.

Offline

#92 2014-12-15 01:16:32

hecate
Member
Registered: 2014-11-05
Posts: 11

Re: HOW TO : using lua scripts in conky

@arclance Many thanks for your help. I now have the right amount of data coming into the terminal smile

Sadly, I can't get it to draw on the desktop. Still, tomorrow is another conky day ...

Thanks also for the link re Lua pattern matching - that is bookmarked!

Offline

#93 2014-12-15 14:15:22

hecate
Member
Registered: 2014-11-05
Posts: 11

Re: HOW TO : using lua scripts in conky

Running my script in a terminal I get the correct amount of data from the website now. I am planning to add the ')' onto the last line as text to tidy it up.

$ conky -c /home/hecate/ToolBox/conky/Other_Scripts/rss2
Conky: desktop window (e00003) is subwindow of root window (1e4)
Conky: window type - normal
Conky: drawing to created window (0x4000001)
Conky: drawing to double buffer
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 20075    0 20075    0     0  53398      0 --:--:-- --:--:-- --:--:-- 53390

<table id="tide_summary">
<tr>
 <td class="high-tide">Low Tide</td>
 <td class="low-tide"><span>06:14</span> (0.90m)</td></tr><tr>
 <td class="high-tide" style="padding-top:35px;">High Tide</td>
 <td class="low-tide"><span>11:54</span> (4.70m)</td></tr><tr>
 <td class="high-tide" style="padding-top:35px;">Low Tide</td>
 <td class="low-tide"><span>18:42</span> (0.90

Problem is I don't know the code that needs to be added to the lua script in order for the data to be displayed in the conky window, just commenting out the 'print (tides)' line simply draws an empty conky window on the desktop. I have read through this thread but can't seem to work out what to do.

Conky script

######################
# - Conky settings - #
######################

background no
update_interval 4
cpu_avg_samples 2
total_run_times 0
override_utf8_locale yes
 
double_buffer yes
#no_buffers yes
 
text_buffer_size 1024
#imlib_cache_size 0

minimum_size 300 300
maximum_width 320

gap_x 10
gap_y 50
#####################
# - Text settings - #
#####################
use_xft yes
xftfont monofur:size=12
#xftalpha .8
uppercase no
default_color ffffff
alignment bottom_left
#############################
# - Window specifications - #
#############################
own_window yes
own_window_transparent no
own_window_type normal
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
own_window_class conky-semi
#own_window_argb_visual yes
#own_window_argb_value 255
border_inner_margin 0
border_outer_margin 0
#########################
# - Graphics settings - #
#########################
draw_shades no
#default_shade_color 292421
draw_outline no
draw_borders no
stippled_borders 0
draw_graph_borders no

#lua_load /home/jed/Conky/LUA/draw_bg.lua
#lua_draw_hook_post draw_bg 10 0 0 0 0 0x5C3434 0.4
lua_load /home/hecate/ToolBox/conky/Other_Scripts/tidesrss2.lua
lua_draw_hook_post conky_main

TEXT

tidesrss2.lua

--this is a lua script for use in conky
require 'cairo'

function conky_main()
updates=tonumber(conky_parse("${updates}"))
interval=100
timer=(updates % interval)
if timer==0 or conky_start==1 then
used_table={}
local web="https://www.tidetimes.org.uk/ferryside-tide-times"
local file = io.popen("curl "..web)
output=file:read("*a")
file:close()
local s,f,tides=string.find(output,"20px%p%p>([%d%a%p%s]*)m%)</td></tr></table>")
conky_start=nil
--print (tides)
end
end

Thanks in advance to anyone who can help!

Offline

#94 2014-12-15 14:25:09

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 987

Offline

#95 2014-12-15 19:51:24

PeterIHughes
New Member
Registered: 2014-12-15
Posts: 5

Re: HOW TO : using lua scripts in conky

Hi, new to this forum.

linux mint 17.1 cinnamon
conky-all

all code stored in my #home/.conky/Moon_Phase directory

I have worked in software development for many years, and am familiar with c, c++, java, javascrip.
But it is my first time using linux / conky / lua, so I am sure I am missing something.

I have an issue using lua built in functions in conky.
The problem is that string functions such as "strsub" do not seem to work.
In fact, the seem to prevent the lua returning any output.


The lua itself is executing (so it is not a problem with how it is being called).
This is evidence by the fact that when the strsub function/method is commented out, the output I see on the desktop is my moon phase .png image and the text - AAAhelloAAA (thus showing the lua did something).

But, in the lua script below, when I remove the comment for the strsub line (and comment the previous line), the text on the desktop disappears.
I would expect it to say - AAA11AAA

I have tried other functions (find, format, len, lower, match etch)
This is part of a much bigger coding exersise.


Is there something else that needs to be included (such as - require 'cairo' - but I know that is not it)




the Moon_Phase conky code

# Moon Phases conky
.
.
the usual conky header stuff
.
.
# -- Lua Load -- #
lua_load /home/myusername/.conky/Moon_Phase/Moon_Phase.lua
lua_draw_hook_pre main

TEXT
${image $HOME/.conky/Moon_Phase/current.png -p 0,20 -s 200x200}

${lua_parse get_month_name ${execpi 600 sed -n '24p' $HOME/.conky/Moon_Phase/today} "yyyy-mm-dd"}

the Moon_Pahse.lua

-- lua script for use in Moon Phase conky
function conky_main()
end

function conky_get_month_name(date_str, dateformat)
	local monthname = ""
	if (date_str and date_str ~= "") then
		monthname = "hello"
--		monthname = strsub("2014-11-29",6,2)
	else
		monthname = "world"
	end
        month = "AAA" .. monthname .. "AAA"
        return month
end

Offline

#96 2014-12-15 22:11:47

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 987

Re: HOW TO : using lua scripts in conky

You need to use "string.strsub" not just "strsub" like this since "strsub" is part of the "string" library.

monthname = string.strsub("2014-11-29",6,2)

Offline

#97 2014-12-15 23:47:02

PeterIHughes
New Member
Registered: 2014-12-15
Posts: 5

Re: HOW TO : using lua scripts in conky

arclance wrote:

You need to use "string.strsub" not just "strsub" like this since "strsub" is part of the "string" library.

monthname = string.strsub("2014-11-29",6,2)

You guys are awesome.

Various versions of lua documentation show either "strsub"  or "sub".
In my case, "sub" worked this time along with your suggestion of preceding with "string."


I think I am going to like it here.


Many Thanks

Pete

BTW. I am trying to think of an easy way to get the day name.
Simple in other scripting languages. But lua does not seem to support a version of "strttodate"
Which I would need to use  before using %A od the date function.

I am still trying to get some form of string.gsub(dateformat, "DDD",  etc working

Offline

#98 2014-12-15 23:51:14

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 987

Offline

#99 2014-12-16 02:04:45

PeterIHughes
New Member
Registered: 2014-12-15
Posts: 5

Re: HOW TO : using lua scripts in conky

Thanks,

It is, sort of.......................

If I can move a string date to a date variable, then, I am hoping that I can use the built in DDD, ddd, MON etc functions to get back the parts of a date that I "REALLY NEED smile ".

But what I am trying to do, is replace all of the dates of future moon phases in my conky
from CCYY-MM-DD to "dayname   monthname - dd -ccyy"
such as "Mon   Dec - 15 - 2014"
It is not always (if ever) going to be the current date.


Moon phases is something I am trying to teach scouts, and a desktop lunar-calendar would be cool.
(more importantly to me as a programmer of a few plus years, I want to find an elegant solution.)

I have only had a linux PC for about a week now (thanks to a new pc and week plus long wait for a win 8.1 cd)

I am fudging my way through and trying to find a good scripting solution.

Are there other scripting languages avaiable for conky > ? Python etc
lua seems to be lacking (to me at least)

Offline

Help fund CrunchBang, donate to the project!

#100 2014-12-16 02:12:33

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 987

Re: HOW TO : using lua scripts in conky

You can use "io.popen" to run scripts in other languages and send the results to the Lua script.
I use Python for things that can't be done or are too difficult or complicated to do in Lua that way.

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: acrobat

Debian Logo