Using Hooks in Independent Modules
jjweimer
#pragma IndependentModule=MyModule
SetIgorHook IgorMenuHook=TestTheMenu // does not work with this line
SetIgorHook IgorMenuHook=MyModule#TestTheMenu // does not work with this line
SetIgorHook IgorMenuHook=MyModule#MyModule#TestTheMenu // does not work with this line
Static Function TestTheMenu(...)
...
end
SetIgorHook IgorMenuHook=TestTheMenu // does not work with this line
SetIgorHook IgorMenuHook=MyModule#TestTheMenu // does not work with this line
SetIgorHook IgorMenuHook=MyModule#MyModule#TestTheMenu // does not work with this line
Static Function TestTheMenu(...)
...
end
Neither does the following direct setup:
#pragma IndependentModule=MyModule
Function IgorMenuHook(...)
...
end
Function IgorMenuHook(...)
...
end
Is this a limitation of Independent Modules, a my misunderstanding of the text on page IV-41 of the manual ...
However, if need be, you can call static functions in the independent module from outside the group using a triple name syntax:
imName#modName#functionName()
... or a limitation of Independent Modules AND IgorMenuHook functions?
BTW, I am still generally confused about the first two names in the triple name sequence imName#modName#functionName. What is the modName of an Independent Module?
I'm not sure if you can use functions in independent modules with SetIgorHook, but if you can, your first example would probably look like this:
#pragma ModuleName=foo
SetIgorHook IgorMenuHook=MyModule#foo#TestTheMenu // does not work with this line
Static Function TestTheMenu(...)
...
end
With independent modules, I don't think that you need to use static functions in most cases, since the function name space of the independent module is separate from other functions that are in other independent modules or not in independent modules at all.
April 1, 2008 at 03:33 pm - Permalink
After further tests I found, if you use a Static function, AND you want to access it from outside the procedure file, then you MUST use a ModuleName pragma. Try the following in the procedure window:
print "Hello World!"
testyou()
return 0
end
Static Function TestYou()
print "Hello Universe!"
return 0
end
Executing testme() on the command line works to print "Hello World!" and "Hello Universe!", however testyou() is inaccessible at the command line level. Putting this code into a Procedure window with a ModuleName=Tester pragma makes Tester#TestYou() accessible and keeps the simple call TestMe() still accessible.
So, with regard to naming functions to avoid conflicts ...
1) In any type of procedure file, the names of Static functions are always local.
2) When a procedure file or files have a ModuleName pragma, the names of Non-Static functions are still global.
3) When a procedure file or files have an IndependentModule pragma, the names of all functions are local.
When a function name is global, you should use a unique name (ie, GXY_Create(...) rather than Create(...)) to avoid potential conflicts with a (global) function using the same name in a different procedure file. When a function name is local, you can use any name you want.
Also, with regard to interactions of ModuleName and IndependentModule pragmas with Static or Non-Static functions ...
1) When a procedure file or files have a ModuleName pragma, you access Static functions from outside the module using the ModuleName#FunctionName(...) syntax.
2) When a procedure file or files have an IndependentModule pragma, you access any function from outside the independent module using the IndependentModuleName#FunctionName(...) syntax.
3) When a procedure file or files have both a ModuleName and an IndependentModule pragma, you access Non-Static functions from outside the module using the IndependentModuleName#FunctionName(...) syntax.
4) When a procedure file or files have both a ModuleName and an IndependentModule pragma, you access Static functions from outside the module using the IndependentModuleName#ModuleName#FunctionName(...) syntax.
Remember, when you design controls on control panels, their procedure files run as though they were called from outside the procedure file. Therefore, you must use the corresponding IndependentModuleName#FunctionName, ModuleName#FunctionName, or IndependentModuleName#ModuleName#FunctionName syntax.
(Just thought I would be expansive for the sake of anyone reading this who is new to Igor programming)
My tests show, you CANNOT use IgorMenuHook(...) from within an IndependentModule. Apparently, it is never called.
Perhaps, short of breaking the procedure file into two pieces (Regular with the IgorMenuHook(...) function and IndependentModule with everything else), someone has a suggestion on how to have an IgorMenuHook(...) function recognized when it is within a procedure that is an IndependentModule.
Alternatively, the inaccessibility of Igor hook functions might be a fifth Limitations of Independent Modules to add to page IV-41 of the manual.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
April 14, 2008 at 06:56 am - Permalink
Jim Prouty
WaveMetrics, Inc.
April 15, 2008 at 02:53 pm - Permalink
April 30, 2012 at 02:20 pm - Permalink
April 30, 2012 at 02:25 pm - Permalink
April 30, 2012 at 03:54 pm - Permalink
--Jim Prouty
Software Engineer, WaveMetrics, Inc. Post the code, including #pragmas here (along with the version of Igor and the version of the operating system), and maybe we can figure it out from that.
May 1, 2012 at 08:51 am - Permalink
setIgorHook igorMenuHook = #
Simply calling the hook function igorMenuHook and placing it in an independent module doesn't work, even though it does work from ProcGlobal.
May 1, 2012 at 09:28 am - Permalink
#pragma IndependentModule= MyModule
Function AfterCompiledHook()
print "here AfterCompiledHook"
return 0
End
While it will fire when preceded by "Static":
#pragma IndependentModule= MyModule
Static Function AfterCompiledHook()
print "here AfterCompiledHook"
return 0
End
May 5, 2012 at 04:50 pm - Permalink
Hmmm .... ? I wonder how this fits in the context of this thread?
http://www.igorexchange.com/node/1688
Seems as though some concrete examples would be helpful.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
May 4, 2012 at 09:09 am - Permalink