Page 12 of 34 FirstFirst ... 2101112131422 ... LastLast
Results 111 to 120 of 334

Thread: Conky Lua & Cairo Troubleshooting

  1. #111
    Join Date
    Nov 2008
    Location
    Wirral, UK
    Beans
    277
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Need Help With the Photo-Album.lua script

    Quote Originally Posted by londonali1010 View Post
    Oh, good, it's true you had me a bit stumped Anyway, don't feel bad, I do things like that quite regularly...
    Right, I know I said I fixed it, but I lied, when the album has displayed all of it's pictures, the place that should show the first picture again remains blank.
    if i run conky from the terminal I get this error at the same time,
    I think it is trying to display picture 0(ZERO) does anyone have any ideas how I can fix it?
    Code:
    sed: -e expression #1, char 2: invalid usage of line address 0
    Here is the script
    Code:
    require 'cairo'
    require 'imlib2'
     
    -- OPTIONS
    -- "album_dir" is the directory containing the images for your photo album; please note that the path must be absolute (e.g. no "~")
    album_dir = "/home/phil/Documents/MyPictures/"
    -- "xc" and "yc" are the coordinates of the centre of the photo album, relative to the top left corner of the Conky window, in pixels
    xc, yc = 140, 140
    -- "w_max" and "h_max" are the maximum dimensions, in pixels, that you want the widget to be.  The script will ensure that the photo album fits inside the box bounded by w_max and h_max
    w_max, h_max = 280, 140
    -- "t" is the thickness of the frame, in pixels
    t = 2
    -- "update_interval" is the number of Conky updates between refreshes
    update_interval = 1
     
    function get_file_to_use()
        num_files = tonumber(conky_parse("${exec ls -A " .. album_dir .. " | wc -l}"))
        if num_files == nil then num_files = 0 end
        if num_files == 0 then return "none" end
     
        updates = tonumber(conky_parse("${updates}"))
        whole = math.ceil(updates/update_interval)
     
        if whole <= num_files
        then
            num_file_to_show = whole
        else
            whole = whole % num_files
            num_file_to_show = whole
        end
     
        return conky_parse("${exec ls " .. album_dir .. " | sed -n " .. num_file_to_show .. "p}")
    end
     
    function init_drawing_surface()
        imlib_set_cache_size(4096 * 1024)
        imlib_context_set_dither(1)
    end
     
    function draw_frame()
    	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)
     
        cairo_rectangle(cr, xc - width/2 - t, yc - height/2 - t, width + 2*t, height + 2*t)
        cairo_set_source_rgba(cr, 0.1, 0.4, 1, 0.4)
        cairo_fill(cr)   
     
        cairo_destroy(cr)
    end
     
    function draw_image()
        init_drawing_surface()
     
        image = imlib_load_image(album_dir .. filename)
        if image == nil then return end
        imlib_context_set_image(image)
     
    	w_img, h_img = imlib_image_get_width(), imlib_image_get_height()
    	if w_img >= h_img
    	then
    	    width = w_max - 2*t
    	    height = width * (h_img/w_img)
    	else
    	    height = h_max - 2*t
    	    width = height * (w_img/h_img)
    	end
     
    	draw_frame()
     
    	buffer = imlib_create_image(width, height)
    	imlib_context_set_image(buffer)
     
    	imlib_blend_image_onto_image(image, 0, 0, 0, w_img, h_img, 0, 0, width, height)
    	imlib_context_set_image(image)
    	imlib_free_image()
     
    	imlib_context_set_image(buffer)
    	imlib_render_image_on_drawable(xc - width/2, yc - height/2)
    	imlib_free_image()
    end
     
     
    function conky_photo_album()
        if conky_window == nil then return end
        filename = get_file_to_use()
        if filename == "none"
        then
            print(album_dir .. ": No files found")
        else
            draw_image()
        end
    end
    Thanks in Advance
    Phil

    ps it doesn't display the last picture either, the work around is put a picture I don't want to display and call it zzzzzzzz.jpg
    Last edited by 5BallJuggler; December 14th, 2009 at 10:52 AM. Reason: missing info
    I'll never drink water again....Fish poo in it!
    XP for iTunes Only : Ubuntu10.04 : Crunchbang : DSL
    I'm Pushing Narcoleptic Numbat for ubuntu11.04
    Proper Funny Stuff

  2. #112
    Join Date
    Feb 2009
    Location
    UK
    Beans
    129
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Hi Phil...if you put the following in your terminal prompt, can you confirm that it outputs the correct number of files in the album_dir?
    Code:
    ls -A <album_dir> | wc -l
    - Samsung R519 Silver - Dual-Boot Windows 7/Ubuntu 9.10 -
    - The Official Conky Blog - Follow conkynews on Twitter -
    - My Launchpad PPA -
    - My blog: My Little Desktop -

  3. #113
    Join Date
    Nov 2008
    Location
    Wirral, UK
    Beans
    277
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Conky Lua & Cairo Troubleshooting

    Quote Originally Posted by londonali1010 View Post
    Hi Phil...if you put the following in your terminal prompt, can you confirm that it outputs the correct number of files in the album_dir?
    Code:
    ls -A <album_dir> | wc -l
    Code:
    phil@phil-netbook:~$ exec ls -A "/home/phil/Documents/MyPictures/" | wc -l
    16
    Code:
    phil@phil-netbook:~$ exec ls "/home/phil/Documents/MyPictures" | sed -n p
    10.jpg
    11.jpg
    12.jpg
    13.bmp
    14.jpg
    15.jpg
    1.jpg
    2.jpg
    3.jpg
    4.jpg
    5.jpg
    6.jpg
    7.jpg
    8.jpg
    9.jpg
    zzzzzzzzzz.jpg
    so the commands are returning the correct data.
    I'll never drink water again....Fish poo in it!
    XP for iTunes Only : Ubuntu10.04 : Crunchbang : DSL
    I'm Pushing Narcoleptic Numbat for ubuntu11.04
    Proper Funny Stuff

  4. #114
    Join Date
    Feb 2009
    Location
    UK
    Beans
    129
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Well, your code matches mine and your album directory looks fine, so my next step would be to add some checks in the code and watch it run in the terminal...If you add in
    Code:
    print(updates, update_interval, num_file_to_show)
    localfilename = conky_parse("${exec ls " .. album_dir .. " | sed -n " .. num_file_to_show .. "p}")
    print(localfilename)
    just before the "return", that should print, for every iteration of Conky, what update number you're on, the update interval, which file to show, and the name of the file it's returning. That should pinpoint where it's going wrong.
    - Samsung R519 Silver - Dual-Boot Windows 7/Ubuntu 9.10 -
    - The Official Conky Blog - Follow conkynews on Twitter -
    - My Launchpad PPA -
    - My blog: My Little Desktop -

  5. #115
    Join Date
    Nov 2008
    Location
    Wirral, UK
    Beans
    277
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Conky Lua & Cairo Troubleshooting

    Quote Originally Posted by londonali1010 View Post
    Well, your code matches mine and your album directory looks fine, so my next step would be to add some checks in the code and watch it run in the terminal...If you add in
    Code:
    print(updates, update_interval, num_file_to_show)
    localfilename = conky_parse("${exec ls " .. album_dir .. " | sed -n " .. num_file_to_show .. "p}")
    print(localfilename)
    just before the "return", that should print, for every iteration of Conky, what update number you're on, the update interval, which file to show, and the name of the file it's returning. That should pinpoint where it's going wrong.
    Code:
    1	1	1
    10.jpg
    1	1	1
    10.jpg
    1	1	1
    10.jpg
    2	1	2
    11.jpg
    3	1	3
    12.jpg
    4	1	4
    13.bmp
    5	1	5
    14.jpg
    6	1	6
    15.jpg
    7	1	7
    1.jpg
    8	1	8
    2.jpg
    9	1	9
    3.jpg
    10	1	10
    4.jpg
    11	1	11
    5.jpg
    12	1	12
    6.jpg
    13	1	13
    7.jpg
    14	1	14
    8.jpg
    15	1	15
    9.jpg
    16	1	16
    zzzzzzzzzz.jpg
    17	1	1
    10.jpg
    18	1	2
    11.jpg
    19	1	3
    12.jpg
    20	1	4
    13.bmp
    21	1	5
    14.jpg
    22	1	6
    15.jpg
    23	1	7
    1.jpg
    24	1	8
    2.jpg
    25	1	9
    3.jpg
    26	1	10
    4.jpg
    27	1	11
    5.jpg
    28	1	12
    6.jpg
    29	1	13
    7.jpg
    30	1	14
    8.jpg
    31	1	15
    9.jpg
    32	1	0
    sed: -e expression #1, char 2: invalid usage of line address 0
    
    sed: -e expression #1, char 2: invalid usage of line address 0
    33	1	1
    10.jpg
    34	1	2
    11.jpg
    35	1	3
    12.jpg
    36	1	4
    13.bmp
    37	1	5
    14.jpg
    38	1	6
    15.jpg
    it seems that during the first cycle all of the files are called OK, but in subsequent cycles it misses out zzzzzzz.jpg and tries to call image 0(zero)
    I'll never drink water again....Fish poo in it!
    XP for iTunes Only : Ubuntu10.04 : Crunchbang : DSL
    I'm Pushing Narcoleptic Numbat for ubuntu11.04
    Proper Funny Stuff

  6. #116
    Join Date
    Feb 2009
    Location
    UK
    Beans
    129
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Ah, I see...the index isn't reinitialising correctly at the end.

    Replace
    Code:
    if whole <= num_files
    then
        num_file_to_show = whole
    else
        whole = whole % num_files
        num_file_to_show = whole
    end
    with
    Code:
    if whole <= num_files
    then
        num_file_to_show = whole
    else
        whole = whole % num_files
        if whole == 0 then whole = num_files end
        num_file_to_show = whole
    end
    or
    Code:
    if whole <= num_files
    then
        num_file_to_show = whole
    else
        whole = (whole - 1) % num_files + 1
        num_file_to_show = whole
    end
    Both should work, not sure which one's more efficient!
    - Samsung R519 Silver - Dual-Boot Windows 7/Ubuntu 9.10 -
    - The Official Conky Blog - Follow conkynews on Twitter -
    - My Launchpad PPA -
    - My blog: My Little Desktop -

  7. #117
    Join Date
    Nov 2008
    Location
    Wirral, UK
    Beans
    277
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Conky Lua & Cairo Troubleshooting

    Thanks Londonali

    I used this one

    Code:
    if whole <= num_files
    then
        num_file_to_show = whole
    else
        whole = whole % num_files
        if whole == 0 then whole = num_files end
        num_file_to_show = whole
    end
    It works a treat, solving both issues

    Thanks very much
    Phil
    I'll never drink water again....Fish poo in it!
    XP for iTunes Only : Ubuntu10.04 : Crunchbang : DSL
    I'm Pushing Narcoleptic Numbat for ubuntu11.04
    Proper Funny Stuff

  8. #118
    Join Date
    Dec 2009
    Beans
    1

    Re: Conky Lua & Cairo Troubleshooting

    Hi everyone,

    I'm new to conky, and after some time spent trying to install it, it finally compiled and installed.
    It however seems that whenever i want to draw circles using cairo_xlib_surface_create, it wont work.

    I am currently using Milax configuration files (http://www.milax.org/?p=287), eventhough i also tested with some of londonali1010's nice widgets.

    It would seem that the display, drawable and visual fields of the conky_window variable are nil..

    The error output of conky is:
    Code:
    42sh$ conky -c ~/.conkyrc                                                                                                                                                                     | 13:55
    Conky: desktop window (67) is root window
    Conky: window type - desktop
    Conky: drawing to created window (0x1e00001)
    Conky: drawing to double buffer
    table: 0x8d892c8
    nil
    nil
    nil
    2
    2
    Conky: llua_do_call: function conky_ring_stats execution failed: /home/scyn/rings.lua:254: attempt to call global 'cairo_xlib_surface_create' (a nil value)
    table: 0x8d892c8
    nil
    nil
    nil
    1002
    602
    Conky: llua_do_call: function conky_ring_stats execution failed: /home/scyn/rings.lua:254: attempt to call global 'cairo_xlib_surface_create' (a nil value)
    table: 0x8d892c8
    nil
    nil
    nil
    1002
    602
    Conky: llua_do_call: function conky_ring_stats execution failed: /home/scyn/rings.lua:254: attempt to call global 'cairo_xlib_surface_create' (a nil value)
    table: 0x8d892c8
    nil
    nil
    nil
    1002
    602
    Conky: llua_do_call: function conky_ring_stats execution failed: /home/scyn/rings.lua:254: attempt to call global 'cairo_xlib_surface_create' (a nil value)
    table: 0x8d892c8
    nil
    nil
    nil
    1002
    602
    Conky: llua_do_call: function conky_ring_stats execution failed: /home/scyn/rings.lua:254: attempt to call global 'cairo_xlib_surface_create' (a nil value)
    ^CConky: received SIGINT or SIGTERM to terminate. bye!
    The intermediate prints between errors are the fields of conky_window.

    Here are my conkyrc and clock_rings
    Code:
    # -- Conky settings -- #
    background no
    update_interval 1
    
    cpu_avg_samples 2
    net_avg_samples 2
    
    override_utf8_locale yes
    
    double_buffer yes
    no_buffers yes
    
    text_buffer_size 2048
    #imlib_cache_size 0
    
    # -- Window specifications -- #
    
    own_window yes
    own_window_type desktop
    own_window_transparent yes
    own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
    
    border_inner_margin 0
    border_outer_margin 0
    
    minimum_size 1020 600
    maximum_width 1000
    
    alignment tm
    gap_x 10
    gap_y 0
    
    # -- Graphics settings -- #
    draw_shades no
    draw_outline no
    draw_borders no
    draw_graph_borders no
    
    # -- Text settings -- #
    use_xft yes
    xftfont Santana:size=24
    xftalpha 0.8
    
    uppercase no
    
    default_color FFFFFF
    
    # -- Lua Load -- #
    lua_load ~/rings.lua
    lua_draw_hook_pre conky_ring_stats
    
    TEXT
    ${voffset 35}${font Santana:size=50}${alignr}${time %H.%M}${font}
    ${goto 160}${hr 2}
    ${goto 250}${time %A, %d %B %Y}
    Code:
    --[[
    Ring Meters by londonali1010 (2009)
    
    This script draws percentage meters as rings. It is fully customisable; all options are described in the 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/rings-v1.2.lua
        lua_draw_hook_pre ring_stats
        
    Changelog:
    + v1.2 -- Added option for the ending angle of the rings (07.10.2009)
    + v1.1 -- Added options for the starting angle of the rings, and added the "max" variable, to allow for variables that output a numerical value rather than a percentage (29.09.2009)
    + v1.0 -- Original release (28.09.2009)
    ]]
    
    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.1,
            -- "fg_colour" is the colour of the indicator part of the ring.
            fg_colour=0xffffff,
            -- "fg_alpha" is the alpha value of the indicator part of the ring.
            fg_alpha=0.2,
            -- "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=165, y=170,
            -- "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 (e.g. more clockwise) than start_angle.
            end_angle=360
        },
        {
            name='time',
            arg='%M.%S',
            max=60,
            bg_colour=0xffffff,
            bg_alpha=0.1,
            fg_colour=0xffffff,
            fg_alpha=0.4,
            x=165, y=170,
            radius=56,
            thickness=5,
            start_angle=0,
            end_angle=360
        },
        {
            name='time',
            arg='%S',
            max=60,
            bg_colour=0xffffff,
            bg_alpha=0.1,
            fg_colour=0xffffff,
            fg_alpha=0.6,
            x=165, y=170,
            radius=62,
            thickness=5,
            start_angle=0,
            end_angle=360
        },
        {
            name='cpu',
            arg='cpu1',
            max=100,
            bg_colour=0xffffff,
            bg_alpha=0,
            fg_colour=0xffffff,
            fg_alpha=0.1,
            x=165, y=170,
            radius=70,
            thickness=5,
            start_angle=60,
            end_angle=120
        },
        {
            name='cpu',
            arg='cpu2',
            max=100,
            bg_colour=0xffffff,
            bg_alpha=0,
            fg_colour=0xffffff,
            fg_alpha=0.1,
            x=165, y=170,
            radius=76,
            thickness=5,
            start_angle=60,
            end_angle=120
        },
        {
            name='cpu',
            arg='cpu0',
            max=100,
            bg_colour=0xffffff,
            bg_alpha=0.1,
            fg_colour=0xffffff,
            fg_alpha=0.4,
            x=165, y=170,
            radius=84.5,
            thickness=8,
            start_angle=60,
            end_angle=120
        },
        {
            name='battery_percent',
            arg='BAT1',
            max=100,
            bg_colour=0xffffff,
            bg_alpha=0.1,
            fg_colour=0xffffff,
            fg_alpha=0.6,
            x=165, y=170,
            radius=72,
            thickness=11,
            start_angle=122,
            end_angle=210
        },
        {
            name='memperc',
            arg='',
            max=100,
            bg_colour=0xffffff,
            bg_alpha=0.1,
            fg_colour=0xffffff,
            fg_alpha=0.8,
            x=165, y=170,
            radius=83.5,
            thickness=8,
            start_angle=122,
            end_angle=210
        },
        {
            name='time',
            arg='%d',
            max=31,
            bg_colour=0xffffff,
            bg_alpha=0.1,
            fg_colour=0xffffff,
            fg_alpha=0.8,
            x=165, y=170,
            radius=70,
            thickness=5,
            start_angle=212,
            end_angle=360
        },
        {
            name='time',
            arg='%m',
            max=12,
            bg_colour=0xffffff,
            bg_alpha=0.1,
            fg_colour=0xffffff,
            fg_alpha=0.8,
            x=165, y=170,
            radius=76,
            thickness=5,
            start_angle=212,
            end_angle=360
        },
        {
            name='fs_used_perc',
            arg='/',
            max=150,
            bg_colour=0xffffff,
            bg_alpha=0.2,
            fg_colour=0xffffff,
            fg_alpha=0.3,
            x=165, y=170,
            radius=108.5,
            thickness=3,
            start_angle=-120,
            end_angle=240
        },
        {
            name='fs_used_perc',
            arg='/',
            max=100,
            bg_colour=0xffffff,
            bg_alpha=0.2,
            fg_colour=0xffffff,
            fg_alpha=0.3,
            x=165, y=170,
            radius=135,
            thickness=50,
            start_angle=-120,
            end_angle=120
        },
    }
    
    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 conky_ring_stats()
        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
    
        if conky_window==nil then return end
        print (conky_window)
        print (conky_window.display)
        print (conky_window.drawable)
        print (conky_window.visual)
        print (conky_window.width)
        print (conky_window.height)
        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
    end
    Thanks in advance, and apologies for my english
    Happy conking,

    --
    Scyn

  9. #119
    Join Date
    Aug 2008
    Beans
    360
    Distro
    Ubuntu 12.04 Precise Pangolin

    Smile Re: Conky Lua & Cairo Troubleshooting

    While i was trying to have the photo album thing i get this error:
    Code:
    Conky: llua_do_call: function conky_widgets execution failed: ...e/chinmaya/.conkyscripts/conky_widgets_duplicate.lua:150: attempt to call global 'cairo_xlib_surface_create' (a nil value)
    I can run that air clock! but this is giving problem! My .conkyrc
    Code:
    background no
    
    cpu_avg_samples 2
    net_avg_samples 1
        
    use_xft yes
    xftfont Radio Space:size=45
    uppercase no
    
    xftalpha 0.1
    update_interval 1.0
    use_spacer none
    
    total_run_times 0
    
    own_window yes
    own_window_type override
    own_window_transparent yes
    #own_window_type normal
    own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
    
    double_buffer yes
    no_buffers yes
    
    gap_x 15
    gap_y 30
      
    draw_shades no
    draw_outline no
    draw_borders no
    #draw_graph_borders no
    
    default_color white
    default_shade_color white
    default_outline_color white
    alignment top_right
    
    minimum_size 600 80
    maximum_width 600
      
    #override_utf8_locale yes
    #text_buffer_size 256
    
    color1 5e97f6
    color2 FFFFFF
    
    #--lua load --#
    lua_load ~/.conkyscripts/conky_widgets_duplicate.lua
    lua_draw_hook_pre conky_widgets
    
    ### Now we start drawing ! ###
    
    TEXT
    ${voffset -10}${alignr}${time %d %B %Y}
    
    ${voffset -90}${goto 15} ${font Sans Bold:size=17} ${alignc} ${color1}CPU ${color2}${cpu cpu1}${color1} RAM ${color2}$memperc ${color1} DOWN ${color2}${downspeed eth0} ${color1} UP ${color2}${upspeed eth0}
    And my conky_widgets_duplicate.lua (i copied the code from your script!):
    Code:
    --[[ PHOTO ALBUM WIDGET ]]
    --[[ by londonali1010 (2009) ]]
    --[[ Options (album_dir, xc, yc, w_max, h_max, t, update_interval)
        "album_dir" is the directory containing the images for your photo album; please note that the path must be absolute (e.g. no "~")
        "xc" and "yc" are the coordinates of the centre of the photo album, relative to the top left corner of the Conky window, in pixels
        "w_max" and "h_max" are the maximum dimensions, in pixels, that you want the widget to be.  The script will ensure that the photo album fits inside the box bounded by w_max and h_max
        "t" is the thickness of the frame, in pixels
        "update_interval" is the number of Conky updates between refreshes ]]
    
    function photo_album(album_dir, xc, yc, w_max, h_max, t, update_interval)
        local function get_file_to_use()
            num_files = tonumber(conky_parse("${exec ls -A " .. album_dir .. " | wc -l}"))
            if num_files == nil then num_files = 0 end
            if num_files == 0 then return "none" end
        
            updates = tonumber(conky_parse("${updates}"))
            whole = math.ceil(updates/update_interval)
        
            if whole <= num_files
            then
                num_file_to_show = whole
            else
                whole = whole % num_files
                num_file_to_show = whole
            end
        
            return conky_parse("${exec ls " .. album_dir .. " | sed -n " .. num_file_to_show .. "p}")
        end
    
        function init_drawing_surface()
            imlib_set_cache_size(4096 * 1024)
            imlib_context_set_dither(1)
        end
    
        function draw_frame()
            cairo_rectangle(cr, xc - width/2 - t, yc - height/2 - t, width + 2*t, height + 2*t)
            cairo_set_source_rgba(cr, 1, 1, 1, 0.8)
            cairo_fill(cr)   
        end
    
        function draw_image()
            init_drawing_surface()
        
            image = imlib_load_image(album_dir .. filename)
            if image == nil then return end
            imlib_context_set_image(image)
    	
        	w_img, h_img = imlib_image_get_width(), imlib_image_get_height()
        	if w_img >= h_img
        	then
        	    width = w_max - 2*t
        	    height = width * (h_img/w_img)
        	else
        	    height = h_max - 2*t
        	    width = height * (w_img/h_img)
        	end
        	
        	draw_frame()
        	
        	buffer = imlib_create_image(width, height)
        	imlib_context_set_image(buffer)
        	
        	imlib_blend_image_onto_image(image, 0, 0, 0, w_img, h_img, 0, 0, width, height)
        	imlib_context_set_image(image)
        	imlib_free_image()
        	
        	imlib_context_set_image(buffer)
        	imlib_render_image_on_drawable(xc - width/2, yc - height/2)
        	imlib_free_image()
        end
    
        if conky_window == nil then return end
        filename = get_file_to_use()
        if filename == "none"
        then
            print(album_dir .. ": No files found")
        else
            draw_image()
        end
    end
    
    --[[ END PHOTO ALBUM WIDGET ]]
    
    
    
    --[[ RING (COUNTER-CLOCKWISE) WIDGET ]]
    --[[ v1.1 by londonali1010 (2009) ]]
    --[[ Options (name, arg, max, bg_colour, bg_alpha, xc, yc, radius, thickness, start_angle, end_angle):
    	"name" is the type of stat to display; you can choose from 'cpu', 'memperc', 'fs_used_perc', 'battery_used_perc'.
    	"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 ''.
    	"max" is the maximum value of the ring. If the Conky variable outputs a percentage, use 100.
    	"bg_colour" is the colour of the base ring.
    	"bg_alpha" is the alpha value of the base ring.
    	"fg_colour" is the colour of the indicator part of the ring.
    	"fg_alpha" is the alpha value of the indicator part of the ring.
    	"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.
    	"radius" is the radius of the ring.
    	"thickness" is the thickness of the ring, centred around the radius.
    	"start_angle" is the starting angle of the ring, in degrees, counter-clockwise from top. Value can be either positive or negative.
    	"end_angle" is the ending angle of the ring, in degrees, counter-clockwise from top. Value can be either positive or negative, but must be larger (e.g. more counter-clockwise) than start_angle. ]]
    
    function ring_ccw(name, arg, max, bgc, bga, fgc, fga, xc, yc, r, t, sa, ea)
    	local function rgb_to_r_g_b(colour, alpha)
    		return ((colour / 0x10000) % 0x100) / 255., ((colour / 0x100) % 0x100) / 255., (colour % 0x100) / 255., alpha
    	end
    	
    	local function draw_ring(pct)
    		local angle_0 = sa * (2 * math.pi/360) - math.pi/2
    		local angle_f = ea * (2 * math.pi/360) - math.pi/2
    		local pct_arc = pct * (angle_f - angle_0)
    
    		-- Draw background ring
    
    		cairo_arc_negative(cr, xc, yc, r, angle_0, angle_f)
    		cairo_set_source_rgba(cr, rgb_to_r_g_b(bgc, bga))
    		cairo_set_line_width(cr, t) 
    		cairo_stroke(cr)
    	
    		-- Draw indicator ring
    
    		cairo_arc_negative(cr, xc, yc, r, angle_0, angle_0 - pct_arc)
    		cairo_set_source_rgba(cr, rgb_to_r_g_b(fgc, fga))
    		cairo_stroke(cr)
    	end
    	
    	local function setup_ring()
    		local str = ''
    		local value = 0
    		
    		str = string.format('${%s %s}', name, arg)
    		str = conky_parse(str)
    		
    		value = tonumber(str)
    		if value == nil then value = 0 end
    		pct = value/max
    		
    		draw_ring(pct)
    	end	
    	
    	local updates = conky_parse('${updates}')
    	update_num = tonumber(updates)
    	
    	if update_num > 5 then setup_ring() end
    end
    
    --[[ END RING (COUNTER-CLOCKWISE) WIDGET ]]
    
    function conky_widgets()
    	if conky_window == nil then return end
    	local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
    	cr = cairo_create(cs)
            photo_album('/home/chinmaya/Pictures', 100, 100, 320, 180, 10, 5)
    	
    	cairo_destroy(cr)
    end
    Can you help me out!!
    Never hate your Enemy. It will affect your Judgement !

  10. #120
    Join Date
    Aug 2009
    Location
    East of Atlantic
    Beans
    81
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Hi,

    This is my attempt to use lua binding (but no cairo) in my conky . It is based on londonali's Photo Album but pictures are displayed as stacks in a messy way (the script create an image after each conky refresh with all photos previously displayed).

    I have post this on a blog too : http://u-scripts.blogspot.com/

    bye !

    w.

    Edit 22 Feb 2010:
    v1.1 The script is updated and can now get images from deviant art website






    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by wlourf; February 22nd, 2010 at 09:39 PM.

Page 12 of 34 FirstFirst ... 2101112131422 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •