Loading/unloading of procedure files from User Procedures folder
thomas_braun
Just add the desired procedure file in the panel and then load/unload it with one click or CTRL+6 to siwtch the included state.
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
#pragma version=0.1
#pragma igorVersion=6.3
#pragma IndependentModule=IncludeLoader
// Author: thomas aht braun dot byte minus physics dot de
// Feb 2018
static StrConstant panel = "IncludeLoader"
Menu "MyMacros"
"IncludeLoader",/Q, CreatePanel()
"Switch Inluded State/6",/Q, SwitchState()
End
Function CreatePanel()
DoWindow $panel
if(V_Flag)
KillWindow $panel
endif
NewPanel/W=(150,77,350,150)/N=$panel/K=1
Button button0,pos={76,7},size={50,20},proc=$(GetIndependentModuleName() + "#ButtonProcLoadUnload")
SetVariable setvar0,pos={37,38},size={159,16},title="Includes: "
SetVariable setvar0,value= _STR:""
UpdatePanel()
End
static Function/S GetIncludes()
DoWindow $panel
if(!V_Flag)
return ""
endif
ControlInfo/W=$panel setvar0
return S_value
End
static Function isIncludeLoaded()
string includeFiles = GetIncludes()
/// @todo handle properly
string includeFile = StringFromList(0, includeFiles)
string list = WinList(includeFile + ".ipf", ";", "WIN:128")
return ( strlen(list) != 0 )
End
Function SwitchState()
variable i, numItems
string includeFile, includeFiles
includeFiles = GetIncludes()
numItems = ItemsInList(includeFiles)
for(i = 0; i < numItems; i += 1)
includeFile = StringFromList(i, includeFiles)
if(isIncludeLoaded())
Execute/P/Q "DELETEINCLUDE \"" + includeFile + "\""
else
Execute/P/Q "INSERTINCLUDE \"" + includeFile + "\""
endif
endfor
Execute/P/Q/Z "COMPILEPROCEDURES "
// update the panel after loading/unloading the include
Execute/P/Q/Z GetIndependentModuleName() + "#UpdatePanel()"
End
Function ButtonProcLoadUnload(ba) : ButtonControl
STRUCT WMButtonAction &ba
switch(ba.eventCode)
case 2: // mouse up
SwitchState()
break
case -1: // control being killed
break
endswitch
return 0
End
Function UpdatePanel()
if(isIncludeLoaded())
Button button0, win=$panel, title="Unload"
else
Button button0, win=$panel, title="Load"
endif
End
#pragma version=0.1
#pragma igorVersion=6.3
#pragma IndependentModule=IncludeLoader
// Author: thomas aht braun dot byte minus physics dot de
// Feb 2018
static StrConstant panel = "IncludeLoader"
Menu "MyMacros"
"IncludeLoader",/Q, CreatePanel()
"Switch Inluded State/6",/Q, SwitchState()
End
Function CreatePanel()
DoWindow $panel
if(V_Flag)
KillWindow $panel
endif
NewPanel/W=(150,77,350,150)/N=$panel/K=1
Button button0,pos={76,7},size={50,20},proc=$(GetIndependentModuleName() + "#ButtonProcLoadUnload")
SetVariable setvar0,pos={37,38},size={159,16},title="Includes: "
SetVariable setvar0,value= _STR:""
UpdatePanel()
End
static Function/S GetIncludes()
DoWindow $panel
if(!V_Flag)
return ""
endif
ControlInfo/W=$panel setvar0
return S_value
End
static Function isIncludeLoaded()
string includeFiles = GetIncludes()
/// @todo handle properly
string includeFile = StringFromList(0, includeFiles)
string list = WinList(includeFile + ".ipf", ";", "WIN:128")
return ( strlen(list) != 0 )
End
Function SwitchState()
variable i, numItems
string includeFile, includeFiles
includeFiles = GetIncludes()
numItems = ItemsInList(includeFiles)
for(i = 0; i < numItems; i += 1)
includeFile = StringFromList(i, includeFiles)
if(isIncludeLoaded())
Execute/P/Q "DELETEINCLUDE \"" + includeFile + "\""
else
Execute/P/Q "INSERTINCLUDE \"" + includeFile + "\""
endif
endfor
Execute/P/Q/Z "COMPILEPROCEDURES "
// update the panel after loading/unloading the include
Execute/P/Q/Z GetIndependentModuleName() + "#UpdatePanel()"
End
Function ButtonProcLoadUnload(ba) : ButtonControl
STRUCT WMButtonAction &ba
switch(ba.eventCode)
case 2: // mouse up
SwitchState()
break
case -1: // control being killed
break
endswitch
return 0
End
Function UpdatePanel()
if(isIncludeLoaded())
Button button0, win=$panel, title="Unload"
else
Button button0, win=$panel, title="Load"
endif
End
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
Here is a slightly different version that uses listboxes to select files to be loaded or unloaded, and populates these with the names of available procedure files. Since this should be run as an independent module, the code must sit in its own procedure window. I've attached a procedure file.
-- edited to remove attachment. more recent version of procedure loader is here.
July 23, 2018 at 08:45 am - Permalink