CheckBox ControlInfo doesnot work inside a mouse event
supra
I borrowed this code from utility "Drag and Drop Traces by" "RGerkin" and used it in my own program with certain modifciation and bug fixed.
I added a Checkbox named "Check5" and used it to select whether the "AppendToGraph" is with or without reverse axis.( See the code within two red horizontal dashed line.")
But Somehow this control does not work. always it choose the default unchecked option ( without reverse axis ) although it does not give any wrong message. Is it because this control is within a mouse event that’s why its not working ? or I am missing something.
CheckBox Check5, pos={300,265},size={39,14},title="Reverse Axis",value= 0
Function DragAndDropToggle()
variable i
string wins=winlist("*",";","WIN:1")
dfref df=root:Packages:DragAndDropTraces
if(!datafolderrefstatus(df))
newdatafolder /o root:Packages
newdatafolder /o root:Packages:DragAndDropTraces
dfref df=root:Packages:DragAndDropTraces
string /g df:source,df:dest,df:trace
variable /g df:lsize
for(i=0;i<itemsinlist(wins);i+=1)
string win=stringfromlist(i,wins)
setwindow $win hook(DragAndDrop)=DragAndDropHook
endfor
else
killdatafolder df
for(i=0;i<itemsinlist(wins);i+=1)
win=stringfromlist(i,wins)
setwindow $win hook(DragAndDrop)=$""
endfor
endif
End
Function DragAndDropHook(info)
struct WMWinHookStruct &info
dfref df=root:Packages:DragAndDropTraces
if(!datafolderrefstatus(df))
return -1
endif
string trace_info1=TraceFromPixel(info.mouseLoc.h,info.mouseLoc.v,"")
getwindow $info.winName psizeDC
variable mouseH=info.mouseLoc.h, mouseV=info.mouseLoc.v // Convert to variables.
if(mouseH>v_right || mouseH<v_left || mouseV<v_top || mouseV>v_bottom)
nvar /sdfr=df lsize
svar /sdfr=df trace
if(strlen(trace) && lsize)
modifygraph /z lsize($trace)=lsize
endif
endif
switch(info.eventCode)
case 3: // Mouse down.
if(strlen(trace_info1))
info.cursorCode=1
info.doSetCursor=1
string /g df:trace=stringbykey("TRACE",trace_info1), df:source=info.winName
svar /sdfr=df trace
string trace_info2=traceinfo(info.winName,trace,0)
variable /g df:lsize=numberbykey("lsize(x)",trace_info2,"=")
nvar /sdfr=df lsize
if(numtype(lsize))
return -2
endif
modifygraph lsize($trace)=min(10,lsize*3)
endif
break
case 5: // Mouse up.
nvar /sdfr=df lsize
svar /sdfr=df trace,source
if(strlen(trace) && strlen(source) && lsize)
modifygraph /z/w=$source lsize($trace)=lsize
endif
if(!stringmatch(source,info.winName)) // Dragged from another window.
wave w1=tracenametowaveref(source,trace)
wave xWave = XWaveRefFromTrace(source, trace)
// removefromgraph /z/w=$source $trace
//---------------------------------------------------------------------------------------------------------------
Variable Conf5
ControlInfo Check5
Conf5= V_value
if (Conf5)
appendtograph/R /w=$info.winName w1 vs xWave
else
appendtograph /w=$info.winName w1 vs xWave
endif
//------------------------------------------------------------------------------------------------------------------
//display w1 vs xWave
endif
trace=""
break
endswitch
End
Function DragAndDropToggle()
variable i
string wins=winlist("*",";","WIN:1")
dfref df=root:Packages:DragAndDropTraces
if(!datafolderrefstatus(df))
newdatafolder /o root:Packages
newdatafolder /o root:Packages:DragAndDropTraces
dfref df=root:Packages:DragAndDropTraces
string /g df:source,df:dest,df:trace
variable /g df:lsize
for(i=0;i<itemsinlist(wins);i+=1)
string win=stringfromlist(i,wins)
setwindow $win hook(DragAndDrop)=DragAndDropHook
endfor
else
killdatafolder df
for(i=0;i<itemsinlist(wins);i+=1)
win=stringfromlist(i,wins)
setwindow $win hook(DragAndDrop)=$""
endfor
endif
End
Function DragAndDropHook(info)
struct WMWinHookStruct &info
dfref df=root:Packages:DragAndDropTraces
if(!datafolderrefstatus(df))
return -1
endif
string trace_info1=TraceFromPixel(info.mouseLoc.h,info.mouseLoc.v,"")
getwindow $info.winName psizeDC
variable mouseH=info.mouseLoc.h, mouseV=info.mouseLoc.v // Convert to variables.
if(mouseH>v_right || mouseH<v_left || mouseV<v_top || mouseV>v_bottom)
nvar /sdfr=df lsize
svar /sdfr=df trace
if(strlen(trace) && lsize)
modifygraph /z lsize($trace)=lsize
endif
endif
switch(info.eventCode)
case 3: // Mouse down.
if(strlen(trace_info1))
info.cursorCode=1
info.doSetCursor=1
string /g df:trace=stringbykey("TRACE",trace_info1), df:source=info.winName
svar /sdfr=df trace
string trace_info2=traceinfo(info.winName,trace,0)
variable /g df:lsize=numberbykey("lsize(x)",trace_info2,"=")
nvar /sdfr=df lsize
if(numtype(lsize))
return -2
endif
modifygraph lsize($trace)=min(10,lsize*3)
endif
break
case 5: // Mouse up.
nvar /sdfr=df lsize
svar /sdfr=df trace,source
if(strlen(trace) && strlen(source) && lsize)
modifygraph /z/w=$source lsize($trace)=lsize
endif
if(!stringmatch(source,info.winName)) // Dragged from another window.
wave w1=tracenametowaveref(source,trace)
wave xWave = XWaveRefFromTrace(source, trace)
// removefromgraph /z/w=$source $trace
//---------------------------------------------------------------------------------------------------------------
Variable Conf5
ControlInfo Check5
Conf5= V_value
if (Conf5)
appendtograph/R /w=$info.winName w1 vs xWave
else
appendtograph /w=$info.winName w1 vs xWave
endif
//------------------------------------------------------------------------------------------------------------------
//display w1 vs xWave
endif
trace=""
break
endswitch
End
V_flag = 2 for a checkbox.
June 13, 2012 at 05:08 am - Permalink
ControlInfo/W=panelname Check5 if (V_value) ... endif
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
June 13, 2012 at 05:53 am - Permalink
June 13, 2012 at 06:05 am - Permalink
Indeed Panel name was the problem and as Weimer suggested ControlInfo/W=panelname solved the problem
Thank you so much to all of you
June 13, 2012 at 04:49 pm - Permalink