Using Hooks in Independent Modules
| aclight | April 1, 2008 - 16:33 | ||
|---|---|---|---|
|
I could be wrong here, but I think your problem is that if you declare a function as static, you need to include a #pragma ModuleName = mn type directive in that procedure file. That's the middle name of the triple name syntax. If you have a function in an independent module but it's not a static function, you don't need the middle name. 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 IndependentModule=MyModule #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. |
|||
| jjweimer | April 2, 2008 - 08:26 | ||
|---|---|---|---|
|
I could be wrong here, but I think your problem is that if you declare a function as static, you need to include a #pragma ModuleName = mn type directive in that procedure file. ...
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: Function TestMe() 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. 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. 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) I'm not sure if you can use functions in independent modules with SetIgorHook, ...
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. -- [ last edited April 14, 2008 - 07:56 ]
|
|||

Joined: 2007-08-14
Location: United States
I have a question about using a Menu Hook Function in an Independent Modules. The following options do not work for me:
Neither does the following direct setup:
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?
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH