Page 18 of 34 FirstFirst ... 8161718192028 ... LastLast
Results 171 to 180 of 334

Thread: Conky Lua & Cairo Troubleshooting

  1. #171
    Join Date
    Aug 2009
    Location
    East of Atlantic
    Beans
    81
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Quote Originally Posted by mrpeachy View Post

    re the blur... no luck yet, or at least nothing I know how to implement.

    i was thinking along the line of seeing if you can export the data from cairo to imlib2...
    you can use imlib2 to apply a blur filter to an image... or even export the cairo data to an image file and then display and blur the image with imlib2

    but i havn't found out how to do that yet
    Hi MrPeachy !
    To export data from cairo to imlib, I think you have to export cairo to a png file and import png in imlib.
    Look at theses functions in lua :
    Code:
    cairo_surface_write_to_png()
    imlib_load_image()
    Maybe there is another way, but at least it works, I used this method for my "calendar wheel" script if you 're looking for an example, it's here.

    But how do you blur an image with imlib ??

    Thanks

  2. #172
    Join Date
    Oct 2009
    Location
    Under a rock
    Beans
    Hidden!

    Re: Conky Lua & Cairo Troubleshooting

    I thought I had read about a blur filter with imlib2... but maybe it was something else:
    heres one place that mentions it:

    http://asbradbury.org/projects/lua-imlib2/doc/
    search for blur... says
    img:blur(radius)

    Blurs the image. A radious value of 0 has no effect. 1 and above determine the blur matrix radius that determines how much to blur the image.

    but now im not sure that this might require the lua-imlib2 package created by the author.

    Or you could do your own "blur" effect, by calling multiple instances of the same image, altering their alpha value and overlaying them with slightly altered positions like this:

    goes to

    or another way to achieve a blur like effect would be to scale the image down, save it and then scale it back up again like this:

    not as nice but quick and easy.

    i havnt used imlib2 so i dont know if it can do the above either
    Last edited by mrpeachy; February 13th, 2010 at 01:02 AM.

  3. #173
    Join Date
    Aug 2009
    Location
    East of Atlantic
    Beans
    81
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Hi all,

    I need some advice for calling C code in a Lua script.

    I am back with my attempt to draw an audio equalizer widget with conky (does this already exist ?)
    This work is based on this widget (Impulse) for gnome : https://launchpad.net/impulse.bzr

    So, if I can't get something faster, I will post the code here.

    Actually the Lua script call a python script which call the Impulse.so file.

    So I think Lua should call directly the Impulse.so file but I have no skills in C and it's where problems begin ! First I read this tuto

    The conky is :
    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
    own_window_title with lua
    
    border_inner_margin 0
    border_outer_margin 0
    
    minimum_size 200 300
    
    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=12
    xftalpha 0.8
    
    uppercase no
    
    default_color FFFFFF
    
    
    # -- Lua Load -- #
    # SET THE PATH TO THE SCRIPT HERE
    lua_load ~/scripts/equa1.1c/equalizer.lua
    lua_draw_hook_pre main3
    
    TEXT
    with lua
    cpu0 ${cpu cpu0}
    cpu1 ${cpu cpu1}
    update=0.1
    mem ${mem}
    up. ${updates}
    The Lua code to load the Impulse.so is :

    Code:
    require 'cairo'
    function conky_main3()
    
        package.cpath = "./?.so"
        require "Impulse"
        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)
    
        cairo_destroy(cr)
        cairo_surface_destroy(cs)
            
    end
    After installing the packages libfftw3 and libpulsedev
    I modified the Impulse.c file at the beginning :

    Code:
    /*
     *
     *+  Copyright (c) 2009 Ian Halpern
     *@  http://impulse.ian-halpern.com
     *
     *   This file is part of Impulse.
     *
     *   Impulse is free software: you can redistribute it and/or modify
     *   it under the terms of the GNU General Public License as published by
     *   the Free Software Foundation, either version 3 of the License, or
     *   (at your option) any later version.
     *
     *   Impulse is distributed in the hope that it will be useful,
     *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *   GNU General Public License for more details.
     *
     *   You should have received a copy of the GNU General Public License
     *   along with Impulse.  If not, see <http://www.gnu.org/licenses/>.
     */
    /* 
    wlourf 16.02.2010
    added the 4 first lines
    install libfftw3 libpulsedev package
    */
    
    #include "lua/lua.h"
    #include "lua/lualib.h"
    #include "lua/lauxlib.h"
    #include "stdio.h"
    
    #include <pulse/pulseaudio.h>
    #include <assert.h>
    #include <string.h>
    #include <fftw3.h>
    #include <math.h>
    
    #define CHUNK 1024
    
    static const long fft_max[] = { 12317168L, 7693595L, 5863615L, 4082974L, 5836037L, 4550263L, 3377914L, 3085778L, 3636534L, 3751823L, 2660548L, 3313252L, 2698853L, 2186441L, 1697466L, 1960070L, 1286950L, 1252382L, 1313726L, 1140443L, 1345589L, 1269153L, 897605L, 900408L, 892528L, 587972L, 662925L, 668177L, 686784L, 656330L, 1580286L, 785491L, 761213L, 730185L, 851753L, 927848L, 891221L, 634291L, 833909L, 646617L, 804409L, 1015627L, 671714L, 813811L, 689614L, 727079L, 853936L, 819333L, 679111L, 730295L, 836287L, 1602396L, 990827L, 773609L, 733606L, 638993L, 604530L, 573002L, 634570L, 1015040L, 679452L, 672091L, 880370L, 1140558L, 1593324L, 686787L, 781368L, 605261L, 1190262L, 525205L, 393080L, 409546L, 436431L, 723744L, 765299L, 393927L, 322105L, 478074L, 458596L, 512763L, 381303L, 671156L, 1177206L, 476813L, 366285L, 436008L, 361763L, 252316L, 204433L, 291331L, 296950L, 329226L, 319209L, 258334L, 388701L, 543025L, 396709L, 296099L, 190213L, 167976L, 138928L, 116720L, 163538L, 331761L, 133932L, 187456L, 530630L, 131474L, 84888L, 82081L, 122379L, 82914L, 75510L, 62669L, 73492L, 68775L, 57121L, 94098L, 68262L, 68307L, 48801L, 46864L, 61480L, 46607L, 45974L, 45819L, 45306L, 45110L, 45175L, 44969L, 44615L, 44440L, 44066L, 43600L, 57117L, 43332L, 59980L, 55319L, 54385L, 81768L, 51165L, 54785L, 73248L, 52494L, 57252L, 61869L, 65900L, 75893L, 65152L, 108009L, 421578L, 152611L, 135307L, 254745L, 132834L, 169101L, 137571L, 141159L, 142151L, 211389L, 267869L, 367730L, 256726L, 185238L, 251197L, 204304L, 284443L, 258223L, 158730L, 228565L, 375950L, 294535L, 288708L, 351054L, 694353L, 477275L, 270576L, 426544L, 362456L, 441219L, 313264L, 300050L, 421051L, 414769L, 244296L, 292822L, 262203L, 418025L, 579471L, 418584L, 419449L, 405345L, 739170L, 488163L, 376361L, 339649L, 313814L, 430849L, 275287L, 382918L, 297214L, 286238L, 367684L, 303578L, 516246L, 654782L, 353370L, 417745L, 392892L, 418934L, 475608L, 284765L, 260639L, 288961L, 301438L, 301305L, 329190L, 252484L, 272364L, 261562L, 208419L, 203045L, 229716L, 191240L, 328251L, 267655L, 322116L, 509542L, 498288L, 341654L, 346341L, 451042L, 452194L, 467716L, 447635L, 644331L, 1231811L, 1181923L, 1043922L, 681166L, 1078456L, 1088757L, 1221378L, 1358397L, 1817252L, 1255182L, 1410357L, 2264454L, 1880361L, 1630934L, 1147988L, 1919954L, 1624734L, 1373554L, 1865118L, 2431931L };
    
    static int16_t buffer[ CHUNK / 2 ], snapshot[ CHUNK / 2 ];
    static size_t buffer_index = 0;
    
    static pa_context *context = NULL;
    static pa_stream *stream = NULL;
    static pa_threaded_mainloop* mainloop = NULL;
    static pa_io_event* stdio_event = NULL;
    static pa_mainloop_api *mainloop_api = NULL;
    static char *stream_name = NULL, *client_name = NULL, *device = NULL;
    
    static pa_sample_spec sample_spec = {
        .format = PA_SAMPLE_S16LE,
        .rate = 44100,
        .channels = 2
    };
    
    static pa_stream_flags_t flags = 0;
    
    static pa_channel_map channel_map;
    static int channel_map_set = 0;
    
    
    /* A shortcut for terminating the application */
    static void quit( int ret ) {
        assert( mainloop_api );
        mainloop_api->quit( mainloop_api, ret );
    }
    
    static void get_source_info_callback( pa_context *c, const pa_source_info *i, int is_last, void *userdata ) {
    
        if ( is_last || device != NULL )
            return;
    
        assert(i);
    
        // snprintf(t, sizeof(t), "%u", i->monitor_of_sink);
    
        if ( i->monitor_of_sink != PA_INVALID_INDEX ) {
    
            device = pa_xstrdup( i->name );
    
            if ( ( pa_stream_connect_record( stream, device, NULL, flags ) ) < 0 ) {
                fprintf(stderr, "pa_stream_connect_record() failed: %s\n", pa_strerror(pa_context_errno(c)));
                quit(1);
            }
        }
    }
    
    /* This is called whenever new data may is available */
    static void stream_read_callback(pa_stream *s, size_t length, void *userdata) {
        const void *data;
        assert(s);
        assert(length > 0);
    
        if (stdio_event)
            mainloop_api->io_enable(stdio_event, PA_IO_EVENT_OUTPUT);
    
        if (pa_stream_peek(s, &data, &length) < 0) {
            fprintf(stderr, "pa_stream_peek() failed: %s\n", pa_strerror(pa_context_errno(context)));
            quit(1);
            return;
        }
    
        assert(data);
        assert(length > 0);
    
        int excess = buffer_index * 2 + length - ( CHUNK );
    
        if ( excess < 0 ) excess = 0;
    
        memcpy( buffer + buffer_index, data, length - excess );
        buffer_index += ( length - excess ) / 2;
    
        if ( excess ) {
            memcpy( snapshot, buffer, buffer_index * 2 );
            buffer_index = 0;
        }
    
        pa_stream_drop(s);
    }
    
    
    static void context_state_callback(pa_context *c, void *userdata) {
    
        switch (pa_context_get_state(c)) {
            case PA_CONTEXT_CONNECTING:
            case PA_CONTEXT_AUTHORIZING:
            case PA_CONTEXT_SETTING_NAME:
                break;
            case PA_CONTEXT_READY:
                assert(c);
                assert(!stream);
    
                if (!(stream = pa_stream_new(c, stream_name, &sample_spec, channel_map_set ? &channel_map : NULL))) {
                    fprintf(stderr, "pa_stream_new() failed: %s\n", pa_strerror(pa_context_errno(c)));
                    quit(1);
                }
    
                pa_stream_set_read_callback(stream, stream_read_callback, NULL);
    
                pa_operation_unref( pa_context_get_source_info_list( c, get_source_info_callback, NULL ) );
    
                break;
            case PA_CONTEXT_TERMINATED:
                quit(0);
                break;
    
            case PA_CONTEXT_FAILED:
            default:
                fprintf(stderr, "Connection failure: %s\n", pa_strerror(pa_context_errno(c)));
                quit(1);
        }
    }
    
    void im_stop (void) {
    
        pa_threaded_mainloop_stop( mainloop );
    
        //printf( "exit\n" );
    }
    
    double *im_getSnapshot( int fft ) {
    
        static double magnitude[ CHUNK / 4 ];
    
        if ( ! fft ) {
            int i;
            for ( i = 0; i < CHUNK / 2; i += sample_spec.channels ) {
                magnitude[ i / sample_spec.channels ] = 0;
                int j;
                for ( j = 0; j < sample_spec.channels; j++ )
                    magnitude[ i / sample_spec.channels ] += fabs( ( (double) snapshot[ i + j ] / ( pow( 2, 16 ) / 2 ) ) / sample_spec.channels );
            }
        } else {
    
            double *in;
            fftw_complex *out;
            fftw_plan p;
    
            in = (double*) malloc( sizeof( double ) * ( CHUNK / 2 ) );
            out = (fftw_complex*) fftw_malloc( sizeof( fftw_complex ) * ( CHUNK / 2 ) );
    
            if ( snapshot != NULL ) {
                int i;
                for ( i = 0; i < CHUNK / 2; i++ ) {
                    in[ i ] = (double) snapshot[ i ];
                }
            }
    
            p = fftw_plan_dft_r2c_1d( CHUNK / 2, in, out, 0 );
    
            fftw_execute( p );
    
            fftw_destroy_plan( p );
    
            if ( out != NULL ) {
                int i;
                for ( i = 0; i < CHUNK / 2 / sample_spec.channels; i++ ) {
                    magnitude[ i ] = (double) sqrt( pow( out[ i ][ 0 ], 2 ) + pow( out[ i ][ 1 ], 2 ) ) / (double) fft_max[ i ];
                    if ( magnitude[ i ] > 1.0 ) magnitude[ i ] = 1.0;
                }
            }
    
            free( in );
            fftw_free(out);
        }
    
        return magnitude; // PyString_FromStringAndSize( (char *) snapshot, CHUNK );
    }
    
    
    void im_start ( void ) {
    
        // Pulseaudio
        int r;
        char *server = NULL;
    
        client_name = pa_xstrdup( "cimpulse" );
        stream_name = pa_xstrdup( "cimpulse" );
    
        // Set up a new main loop
    
        if ( ! ( mainloop = pa_threaded_mainloop_new( ) ) ) {
            fprintf( stderr, "pa_mainloop_new() failed.\n" );
            return;
        }
    
        mainloop_api = pa_threaded_mainloop_get_api( mainloop );
    
        r = pa_signal_init( mainloop_api );
        assert( r == 0 );
    
        /*if (!(stdio_event = mainloop_api->io_new(mainloop_api,
                                                 STDOUT_FILENO,
                                                 PA_IO_EVENT_OUTPUT,
                                                 stdout_callback, NULL))) {
            fprintf(stderr, "io_new() failed.\n");
            goto quit;
        }
        
        // create a new connection context
        if ( ! ( context = pa_context_new( mainloop_api, client_name ) ) ) {
            fprintf( stderr, "pa_context_new() failed.\n" );
            return;
        }
    
        pa_context_set_state_callback( context, context_state_callback, NULL );
    
        /* Connect the context */
        pa_context_connect( context, server, 0, NULL );
    
        // pulseaudio thread
        pa_threaded_mainloop_start( mainloop );
    
        return;
    }
    and I compiled the impulse.c with this command :
    Code:
    gcc -o Impulse.so -shared Impulse.c
    whitout errors

    BUT, when I run my conky
    Code:
    conky -c conkyrc
    I get this error :

    Conky: llua_do_call: function conky_main3 execution failed: error loading module 'Impulse' from file './Impulse.so':
    ./Impulse.so: undefined symbol: pa_xstrdup

    all pulseaudio variables are not recognized !

    So, as I don't know nothing in C, what do you think about this error ?

    Thanks!
    Attached Images Attached Images
    Last edited by wlourf; February 28th, 2010 at 09:51 PM.

  4. #174
    Join Date
    Jul 2007
    Beans
    2

    Re: Conky Lua & Cairo Troubleshooting

    Wlourf,

    As the creator of Impulse let me explain the source structure. impulse.so is the python bindings for the libimpulse.so library. Impulse.h, Impulse.c are the source code files for libimpulse.so, not impulse.so. The source code for impulse.so is impulsemodule.c. impulse.so uses the library libimpulse.so. You should not add any Lua code to Impulse.h or Impulse.c. Instead you should create a new file and follow the structure of impulsemodule.c to create a lua version using the lua c api, like the link you sent me here http://www.wellho.net/mouth/1844_Cal...rst-HowTo.html.

    To build libimpulse.so use something like the following:
    Code:
    gcc -pthread -Wall -fPIC -c Impulse.c -o libimpulse.o
    gcc -pthread -lpulse -lfftw3 -shared -Wl,-soname,libimpulse.so -fPIC libimpulse.o -o libimpulse.so
    rm *.o
    To build impulse.so (the python bindings) use something like the following:
    Code:
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c impulsemodule.c -o impulse.o
    gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -L. -limpulse -Wl,-rpath,. impulse.o -o impulse.so
    rm *.o
    *Note: -Wl,-rpath,. just allows for the dynamic linker to search for libraries in the current local path. You can also just move libimpulse.so to /usr/lib and remove -Wl,-rpath,. from the build command.

    I hope this helps as a jumping off point.

  5. #175
    Join Date
    Aug 2009
    Location
    East of Atlantic
    Beans
    81
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Thanks Ian,
    That seems to be toooooooo complicated for me actually ...
    I will return to my little drawnings and stay with the python stuff for the moment !


    Edit 28 Feb 2010 :
    With the help of Ian, I made a nice conky for his Impulse library, it's on this post.
    Last edited by wlourf; February 28th, 2010 at 09:52 PM.

  6. #176
    Join Date
    Nov 2009
    Location
    Sankt-Petersburg, Russia
    Beans
    4
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Conky Lua & Cairo Troubleshooting

    Hello everyone

    I olgmen from Russia

    Sorry for the mistakes, I do not know much English language and writing with an electronic translator.

    I wrote a small script printed to the window conky expanding inscription MAIL. But I do not know how to connect the test mail. If a script to insert checks with conkyEmail, it is continuous, constant checking email

    Text of script

    Code:
    --[[ Conky Widgets by olgmen (2010)
    
    This widget displays the window conky expanding inscription MAIL!!!
    
    lua_load ~/scripts/text_mail.lua
    lua_draw_hook_pre widgets
    
    ]]
    
    
    require 'cairo'
    
    function text()
    
            local x = 0
            local y = 200
            local w=conky_window.width
            local h = 50
    
            local extents = cairo_text_extents_t:create()
    -- назначаем шрифт
    
            cairo_select_font_face(cr, "PT Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD)
    
    -- font size
    
            size = 10
    
            alpha = 0.6
    
            local updates=conky_parse('${updates}')
    
            if updates == nil then updates = 0 end
    
                update_num=tonumber(updates)
    
                    if (update_num % 6 == 0) then
                    
                        if updates_num == nil then updates_num = 0 end
    
                        reset_num=update_num
            
                    end
    
                    if (reset_num >0)then
    
                        timer_num=update_num-reset_num
    
                        cairo_set_font_size(cr, size*timer_num)
                        cairo_text_extents(cr, "MAIL !!!", extents)
                        cairo_set_source_rgba(cr, 1, 0, 0, alpha+timer_num/10)
                        cairo_move_to(cr, x + w/2 - extents.x_advance/2, y + 0.5*h - extents.y_bearing/2)
                        cairo_show_text(cr, "MAIL !!!")
    
                    end
    end
    
        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)
        text()
        cairo_destroy (cr)
    
    end
    how to make check-mail

    Thank
    and good day

  7. #177
    Join Date
    Aug 2009
    Location
    East of Atlantic
    Beans
    81
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Quote Originally Posted by olgmen View Post
    how to make check-mail

    Thank
    and good day
    hello olgmen, I don't use this function but did you try fetchmail , the documentation says :
    mails (mailbox) (interval) Mail count in the specified mailbox or your mail spool if not. Both mbox and maildir type mailboxes are supported. You can use a program like fetchmail to get mails from some server using your favourite protocol. See also new_mails.
    aybe this like is more sure (conkyEmail) : http://conky.linux-hardcore.com/?page_id=846
    Last edited by wlourf; March 2nd, 2010 at 12:55 AM.

  8. #178
    Join Date
    Aug 2009
    Location
    East of Atlantic
    Beans
    81
    Distro
    Ubuntu

    Re: Conky Lua & Cairo Troubleshooting

    Hi!

    When we call a conkyrc with an alsolute path like this :
    Code:
    conky -c /home/wlourf/scripts/conkyrc
    How can we get the path of the conky, or the path of a Lua script called by the conky.
    It's for the audio analyser widget, it works fine when it is called from conkyrc's path but not when called from an another path because the Lua runs python like this :
    Code:
    impulse_pipe = io.popen('python impulse.py ' .. fft , "r")
    and doesn't find impulse.py

    Thanks

  9. #179
    Join Date
    Jan 2007
    Beans
    Hidden!

    Re: Conky Lua & Cairo Troubleshooting

    Quote Originally Posted by wlourf View Post
    Hi!

    When we call a conkyrc with an alsolute path like this :
    Code:
    conky -c /home/wlourf/scripts/conkyrc
    How can we get the path of the conky, or the path of a Lua script called by the conky.
    It's for the audio analyser widget, it works fine when it is called from conkyrc's path but not when called from an another path because the Lua runs python like this :
    Code:
    impulse_pipe = io.popen('python impulse.py ' .. fft , "r")
    and doesn't find impulse.py

    Thanks


    I don't know the proper way but I do know some improper way

    First of all, there is some better way to call external command (I found it durring "lua wait command" search):
    Code:
    function os.capture(cmd, raw)
    	local f = assert(io.popen(cmd, 'r'))
    	local s = assert(f:read('*a'))
    	f:close()
    	if raw then return s end
    	s = string.gsub(s, '^%s+', '')
    	s = string.gsub(s, '%s+$', '')
    	s = string.gsub(s, '[\n\r]+', ' ')
    	return s
    end


    and then, the improper way - test it:

    conkyrc
    Code:
    background no
    update_interval 1
    total_run_times 1
    own_window yes
    own_window_type override
    own_window_transparent yes
    own_window_colour black
    own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
    double_buffer yes
    minimum_size 0 0
    maximum_width 0
    imlib_cache_size 0
    lua_load $HOME/.conky/lua/test04.lua
    lua_draw_hook_pre conky_main
    TEXT
    test04.lua
    Code:
    do
    
    function os.capture(cmd, raw)
    	local f = assert(io.popen(cmd, 'r'))
    	local s = assert(f:read('*a'))
    	f:close()
    	if raw then return s end
    	s = string.gsub(s, '^%s+', '')
    	s = string.gsub(s, '%s+$', '')
    	s = string.gsub(s, '[\n\r]+', ' ')
    	return s
    end
    
    lua_script_dir = os.capture('find ~ -depth -mount -nowarn -name test04.lua -type f -print -quit 2>/dev/null |awk -F"/" \'{gsub($NF,"");print}\'')
    
    impulse_command = os.capture('find ~ -depth -mount -nowarn -name impulse.py -type f -print -quit 2>/dev/null')
    
    fft = 'you must define it here'
    
    function conky_main()
    	impulse_pipe = os.capture('python ' .. impulse_command .. ' ' .. fft)
    	print (lua_script_dir)
    	print (impulse_pipe)
    end
    
    end
    Last edited by dk75; March 3rd, 2010 at 06:47 PM.
    Linux Debian Sid (Minted) x86_64/3.12.10, Conky 2.0_pre, Xorg 7.7/1.15.0, KDE 4.11.5, Lenovo T61, Intel X3100, HITACHI HTS722010K9SA00 100GB, WDC_WD5000BEVT 500GB
    Linux user No.: 483055 | My Conky Pitstop corner | One4All project

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

    Re: Conky Lua & Cairo Troubleshooting

    Quote Originally Posted by dk75 View Post
    I don't know the proper way but I do know some improper way

    First of all, there is some better way to call external command (I found it durring "lua wait command" search):
    Code:
    function os.capture(cmd, raw)
        local f = assert(io.popen(cmd, 'r'))
        local s = assert(f:read('*a'))
        f:close()
        if raw then return s end
        s = string.gsub(s, '^%s+', '')
        s = string.gsub(s, '%s+$', '')
        s = string.gsub(s, '[\n\r]+', ' ')
        return s
    end
    and then, the improper way - test it:

    conkyrc
    Code:
    background no
    update_interval 1
    total_run_times 1
    own_window yes
    own_window_type override
    own_window_transparent yes
    own_window_colour black
    own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
    double_buffer yes
    minimum_size 0 0
    maximum_width 0
    imlib_cache_size 0
    lua_load $HOME/.conky/lua/test04.lua
    lua_draw_hook_pre conky_main
    TEXT
    test04.lua
    Code:
    do
    
    function os.capture(cmd, raw)
        local f = assert(io.popen(cmd, 'r'))
        local s = assert(f:read('*a'))
        f:close()
        if raw then return s end
        s = string.gsub(s, '^%s+', '')
        s = string.gsub(s, '%s+$', '')
        s = string.gsub(s, '[\n\r]+', ' ')
        return s
    end
    
    lua_script_dir = os.capture('find ~ -depth -mount -nowarn -name test04.lua -type f -print -quit 2>/dev/null |awk -F"/" \'{gsub($NF,"");print}\'')
    
    impulse_command = os.capture('find ~ -depth -mount -nowarn -name impulse.py -type f -print -quit 2>/dev/null')
    
    fft = 'you must define it here'
    
    function conky_main()
        impulse_pipe = os.capture('python ' .. impulse_command .. ' ' .. fft)
        print (lua_script_dir)
        print (impulse_pipe)
    end
    
    end
    Hmmpf, that's nice ! I finally found another (proper?) way to find the script's path using conky_config from Lua API, and I didn't managed to get the path with your script
    Code:
    function conky_main()
    
        local s=conky_config
        local pos=(s:reverse(s)):find("/")
        if pos==nil then pos=0 end
        
        lua_script_dir= s:sub(1 ,#s-pos+1)
        print (lua_script_dir)
        fft = 1
        if impulse_pipe == nil then
            --impulse_pipe = io.popen('python ' .. lua_script_dir .. 'impulse.py ' .. fft , "r")
            impulse_pipe = os.capture('python ' .. lua_script_dir .. 'impulse.py ' .. ' ' .. fft)
        end 
        
    end
    Anyway, it works BUT not, it doesn't work!

    Impulse.py is called, yes, but the python script needs to load the 'impulse' shared library with
    Code:
    import impulse
    but doesn't find it because it's not in the PATH.
    I can pass the path to impulse to python with an argument but after I didn't find a way to load the shared library.
    I tried that for example :
    Code:
    imp.load_dynamic('impulse', os.path.join(sys.argv[2], 'impulse.so'))
    but without success, so if you have some ideas again, it will be nice !

Page 18 of 34 FirstFirst ... 8161718192028 ... 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
  •