CW_FORM woes [message #10263] |
Tue, 04 November 1997 00:00  |
barg
Messages: 3 Registered: September 1997
|
Junior Member |
|
|
Hello All,
Can anyone give me an working example of how to use CW_FORM?
I've included the test example given in the IDL Reference Vol 1,
page 314, but I can't figure how to get global variables set
from obtaining tag=value pairs in my CW_FORM. When I run my
testform below, my event handler traps the 'OK' correctly,
but fails on trapping the tag 'fsize'. What I want to do is
when 'OK' is pressed, all tag=value pairs get saved in variables
defined in the COMMON block 'params'.
A simple example would be greatly appreciated.
Thank you in advance.
Irene Barg
ibarg@as.arizona.edu
****testform.pro*****
; testform.pro - example using CW_FORM.
PRO testform_Event, event
COMMON params, fsize, fname
COMMON b_ids, b
IF (event.id EQ b) THEN BEGIN
PRINT, ' '
PRINT, 'CW_FORM B is up!'
ENDIF
IF (event.quit) THEN BEGIN
PRINT, 'Button selected: ', event.value
WIDGET_CONTROL, event.id, /DESTROY
ENDIF
CASE event.tag OF
'OK': begin
HELP, /STRUCTURE, b
WIDGET_CONTROL, event.top, /DESTROY
end
'fsize': begin
; this doesn't work
fsize = event.value
PRINT, 'FSIZE = ', fsize
end
ENDCASE
END
PRO testform
COMMON b_ids, b
COMMON params, fsize, fname
; describe my form
DESC = [ $
'0, LABEL, Centered Label, CENTER', $
'1, BASE,, ROW, FRAME', $
'0, BUTTON, B1|B2|B3, LABEL_TOP=Nonexclusive:, COLUMN, TAG=bg1', $
'2, BUTTON, E1|E2|E3, EXCLUSIVE, LABEL_TOP=Exclusive:, COLUMN, TAG=bg2', $
'0, TEXT, , LABEL_LEFT=Enter File name:, WIDTH=12, TAG=fname', $
'0, INTEGER, 0, LABEL_LEFT=File size:, WIDTH=12, TAG=fsize', $
'1, BASE,, ROW', $
'0, BUTTON, OK, QUIT, FONT=*helvetica-medium-r-*-180-*, TAG=OK', $
'2, BUTTON, Cancel, QUIT']
a = WIDGET_BASE(TITLE='Testing IDL forms')
b = CW_FORM(a, desc, /COLUMN)
WIDGET_CONTROL, a, /REALIZE
XMANAGER, 'TESTFORM', a
END
|
|
|
Re: CW_FORM [message #21328 is a reply to message #10263] |
Tue, 22 August 2000 00:00  |
promashkin
Messages: 169 Registered: December 1999
|
Senior Member |
|
|
Aimy wrote:
>
> I want to create a widget that will allow the user to input several
> strings into various fields, and then have a 'Quit' button that when
> pressed will destroy the widget and retain the inputed values.
>
> Below is my code. So far I am unsuccessful at getting CW_FORM to work. Is
> CW_FORM what I should be using? If so, could anyone tell me what I am
> missing in my code?
>
> I would appreciate any help!!
>
> Thanks,
> Aimy
Aimy,
I am not so sure that you need to be using CW_FORM. It is the most
convoluted program in my opinion that comes with IDL. I would much
rather write what you need in plain widget language.
However, I think the only thing that is wrong in your code is the first
"1". Try the following:
==================
pro CmpndWidget
BaseWidget=WIDGET_BASE(Title='Base')
desc = ['0, TEXT, , LABEL_LEFT=File name:, WIDTH=12, TAG=Name', $
'0, BUTTON, OK, QUIT, TAG=OK', $
'2, BUTTON, Cancel, QUIT']
FormWidget=CW_FORM(BaseWidget, desc, /COLUMN)
; Making the widget visible on the screen
WIDGET_CONTROL, /REALIZE, BaseWidget
REPEAT BEGIN
event=widget_event(BaseWidget)
ENDREP UNTIL (event.quit EQ 1)
print, event.VALUE
end
==================
I am not exactly sure what are you accomplishing with the event handling
that you provided, but the above code works. I guess you could use event
structures from other widgets inside that repeat loop.
If I needed what you need, I'd put together something like:
==================
pro test
base = widget_base(title='Base', /column)
filename = cw_field(base, title='File name:')
ok = widget_button(base, value='OK', uvalue='void')
cancel = widget_button(base, value='Cancel', uvalue='void')
widget_control, base, /realize
end
==================
and provided a conventional event handling procedure managed by Xmanager
for it. Takes about 10 lines of code.
Cheers,
Pavel
|
|
|