Re: widget with check table ?? [message #12590] |
Tue, 25 August 1998 00:00  |
J.D. Smith
Messages: 214 Registered: August 1996
|
Senior Member |
|
|
Martin Vissers wrote:
>
> I'm trying to create a dialog in which you can select
> several options within a table.
>
> Can this be done with widget programming ???
> an example:
>
> | AA | BB | CC |
> --------------------------|
> 1 | x | | |
> --------------------------|
> 2 | | | x |
> --------------------------|
> 3 | x | x | x |
> --------------------------|
> 4 | | | |
> --------------------------|
> 5 | | | x |
> --------------------------|
>
> so the user can select (with an x or a radio button) which
> options will be processed.
>
> Someone there with a good idea ???
How about the following:
pro testaw_event,ev
widget_control, ev.top, get_uvalue=barr,/NO_COPY
wh=where(ev.id eq barr) & wh=wh[0]
msg='Selected' & if ev.select eq 0 then msg='De-'+msg & msg=' '+msg
print,'ROW: '+strtrim(wh/3+1,2)+' COLUMN: '+ (['A','B','C'])[wh mod 3]+msg
widget_control, ev.top, set_uvalue=barr,/NO_COPY
end
pro testaw
b=widget_base(/COLUMN,/BASE_ALIGN_LEFT)
barr=lonarr(3,5)
lab=widget_label(b,value=string(FORMAT='(3A5)','A','B','C'))
for i=0,4 do begin
base=widget_base(b,/ROW)
lab=widget_label(base,value=string(i+1,FORMAT='(I1)'))
base=widget_base(base,/ROW,/NONEXCLUSIVE)
for j=0,2 do barr(j,i)=widget_button(base,value='')
endfor
widget_control, b,/REALIZE,set_uvalue=barr
XManager, 'testaw',b,/NO_BLOCK
end
Note that to get the column headings to line up we have to monkey with the
string format, and so the placement will depend on the font and system used. In
addition, to get buttons from row to row to line up, the row labels must occupy
the same space (which is easy enough to enforce for a mono-spaced font). This is
of course frustrating but I see no simple workaround. Likely a large amount of
code which test widget size and employs [XY]OFFSET could accomplish this in a
more portable way, but it would be ugly. This works well on my Linux IDL v5.1
with a mono-spaced font (10pt). To accomodate longer column headings you can
use spaces in the button values.
JD
--
J.D. Smith |*| WORK: (607) 255-5842
Cornell University Dept. of Astronomy |*| (607) 255-6263
304 Space Sciences Bldg. |*| FAX: (607) 255-5875
Ithaca, NY 14853 |*|
|
|
|