ListBox & ColorPopup
ChrLie
Ideally a built-in ListBox option (just like checkbox) would exist.
Any thoughts are welcome!
function myPanel() : Panel
Make/O/T/N=(20,3) wList
SetDimlabel 1, 0, Index, wList
SetDimlabel 1, 1, Color, wList
SetDimlabel 1, 2, Stuff, wList
Make/O/N=(20,3,2) sWave = 0
Make/O/N=(20,3) cWave = trunc(abs(enoise(65535)))
wList[][0] = num2str(p)
wList[][2] = "blah"
NewPanel/K=1/N=TestPanel /W=(600,100,1300,500)
ListBox list0,pos={50,50},size={600,300},listWave=wlist
ListBox list0,selWave=sWave, colorWave = cWave, proc=myListBoxProc
ListBox list0,fsize = 12, frame=3, userColumnResize=1
//set color of second column
sWave[][1][1]= p
SetDimLabel 2,1,backColors, sWave
end
Function myListBoxProc(lba) : ListBoxControl
STRUCT WMListboxAction &lba
Variable row = lba.row
Variable col = lba.col
WAVE/T/Z listWave = lba.listWave
WAVE/Z cWave = lba.colorWave
switch( lba.eventCode )
case -1: // control being killed
break
case 1: // mouse down
// clicked on color
if(col == 1)
variable/g WhichRow = row
//get a color popup
GetWindow TestPanel wsizeRM
variable top, left
top = V_top * ScreenResolution/72
left = V_left * ScreenResolution/72
NewPanel/K=1 /N=cpop /W=(left+200, top+200, left+250, top+220)
PopupMenu popup0 value="*COLORPOP*", proc = myPopMenuProc
PopupMenu popup0 popColor=(cWave[row][0],cWave[row][1],cWave[row][2])
endif
break
// handle more events
endswitch
return 0
End
Function myPopMenuProc(pa) : PopupMenuControl
STRUCT WMPopupAction &pa
wave/Z cWave
NVAR WhichRow
variable rr, gg, bb
switch( pa.eventCode )
case 2: // mouse up
Variable popNum = pa.popNum
String popStr = pa.popStr
sscanf popstr, "(%g,%g,%g)", rr,gg,bb
cWave[WhichRow][0] = rr; cWave[WhichRow][1] = gg; cWave[WhichRow][2] = bb;
break
case -1: // control being killed
break
endswitch
return 0
End
Make/O/T/N=(20,3) wList
SetDimlabel 1, 0, Index, wList
SetDimlabel 1, 1, Color, wList
SetDimlabel 1, 2, Stuff, wList
Make/O/N=(20,3,2) sWave = 0
Make/O/N=(20,3) cWave = trunc(abs(enoise(65535)))
wList[][0] = num2str(p)
wList[][2] = "blah"
NewPanel/K=1/N=TestPanel /W=(600,100,1300,500)
ListBox list0,pos={50,50},size={600,300},listWave=wlist
ListBox list0,selWave=sWave, colorWave = cWave, proc=myListBoxProc
ListBox list0,fsize = 12, frame=3, userColumnResize=1
//set color of second column
sWave[][1][1]= p
SetDimLabel 2,1,backColors, sWave
end
Function myListBoxProc(lba) : ListBoxControl
STRUCT WMListboxAction &lba
Variable row = lba.row
Variable col = lba.col
WAVE/T/Z listWave = lba.listWave
WAVE/Z cWave = lba.colorWave
switch( lba.eventCode )
case -1: // control being killed
break
case 1: // mouse down
// clicked on color
if(col == 1)
variable/g WhichRow = row
//get a color popup
GetWindow TestPanel wsizeRM
variable top, left
top = V_top * ScreenResolution/72
left = V_left * ScreenResolution/72
NewPanel/K=1 /N=cpop /W=(left+200, top+200, left+250, top+220)
PopupMenu popup0 value="*COLORPOP*", proc = myPopMenuProc
PopupMenu popup0 popColor=(cWave[row][0],cWave[row][1],cWave[row][2])
endif
break
// handle more events
endswitch
return 0
End
Function myPopMenuProc(pa) : PopupMenuControl
STRUCT WMPopupAction &pa
wave/Z cWave
NVAR WhichRow
variable rr, gg, bb
switch( pa.eventCode )
case 2: // mouse up
Variable popNum = pa.popNum
String popStr = pa.popStr
sscanf popstr, "(%g,%g,%g)", rr,gg,bb
cWave[WhichRow][0] = rr; cWave[WhichRow][1] = gg; cWave[WhichRow][2] = bb;
break
case -1: // control being killed
break
endswitch
return 0
End
EDIT: ok, I found a solution to problem 1). I overlooked mouseLoc.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
November 30, 2015 at 10:50 am - Permalink
is a lot more elegant!
December 1, 2015 at 03:05 am - Permalink