Persistent error in dynamic contextual menu that disables normal menus

 

Hello.  I have been encountering a troublesome error (Igor 7 on the Mac), and I hope somebody might have a suggestion how to avoid it.  I am using a PopupContextualMenu, with the /N option to reference a menu definition.  That menu references a function to return a list of options.  The error comes in that function.  It seems that even though the menu hasn’t been invoked, the function gets executed after compilation and whenever the main Igor menus are selected.  So any error in the function’s execution throws up an error, and it prevents all use of the regular menus.  I can deal with this during development, but now I want to distribute the code, and I find this error prevents doing anything as soon as the procedure file is #included in a new experiment.  Most importantly, the user can't even execute the initialization function that would resolve the error.

 A simple example that reproduces the behavior is below.  In this case "w_List" doesn't exist yet, so myTextFn throws up an error, and I can't call my initFn from the Macros menu.  Has anyone any suggestions how to disable invoking that function to avoid triggering these errors.  Thanks in advance.

-Matthew

menu "Macros"
    "initFn"
end

function initFn ()
    make /t w_List
end

menu "mymenu", contextualmenu, dynamic
    mytextfn ()
end

function /t mytextfn ()
    wave /t w_List
    string mystr
    wfprintf mystr, "%s;" w_List
    return mystr
end

 

A follow-up:  I tried solving this by hiding the guts of myTextFn() behind a conditional compiler directive ("#if (exists ("w_List"))").  That does indeed prevent the error upon startup, and I can call the initFn from the Macros menu.  However, now the contextual menu reports "a string expression was expected" when it is invoked, and calls to myTextFn() from the command line do not return anything.

My guess is that after initFn is run, I need to force recompilation, so that the compiler directive can be satisfied.  I can do that by editting the procedure which forces a recompilation, but I would rather not have this be a necessary step for my lab minions.  Out of the frying pan...

So, I guess I'm still in search of a solution, if anyone has a suggestion.

menu "Macros"
    "initFn"
end

function initFn ()
    make/O/t w_List
end

menu "mymenu", contextualmenu, dynamic
    mytextfn ()
end

function /t mytextfn ()
    string mystr="(no items"
    wave /t/z w_List
    if( WaveExists(w_List) )
        wfprintf mystr, "%s;" w_List
    endif
    return mystr
end

Perhaps this will help.

Ah, the /Z flag!  I didn't know Wave had that too.  It is so useful, even though it feels like cheating.  Thanks!

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More