Re: CW_FIELD question [message #54210] |
Sat, 26 May 2007 18:46  |
markb77
Messages: 217 Registered: July 2006
|
Senior Member |
|
|
The programming weirdness continues! I am forging ahead with my non-
standard and completely upside down IDL programming style - ie. Widget
programs without a separate event handler. I have figured out a
couple of things about querying the state of TEXT and BUTTON widgets
without relying on events generated by them.
Check out this example:
PRO Example
tlb = Widget_Base(Column=1)
field1 = WIDGET_TEXT(tlb, /EDITABLE)
field2 = FSC_INPUTFIELD(tlb)
button_wid = CW_BGroup(tlb, 'SET', /Col, /NonExclusive, Set_Value
= 1)
WIDGET_CONTROL, tlb, /REALIZE
XManager, 'example', tlb, /NO_BLOCK
quita = 0
while quita ne 1 do begin
event2 = WIDGET_EVENT(button_wid, /NOWAIT)
event1 = WIDGET_EVENT(tlb, /NOWAIT)
WIDGET_CONTROL, field1, GET_VALUE=f1val
f2val = field2->Get_Value()
WIDGET_CONTROL, button_wid, GET_VALUE=bval
print, f1val, f2val, bval
if f1val eq 'q' then quita = 1
wait, .1
endwhile
WIDGET_CONTROL, tlb, /DESTROY
END
This fixes the earlier problem I had with not being able to read out
the value of FSC_INPUTFIELD, and a later problem I encountered where I
could not read out the current state of a checkbox button that I had
created with CW_BGROUP.
It seems that the presence of the calls to WIDGET_EVENT are necessary
for both of these things to work. Without the second call to
WIDGET_EVENT we are unable to query the FSC_INPUTFIELD value. Without
the first call, we are unable to query the state of the button.
There's more! Reverse the order of the calls to WIDGET_EVENT and it
doesn't work!
I cannot convince myself that switching to a traditional event handler
application structure is worth the work. I would have to "drag
around" hundreds of variables in some sort of application state
structure or common block. It certainly could be done, but wouldn't
it be easier if we could just query the values of these widgets
without the necessity of some kind of event handler, which it seems is
the current situation? Notice that I'm not using the events for
anything in the code, but the WIDGET_EVENT call is necessary just to
get the subsequent WIDGET_CONTROL.. GET_VALUE queries to work.
Great fun.
Mark
|
|
|