Getting wave reference from WaveSelector Widget?

Probably a question that's very easy to answer. I'm making a panel that allows me to run a function I wrote from it instead of using the command line. I have a decent handle on setting up buttons, checkboxes, and Set Variable controls and I've been using them to set up the panel succesfuly so far. It's the first time that I'm trying to use the waveSelectorWidget so I looked at the WaveSelectorWidgetExample.pxp file to try to implement it. I was able to get the WaveSelectorPopUp functionality working onto my panel (i.e. I can click on the button, get the dropdown menu with the different folders, and browse through the data folders to look for and select the wave I want, [picture attached]) however, I'm unsure as to how reference the wave I have selected with the widget.

One of the procedures included in the example "DemoPopupWaveSelectorNotify" , takes the path to the currently selected wave as input and prints it out into the console. I also noticed that the help text associated with the button is also set to the path to the wave which is exactly what I need but I'm unsure as to how to get that.

Any suggestions?

Function panel()
   DoWindow ClusteringAlgorithm
   if(!V_Flag)
        NewPanel/N=ClusteringAlgorithm/W=(50,0,750,700)
        Button PopupWaveSelectorB1,pos={527,544},size={150,20},title="Select A Wave"
        MakeButtonIntoWSPopupButton("ClusteringAlgorithm", "PopupWaveSelectorB1", "DemoPopupWaveSelectorNotify", options=PopupWS_OptionFloat)
        TitleBox WSPopupTitle1,pos={394,544},size={94,20},title="Button, selection as title:"
        TitleBox WSPopupTitle1,frame=0
   endif
End

Thanks!

Wave Selector Popup works

If you have a string containing a full path to a wave, you can easily get a wave reference like this:

Wave selectedWave = $StringWithWavePath

You can read more about this: DisplayHelpTopic "Accessing Global Variables And Waves"

Especially read the subsection "Runtime Lookup of Globals", but don't stop there!

In reply to by johnweeks

Hi John,

I know about obtaining/using wave references that way. I guess I should've been more clear. What I'm unsure about is what $StringWithWavePath would be in WaveSelectorWidgetExample.ipf . I see that the wavepath is passed as an input in this function presented in the example but I'm unsure how to retrieve that value.

Function DemoPopupWaveSelectorNotify(event, wavepath, windowName, ctrlName)
	Variable event
	String wavepath
	String windowName
	String ctrlName
	
	print "Selected wave:",wavepath, " using control", ctrlName
end

I also think that the wavepath is given by the String str in this function but I'm unsure how to retrieve it:

Function MakeButtonIntoWSPopupButton(hostWindow, hostButton, notifyProc [, initialSelection, globalString, popupWidth, popupHeight, options, content])
	String hostWindow, hostButton, notifyProc
	String initialSelection
	String globalString
	Variable popupWidth, popupHeight
	Variable options
	Variable content									// one of WMWS_Waves, WMWS_NVars, WMWS_Strings, or WMWS_DataFolders
	
	Variable TitleInTitle = 0			// selection is the title
	if (options & PopupWS_OptionTitleInTitle)
		TitleInTitle = 1
	endif
	
	ControlInfo/W=$hostWindow $hostButton
	if (V_flag != 1)
		return PopupWS_ErrorBadControl
	endif
	
	if (!ParamIsDefault(globalString))
		SVAR/Z gs = $globalString
		if (!SVAR_Exists(gs))
			return PopupWS_ErrorNoGlobalStr
		endif
	endif
	
	if (ParamIsDefault(popupWidth))
		popupWidth = 260
	endif
	
	if (ParamIsDefault(popupHeight))
		popupHeight = 240
	endif
	
	if (ParamIsDefault(initialSelection))
		initialSelection = NoSelectionString
	endif
	
	if (ParamIsDefault(content))
		content = WMWS_Waves
	endif
	
	STRUCT PopupWaveSelectorInfo popInfo
	popInfo.version = WAVEPOPUPVERSION
	popInfo.hostWindow = hostWindow
	popInfo.hostButton = hostButton
	popInfo.NotificationProc = notifyProc
	popInfo.width = popupWidth
	popInfo.height = popupHeight
	popInfo.SortKind = -1
	popInfo.SortOrder = -1
	popInfo.options = options
	if (options & PopupWS_OptionFloat)
		popInfo.doFloat = 1
	endif
	popInfo.content = content
	popInfo.fontSize = 0  // don't change it from default
	popInfo.fontStyle = 0 
	String infoStr
	StructPut/S popInfo, infoStr
	
	String titleString = RightJustString+Font9String+MenuArrowString
	if (TitleInTitle)
		ControlInfo/W=$hostWindow $hostButton
		Variable titlePos = strsearch(S_recreation, "title=\"", 0, 2)
		if (titlePos >= 0)
			titlePos += 7
			Variable titleEnd = strsearch(S_recreation, "\"", titlePos, 2)-1
			titleString = RightJustString+S_recreation[titlePos, titleEnd]+Font9String+MenuArrowString
		endif
	endif	
	
	Button $hostButton, win=$hostWindow, userData(popupWSInfo)=infoStr,proc=PopupWaveSelectorButtonProc
	Button $hostButton, win=$hostWindow,title=titleString
	if (SVAR_Exists(gs))
		Button $hostButton, win=$hostWindow, userData(popupWSGString)=globalString
	endif

	Wave/Z w=$initialSelection
	Variable isWave= WaveExists(w)
	Variable isDataFolder= DataFolderExists(initialSelection+":")	
	String str
	
	if (!TitleInTitle)
		if (isWave)
			str= NameOfWave(w)
		elseif(isDataFolder)
			str= initialSelection
		else
			str= NoSelectionString
		endif
		Button $hostButton, win=$hostWindow, title=RightJustString+str+" "+Font9String+MenuArrowString
	endif
	if (isWave)
		str= GetWavesDataFolder(w, 2)
	elseif(isDataFolder)
		str= initialSelection
	else
		str= NoSelectionString
	endif
	PopupWS_SetSelectionFullPath(hostWindow, hostButton, str)
	SetWindow $(StringFromList(0, hostWindow, "#")), hook(PopupWS_HostWindowHook)=PopupWSHostHook		// for the rename event

	return PopupWS_ErrorNoError
end

 

In reply to by vmmr5596

If you have this code working so that the function DemoPopupWaveSelectorNotify is reporting the selection, one way to go is to create a package folder and within the DemoPopupWaveSelectorNotify function save the string wavepath as a global string in your package folder that can be retrieved by your code that runs at another time. Is that what you're looking for?

string /G strwavepath=wavepath
function /S GetWavePath()
	
	SVAR wavepath=strWavepath
	return wavepath
end
•print getWavePath()

If you want the selection to trigger your code, call your code from within DemoPopupWaveSelectorNotify passing wavepath as a string.

Hi Tony,

I think that's exactly what I'm looking for. I also figured out a slightly different way just before reading your message.

Basically, if I use :

String wavePath = GetUserData("DemoPopupwaveSelectorPanel","PopupWaveSelectorB1","PopupWS_FullPath")

And then use your suggestion I get the desired outcome.

Thank you!

Don't use the user data. It is an implementation detail that a future version could change.

You are expected to write your own notify function; it will be called when the user makes a selection from the waveSelectorWidget. In the demo code you are citing, see this:

	MakeSetVarIntoWSPopupButton("DemoPopupWaveSelectorPanel", "PopupWaveSelectorSV1", "DemoPopupWaveSelectorNotify", "root:Packages:DemoPopupWaveSelector:WSSetVar1", options=PopupWS_OptionFloat+PopupWS_OptionSVFramed)

Note the third quoted string- it names the function to be called. The one in the demo simply prints out the selected wave's path; you would instead write a function that does something with that selection. Usually the notify function itself would do whatever is to be done with the wave, but it's possible you need to stash the string somewhere to be retrieved later, as Tony suggested.