Page 10 of 34 FirstFirst ... 8910111220 ... LastLast
Results 91 to 100 of 334

Thread: Conky Lua & Cairo Troubleshooting

  1. #91
    Join Date
    Nov 2009
    Location
    Greece
    Beans
    4

    Re: Conky Lua & Cairo Troubleshooting

    Quote Originally Posted by londonali1010 View Post
    Quote Originally Posted by BornTwisted View Post
    Hi Ali, a couple of things have crossed my mind about the display of the rings, is there an easy way to get the rings to work anti-clockwise and is it possible to make them ovals?
    Probably!
    There's a cairo_arc_negative() function, which is the same as the cairo_arc function, just counterclockwise. I'm not sure about drawing an oval/ellipse...
    First of all I want to express my great gratitude to you for all the good things on my desktop. I'm currently adjusting my conky on #! and soon enough I'm going to post it on #! forums. I'm in great need for an anticlockwise ring and I was wondering if I could add the proper code in the rings.lua you have posted to make it also draw anticlockwise. I try to do it myself but I get messed up and lost since I can't say I have any experience with all that. So my thought was to add a second sequence of variables like:

    name2='cpu',
    arg2='cpu1',
    max2=100,
    bg_colour2=0xFFFFFF,
    bg_alpha2=0.1,
    fg_colour2=0xFFFFFF,
    fg_alpha2=0.5,
    x2=100, y2=101.5,
    radius2=82,
    thickness2=25,
    start_angle2=90,
    end_angle2=270

    and the proper code to draw an anticlockwise ring as well. Is it as simple as I'm thinking of it or is it simpler to load a new rings.lua with the cairo_arc_negative() instead of the cairo_arc() function?

    if it's not a big trouble can you post the new code to be added under the "require 'cairo' " part of the code?

    many thanks,
    Dimitris

  2. #92
    Join Date
    Dec 2007
    Beans
    3

    Re: Conky Lua & Cairo Troubleshooting

    Hi, this is my first message here on Ubuntuforums . I've always searched solutions here, rather than asking myself. But now it is time to ask for some help.

    I like Conky Rings a lot, but I'm having some troubles with it. What I want to know is: how can I establish the position of objects on a "z plane" other than the x and y planes in conky?

    I have two pngs in my config:

    ${image /home/user/.conky/PNGs/1.png -p 0,0}
    ${image /home/user/.conky/PNGs/2.png -p 0,0}

    and i want to put a ring between them. With the current config the ring is always on top:
    Attached Images Attached Images
    • File Type: jpg 1.jpg (34.5 KB, 27 views)

  3. #93
    Join Date
    Feb 2009
    Location
    UK
    Beans
    129
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Quote Originally Posted by vitvic View Post
    Hi, this is my first message here on Ubuntuforums . I've always searched solutions here, rather than asking myself. But now it is time to ask for some help.

    I like Conky Rings a lot, but I'm having some troubles with it. What I want to know is: how can I establish the position of objects on a "z plane" other than the x and y planes in conky?

    I have two pngs in my config:

    ${image /home/user/.conky/PNGs/1.png -p 0,0}
    ${image /home/user/.conky/PNGs/2.png -p 0,0}

    and i want to put a ring between them. With the current config the ring is always on top:
    Well, the problem is that they all draw to the same drawing surface, so theoretically, it should draw the ring first, then the .pngs on top (if you're using lua_draw_hook_pre to draw the rings). Certainly, if you draw two images with $image, the second one will be drawn on top of the first, if they overlap. Have you tried using Lua to draw your .pngs on your Conky window?

    Also, can you post your .conkyrc and any scripts?
    - 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 -

  4. #94
    Join Date
    Dec 2007
    Beans
    3

    Re: Conky Lua & Cairo Troubleshooting

    Thank You for your quick reply and above all your patience/kindness ^^. Anyway, I've not tried using lua. Do you reckon it should solve the trick? How should I do that? With a new lua-script or using the existing ring-script?

    This is the ring script, with only the cpu ring (I've deleted anything else):

    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=-200, 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='cpu',
    		arg='cpu1',
    		max=100,
    		bg_colour=0xffffff,
    		bg_alpha=0,
    		fg_colour=0xAB0000,
    		fg_alpha=0.9,
    		x=-10, y=200,
    		radius=320,
    		thickness=36,
    		start_angle=64,
    		end_angle=116
    	},
    }
    
    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
    	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
    and this is the conky config:

    Code:
    # Use Xft?
    use_xft yes
    xftfont saxMono:size=9
    xftalpha 0.8
    text_buffer_size 2048
    
    # Update interval in seconds
    update_interval 1.0
    
    # This is the number of times Conky will update before quitting.
    # Set to zero to run forever.
    total_run_times 0
    
    # Create own window instead of using desktop (required in nautilus)
     own_window yes
     own_window_transparent yes
     own_window_type override
     #own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
    
    # Use double buffering (reduces flicker, may not work for everyone)
    double_buffer yes
    
    # Minimum size of text area
    minimum_size 400 400
    maximum_width 400
    
    # Draw shades?
    draw_shades no
    
    # Draw outlines?
    draw_outline no
    
    # Draw borders around text
    draw_borders no
    
    # Stippled borders?
    stippled_borders 0
    
    # border margins
    border_inner_margin 5
    
    # border width
    border_width 1
    
    # Default colors and also border colors
    default_color white
    #default_shade_color black
    #default_outline_color white
    own_window_colour 333333
    
    # Text alignment, other possible values are commented
    #alignment top_middle
    alignment top_middle
    #alignment top_right
    #alignment bottom_left
    #alignment bottom_right
    
    # Gap between borders of screen and text
    # same thing as passing -x at command line
    gap_x 0
    gap_y 325
    
    # Subtract file system buffers from used memory?
    no_buffers yes
    
    # set to yes if you want all text to be in uppercase
    uppercase no
    
    # number of cpu samples to average
    # set to 1 to disable averaging
    cpu_avg_samples 2
    
    # number of net samples to average
    # set to 1 to disable averaging
    net_avg_samples 2
    
    # Force UTF8? note that UTF8 support required XFT
    override_utf8_locale yes
    
    # Add spaces to keep things from moving about?  This only affects certain objects.
    use_spacer none
    short_units yes
    pad_percents 2
    imlib_cache_size 0
    
    # -- Lua Load -- #
    lua_load /home/user/.conky/rings-v1.2.lua
    lua_draw_hook_pre ring_stats
    
    TEXT
    
    ${image /home/user/.conky/PNGs/1.png -p 0,0}
    ${image /home/user/.conky/PNGs/2.png -p 0,0}
    while these are the pngs I'm actually using (maybe You can understand what I'm trying to do watching at them):
    Attached Images Attached Images
    • File Type: png 1.png (58.0 KB, 22 views)
    • File Type: png 2.png (216.6 KB, 17 views)
    Last edited by vitvic; November 15th, 2009 at 12:15 PM. Reason: mistake

  5. #95
    Join Date
    Dec 2007
    Beans
    3

    Re: Conky Lua & Cairo Troubleshooting

    lua_draw_hook_pre ring_stats
    I think that this line is the problem:

    This function, if defined, will be called by Conky through each iteration before drawing to the window. Requires X support. Takes any number of optional arguments. Use this hook for drawing things on top of what Conky draws. Conky puts 'conky_' in front of function_name to prevent accidental calls to the wrong function unless you place 'conky_' in front of it yourself.
    I've tried some workarounds without success. I don't know how to draw a .png with Lua, so I've used your photo_album script to draw the top .png, but failed. It draws the .png on top, but seems to convert it to a .jpg (filling the empty spaces I've left on the picture).
    Any suggestions?

    Anyway, here a makeup of what I'm trying to do:
    Attached Images Attached Images
    Last edited by vitvic; November 15th, 2009 at 01:21 PM. Reason: adding attachment

  6. #96
    Join Date
    Sep 2008
    Location
    Italy Varese..
    Beans
    8
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Conky Lua & Cairo Troubleshooting

    I have installed KK..
    Now this is conky:



    Code:
    deegan@deegan-karmic:~$ conky -Version
    Conky 1.7.2 compiled Fri Oct 23 15:55:48 UTC 2009 for Linux 2.6.24-23-server (i686)
    
    Compiled in features:
    
    System config file: /etc/conky/conky.conf
    Package library path: /usr/lib/conky
    
     X11:
      * Xdamage extension
      * XDBE (double buffer extension)
      * Xft
    
     Music detection:
      * MPD
      * MOC
    
     General:
      * math
      * hddtemp
      * portmon
      * Curl
      * RSS
      * Weather (METAR)
      * Weather (XOAP)
      * wireless
      * support for IBM/Lenovo notebooks
      * nvidia
      * eve-online
      * config-output
      * Imlib2
      * ALSA mixer support
      * apcupsd
      * iostats
      * Lua
    
      Lua bindings:
       * Cairo
       * Imlib2
    deegan@deegan-karmic:~$
    If I launch the conky in.lua with:
    cpu0 cpu1 battery_percent memperc fs_used_perc
    OK..
    But if:



    Code:
    {
    	name='wireless_link_qual_perc',
    	arg='wlan0',
    	max=100,
    	bg_colour=0x3399cc,
    	bg_alpha=0.2,
    	fg_colour=0x3399cc,
    	fg_alpha=0.6,
    	x=350, y=100,
    	radius=25,
    	thickness=5,
    	start_angle=-90,
    	end_angle=180
        },
        {
    	name='upspeedf',
    	arg='wlan0',
    	max=100,
    	bg_colour=0x3399cc,
    	bg_alpha=0.2,
    	fg_colour=0x3399cc,
    	fg_alpha=0.3,
    	x=350, y=100,
    	radius=15,
    	thickness=4,
    	start_angle=-90,
    	end_angle=180
        },
        {
    	name='downspeedf',
    	arg='wlan0',
    	max=100,
    	bg_colour=0x3399cc,
    	bg_alpha=0.2,
    	fg_colour=0x3399cc,
    	fg_alpha=0.3,
    	x=350, y=100,
    	radius=20,
    	thickness=4,
    	start_angle=-90,
    	end_angle=180
         },
         {
    	name='fs_used_perc',
    	arg='/media/Xp black',
    	max=100,
    	bg_colour=0x3399cc,
    	bg_alpha=0.2,
    	fg_colour=0x3399cc,
    	fg_alpha=0.3,
    	x=900, y=40,
    	radius=20,
    	thickness=4,
    	start_angle=-90,
    	end_angle=180
    	},
    	{
    	name='fs_used_perc',
    	arg='/media/Xp black',
    	max=100,
    	bg_colour=0x3399cc,
    	bg_alpha=0.2,
    	fg_colour=0x3399cc,
    	fg_alpha=0.2,
    	x=900, y=40,
    	radius=15,
    	thickness=4,
    	start_angle=-90,
    	end_angle=180
    	},


    Code:
    deegan@deegan-karmic:~$ conky -c .conkyrc3
    Conky: desktop window (20000bc) is subwindow of root window (109)
    Conky: window type - override
    Conky: drawing to created window (0x4e00001)
    Conky: drawing to double buffer
    Conky: llua_do_call: function conky_clock_rings execution failed: /home/deegan/Scrivania/clock_rings.lua:314: attempt to perform arithmetic on local 'value' (a nil value)
    Conky: llua_do_call: function conky_clock_rings execution failed: /home/deegan/Scrivania/clock_rings.lua:314: attempt to perform arithmetic on local 'value' (a nil value)
    ^CConky: received SIGINT or SIGTERM to terminate. bye!
    deegan@deegan-karmic:~$

  7. #97
    Join Date
    Jul 2009
    Location
    Germany > Hessen > DA
    Beans
    26

    Re: Conky Lua & Cairo Troubleshooting

    Hi londonali1010,
    i have a problem with the lua, this error:
    Not BAT1 that no error!

    Code:
    [search@localhost ~]$ conky
    Conky: desktop window (1e000ba) is subwindow of root window (13f)
    Conky: window type - normal
    Conky: drawing to created window (0x4400001)
    Conky: drawing to double buffer
    Conky: can't open /sys/class/power_supply/BAT1/uevent: No such file or directory
    Conky: can't open /proc/acpi/battery/BAT1/state: No such file or directory
    Conky: llua_do_call: function conky_widgets execution failed: /home/search/conky/lua/widgets/conky_widgets.lua:323: attempt to perform arithmetic on local 'mem_process' (a nil value)
    the lua-widget:
    Code:
    --[[
    Conky Widgets by londonali1010 (2009)
    
    This script is meant to be a "shell" to hold a suite of widgets for use in Conky.
    
    To configure:
    + Copy the widget's code block (will be framed by --(( WIDGET NAME )) and --(( END WIDGET NAME )), with "[" instead of "(") somewhere between "require 'cairo'" and "function conky_widgets()", ensuring not to paste into another widget's code block
    + To call the widget, add the following just before the last "end" of the entire script:
        cr = cairo_create(cs)
        NAME_OF_FUNCTION(cr, OPTIONS)
        cairo_destroy(cr)
    + Replace OPTIONS with the options for your widget (should be specified in the widget's code block) 
    
    Call this script in Conky using the following before TEXT (assuming you save this script to ~/scripts/conky_widgets.lua):
        lua_load ~/scripts/conky_widgets.lua
        lua_draw_hook_pre widgets
        
    Changelog:
    + v1.0 -- Original release (17.10.2009)
    ]]
    
    require 'cairo'
    
    --[[ AIR CLOCK WIDGET ]]
    --[[ Options (xc, yc, size):
        "xc" and "yc" are the x and y coordinates of the centre of the clock, in pixels, relative to the top left of the Conky window
        "size" is the total size of the widget, in pixels ]]
    
    function air_clock(cr, xc, yc, size)
        local offset = 0
        
        shadow_width = size * 0.03
        shadow_xoffset = 0
        shadow_yoffset = size * 0.01
        
        if shadow_xoffset >= shadow_yoffset then
            offset = shadow_xoffset
        else offset = shadow_yoffset
        end
        
        local clock_r = (size - 2 * offset) / (2 * 1.25)
            
        show_seconds=true
        
        -- Grab time
        
        local hours=os.date("%I")
        local mins=os.date("%M")
        local secs=os.date("%S")
        
        secs_arc=(2*math.pi/60)*secs
        mins_arc=(2*math.pi/60)*mins
        hours_arc=(2*math.pi/12)*hours+mins_arc/12
        
        -- Drop shadow
        
        local ds_pat=cairo_pattern_create_radial(xc+shadow_xoffset,yc+shadow_yoffset,clock_r*1.25,xc+shadow_xoffset,yc+shadow_yoffset,clock_r*1.25+shadow_width)
        cairo_pattern_add_color_stop_rgba(ds_pat,0,0,0,0,0)  -- ,0,0,0,0.2
        cairo_pattern_add_color_stop_rgba(ds_pat,0,0,0,0,0) -- ,1,0,0,0,0
        
        cairo_move_to(cr,0,0)
        cairo_line_to(cr,conky_window.width,0)
        cairo_line_to(cr,conky_window.width, conky_window.height)
        cairo_line_to(cr,0,conky_window.height)
        cairo_close_path(cr)
        cairo_new_sub_path(cr)
        cairo_arc(cr,xc,yc,clock_r*1.25,0,2*math.pi)
        cairo_set_source(cr,ds_pat)
        cairo_set_fill_rule(cr,CAIRO_FILL_RULE_EVEN_ODD)
        cairo_fill(cr)
        
        -- Glassy border
        
        cairo_arc(cr,xc,yc,clock_r*1.25,0,2*math.pi)
        cairo_set_source_rgba(cr,0,0,0,0) -- ,0.5,0.5,0.5,0.2
        cairo_set_line_width(cr,1)
        cairo_stroke(cr)
        
        local border_pat=cairo_pattern_create_linear(xc,yc-clock_r*1.25,xc,yc+clock_r*1.25)
        
        cairo_pattern_add_color_stop_rgba(border_pat,0,0,0,0,0) -- ,0,1,1,1,0.7
        cairo_pattern_add_color_stop_rgba(border_pat,0,0,0,0,0) -- ,0.3,1,1,1,0
        cairo_pattern_add_color_stop_rgba(border_pat,0,0,0,0,0) -- ,0.5,1,1,1,0
        cairo_pattern_add_color_stop_rgba(border_pat,0,0,0,0,0) -- ,0.7,1,1,1,0
        cairo_pattern_add_color_stop_rgba(border_pat,0,0,0,0,0) -- ,1,1,1,1,0.7
        cairo_set_source(cr,border_pat)
        cairo_arc(cr,xc,yc,clock_r*1.125,0,2*math.pi)
        cairo_close_path(cr)
        cairo_set_line_width(cr,clock_r*0.25)
        cairo_stroke(cr)
        
        -- Set clock face
        
        cairo_arc(cr,xc,yc,clock_r,0,2*math.pi)
        cairo_close_path(cr)
        
        local face_pat=cairo_pattern_create_radial(xc,yc-clock_r*0.75,0,xc,yc,clock_r)
        
        cairo_pattern_add_color_stop_rgba(face_pat,0,0,0,0,0)        -- ,0,1,1,1,0.9
        cairo_pattern_add_color_stop_rgba(face_pat,0,0,0,0,0)      -- ,0.5,1,1,1,0.9
        cairo_pattern_add_color_stop_rgba(face_pat,0,0,0,0,0)  -- ,1,0.9,0.9,0.9,0.9
        cairo_set_source(cr,face_pat)
        cairo_fill_preserve(cr)
        cairo_set_source_rgba(cr,0,0,0,0) -- ,0.5,0.5,0.5,0.2
        cairo_set_line_width(cr, 1)
        cairo_stroke (cr)
        
        -- 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,0,0,0,0.8) -- ,0,0,0,0.4
        cairo_stroke(cr)
        
        -- Draw minute hand
        
        xm=xc+0.9*clock_r*math.sin(mins_arc)
        ym=yc-0.9*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+0.9*clock_r*math.sin(secs_arc)
            ys=yc-0.9*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
    
    --[[ END AIR CLOCK WIDGET ]]
    
    --[[ RING WIDGET ]]
    --[[ 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, clockwise from top. Value can be either positive or negative.
        "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. ]]
    
    function ring(cr, 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(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(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 WIDGET ]]
    
    --[[ GRADIENT RING WIDGET ]]
    --[[ Options (name, arg, max, colour, alpha, x, y, inner_radius, outer_radius, frac, 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.
            "fg_colour" is the colour of the ring.
            "fg_alpha" is the alpha value 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.
            "inner_radius" is the inner radius of the ring.
            "outer_radius" is the outer radius of the ring.  
            "frac" determines the extent of the gradient around the ring - 2 implies the gradient fades halfway around the ring, 4 equals a quarter of the way, etc...      
            "thickness" is the thickness of the ring, centred around the radius.
            "start_angle" is the starting angle of the ring, in degrees, clockwise from top. Value can be either positive or negative.
            "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. ]]
         
    function gradient_ring(cr, name, arg, max, fgc, fga, xc, yc, ring_i, ring_o, frac, 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_gradient_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)
         
                for i = 1,max/frac do
                    cairo_set_source_rgba(cr,rgb_to_r_g_b(fgc,fga*i/max)) --for flat shading of bars
            
                    --local pat=cairo_pattern_create_linear(xc-ring_i*math.sin(angle_0+t_arc+2*math.pi*i/max),yc+ring_i*math.cos(angle_0+t_arc+2*math.pi*i/max),xc-ring_o*math.sin(angle_0+t_arc+2*math.pi*i/max),yc+ring_o*math.cos(angle_0+t_arc+2*math.pi*i/max))
                    --cairo_pattern_add_color_stop_rgba(pat,0,rgb_to_r_g_b(fgc,0))
                    --cairo_pattern_add_color_stop_rgba(pat,1,rgb_to_r_g_b(fgc,fga*i/max))
                    --cairo_set_source(cr,pat) -- for gradient shading of bars
            
                    cairo_move_to(cr,xc-ring_i*math.cos(angle_0+pct_arc+2*math.pi*i/max),yc-ring_i*math.sin(angle_0+pct_arc+2*math.pi*i/max))
                    cairo_line_to(cr,xc-ring_o*math.cos(angle_0+pct_arc+2*math.pi*i/max),yc-ring_o*math.sin(angle_0+pct_arc+2*math.pi*i/max))
        
                    cairo_set_line_cap(cr,CAIRO_LINE_CAP_ROUND)
                    cairo_set_line_width(cr,t)
                    cairo_stroke(cr)
                end
            end
         
            local function setup_gradient_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_gradient_ring(pct)
            end    
         
            local updates=conky_parse('${updates}')
            update_num=tonumber(updates)
         
            if update_num>5 then setup_gradient_ring() end
        end
         
    --[[ END GRADIENT RING WIDGET ]]
    
    --[[ PIE WIDGET ]]
    --[[ xc,yc - center of the pie
         r - radius of the pie ]]
    
    function pie_rings (xc, yc, r)
    
        pat = cairo_pattern_create_radial (xc, yc, 0.2*r, xc,  yc, r);
        cairo_pattern_add_color_stop_rgba (pat, 0.1, 1, 1, 1, 0);
        cairo_pattern_add_color_stop_rgba (pat, 1.0, 1, 1, 1, 0.3);
        cairo_set_source (cr, pat);
        cairo_arc (cr, xc, yc, r, 0, 2 * math.pi);
        cairo_fill (cr);
        cairo_pattern_destroy (pat);
    
    
        cairo_set_font_size (cr, 10)
        cairo_select_font_face (cr, "LCDMono",
                    CAIRO_FONT_SLANT_NORMAL,
                    CAIRO_FONT_WEIGHT_NORMAL)    
        cairo_set_line_width (cr, 2.0)
    
        -- Show total mem usage
        local str1 = conky_parse(string.format('${mem}'))
        local str2 = string.match(str1, "(%d+)")
        local str3 = string.match(str1, "(%a+)")
    
        cairo_set_source_rgba(cr, 1, 1, 1, 1)
        cairo_move_to (cr, xc-9, yc-1)
        cairo_show_text (cr, str2)
        cairo_move_to (cr, xc-9, yc+9)
        cairo_show_text (cr, str3)
        cairo_stroke(cr)
    
        -- Get top mem usage
        local str1 = conky_parse(string.format('${mem}'))
        local mem = tonumber(string.match(str1, "(%d+)"))
        local str1 = conky_parse(string.format('${memperc}'))
        local mempct = tonumber(string.match(str1, "(%d+)"))
        
        -- Draw pie
        local angle = -90
        local angle2 = 0
        local tro = 4        -- Text rotational offset (degrees)
        local maxprocesses = 7
        local maxstrlen = 8
    
        for process = 1, maxprocesses do
    
            cairo_save(cr)
        
            -- Get top process memory usage
            local str2 = conky_parse(string.format('${top_mem mem %i}', tonumber(process)))
            local mem_process = tonumber(str2)
            local procpct = mem_process / mempct      <<<<<<<<<< this is Line 323
            angle2 = angle + (procpct*360)
    
            if angle2 > 260 then
                cairo_restore(cr)
                break
            end    
    
            -- Get top process name
            local str2 = conky_parse(string.format('${top_mem name %i} ', tonumber(process)))
            local index = string.find(str2,' ')
            
            if (index == nil) then
                cairo_restore(cr)
                break
            elseif (index > maxstrlen) then
                str2 = string.sub(str2, 0, maxstrlen)
            end
    
            -- Draw pie outline
            cairo_set_source_rgba(cr, 1, 1, 1, 0.2)        
            cairo_arc_negative (cr, xc, yc, 0.2*r, angle2*(math.pi/180), angle*(math.pi/180));            
            cairo_arc (cr, xc, yc, r, angle*(math.pi/180), angle2*(math.pi/180));    
    --        cairo_close_path(cr)
            cairo_stroke(cr)
    
            -- Draw text
            cairo_set_source_rgba(cr, 1, 1, 1, 1)    
            cairo_move_to(cr, xc, yc)
            cairo_rotate(cr, (angle2-((angle2-angle)/2)+tro)*(math.pi/180))
    --        cairo_show_text (cr, '    '..(procpct*100))
            if (index > maxstrlen) then
                cairo_show_text (cr, '      '..str2..'..')
            else
                cairo_show_text (cr, '      '..str2)
            end        
    
            angle = angle2 + 3
    
            cairo_stroke(cr)
            cairo_restore(cr)
        end
    
        if (angle < 264) then
            angle2 = 267
            cairo_set_source_rgba(cr, 1, 1, 1, 0.2)    
            cairo_arc_negative (cr, xc, yc, 0.2*r, angle2*(math.pi/180), angle*(math.pi/180));
            cairo_arc (cr, xc, yc, r, angle*(math.pi/180), angle2*(math.pi/180));    
    --        cairo_close_path(cr)
            cairo_stroke(cr)
            
            if ((angle2 - angle) > 20) then
                cairo_set_source_rgba(cr, 1, 1, 1, 0.5)    
                cairo_move_to(cr, xc, yc)
                cairo_rotate(cr, (angle2-((angle2-angle)/2)+tro+2)*(math.pi/180))
                cairo_show_text (cr, '      '..'other')
                cairo_stroke(cr)
            end
        end
    end
    --[[ END PIE 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)
        air_clock(cr, 90, 90, 200) -- options: xc, yc, size
        cairo_destroy(cr)
        
        cr = cairo_create(cs)
        ring(cr, 'time', '+%S', 60, 0xE3E3E3, 0, 0xFFFF00, 0.7, 90, 90, 70, 4, 0, 360) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
        
        cr = cairo_create(cs)
        ring(cr, 'time', '+%M', 60, 0xE3E3E3, 0.1, 0x00CD00, 0.7, 90, 90, 64, 7, 0, 360) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
        
        cr = cairo_create(cs)
        ring(cr, 'time', '+%H', 24, 0xE3E3E3, 0.2, 0xffffff, 0.7, 90, 90, 53, 14, 0, 360) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
        
        cr = cairo_create(cs)
        ring(cr, 'battery_percent', 'BAT1', 100, 0xFF0000, 0.4, 0xFFFF00, 0, 90, 90, 80, 14, 0, 180) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
        
        cr = cairo_create(cs)
        ring(cr, 'battery_percent', 'BAT1', 100, 0xFF0000, 0.8, 0xFFFF00, 0, 90, 90, 75, 4, 180, 360) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
        
        cr = cairo_create(cs)
        ring(cr, 'battery_percent', 'BAT1', 100, 0xFF0000, 0.8, 0xFFFF00, 0, 90, 90, 86, 2, 180, 360) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
    
        cr = cairo_create(cs)
        ring(cr, 'cpu', 'CPU0', 100, 0xA1A1A1, 0.4, 0xFFFF00, 1, 90, 590, 86, 12, 0, 270) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
        
        cr = cairo_create(cs)
        ring(cr, 'cpu', 'CPU1', 100, 0xA1A1A1, 0.4, 0xCDCD00, 1, 90, 590, 73, 12, 0, 270) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
    
        cr = cairo_create(cs)
        ring(cr, 'memperc', '', 100, 0xA1A1A1, 0.4, 0x708090, 1, 90, 590, 60, 12, 0, 270) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
    
        cr = cairo_create(cs)
        ring(cr, 'battery_percent', 'BAT0', 100, 0xA1A1A1, 0.4, 0xFF8C00, 1, 90, 590, 47, 12, 0, 270) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
    
        cr = cairo_create(cs)
        ring(cr, 'fs_used_perc', '/', 100, 0xA1A1A1, 0.4, 0x008B00, 1, 90, 590, 34, 12, 0, 270) -- options: name, arg, max, bg_colour, bg_alpha, fg_colour, fg_alpha, xc, yc, radius, thickness, start_angle, end_angle
        cairo_destroy(cr)
    
        cr = cairo_create(cs)
        local w = conky_window.width
        local h = conky_window.height
    
        r = 75
        xc = 90
        yc = 360
        
        local updates=conky_parse('${updates}')
        update_num=tonumber(updates)
        
        if update_num>5 then
            pie_rings(xc, yc, r)
        end
    
            cairo_destroy(cr)
    
    end
    Have you Idea?
    Last edited by searchOne; November 24th, 2009 at 09:06 PM.
    64Bit - HP Compaq Presario CQ60-105EG, 4GB RAM, 160GB, NVIDIA GeForce 8200M, AMD Athlon X2 Dual-Core / Mandriva 2009.1, Mandriva 2010, #! Crunchbang 9.04.01 Conky-Hardcore - searchOne

  8. #98
    Join Date
    Feb 2009
    Location
    UK
    Beans
    129
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    ^^^ mem_process isn't an actual variable...Did you mean to write mem_percent?
    - 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 -

  9. #99
    Join Date
    Jul 2009
    Location
    Germany > Hessen > DA
    Beans
    26

    Re: Conky Lua & Cairo Troubleshooting

    oh is it not a mistake?
    Code:
    Conky: llua_do_call: function conky_widgets execution failed: /home/search/conky/lua/widgets/conky_widgets.lua:323: attempt to perform arithmetic on local 'mem_process' (a nil value)
    64Bit - HP Compaq Presario CQ60-105EG, 4GB RAM, 160GB, NVIDIA GeForce 8200M, AMD Athlon X2 Dual-Core / Mandriva 2009.1, Mandriva 2010, #! Crunchbang 9.04.01 Conky-Hardcore - searchOne

  10. #100
    Join Date
    Feb 2009
    Location
    UK
    Beans
    129
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Quote Originally Posted by searchOne View Post
    oh is it not a mistake?
    Code:
    Conky: llua_do_call: function conky_widgets execution failed: /home/search/conky/lua/widgets/conky_widgets.lua:323: attempt to perform arithmetic on local 'mem_process' (a nil value)
    Oh! I didn't see the pie widget in there. D'oh!

    Well, I haven't run that widget myself, but at first glance, it looks like mem_process is returning a nil value (sorry, that's probably obvious). You can error-check it by inserting a line that says:
    Code:
    if mem_process == nil then mem_process = 0 end
    That will at least keep you from getting the error message. But it may still mean that if there's another problem, it will always display zero. Try it and see if that helps.
    - 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 -

Page 10 of 34 FirstFirst ... 8910111220 ... 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
  •