Re: WIDGET_COMBOBOX [message #39281] |
Fri, 07 May 2004 13:29 |
portshome
Messages: 10 Registered: August 2003
|
Junior Member |
|
|
Here is what I am trying to do. I have an image display GUI that
allows the user to change the zoom factor of the image in several
different ways.
1. Type a zoom factor in manually (currently done using just an
editable CW_FIELD
2. Choose from a list of predefined zoom factors (if I could just the
WIDGET_COMBOBOX to do what I wanted it to do, I would use it)
3. Increment/Decrement the zoom factor (using + and - buttons)
4. Drag and select an area in the draw window and zoom in on that
area.
Number 4 creates the need to be able to manually update the text
portion of the WIDGET_COMBOBOX. Since dragging and selecting an area
will create a new zoom factor, I want to display this number for the
user's information. However, I do not want to add it to my list of
predefined zoom factors, especially since if they do this several
times the list could become long and unwieldly.
So I suppose I am just asking for too much. Which is fine, I just
thought there might be a way.
PJ
|
|
|
Re: WIDGET_COMBOBOX [message #39287 is a reply to message #39281] |
Fri, 07 May 2004 06:36  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
David Fanning writes:
> If *you* want to do it, you include it in the list.
> Otherwise, what is the point?
Let me put this another way.
The point of a combobox is to allow the user to
make a choice that the programmer didn't anticipate.
If the programmer *had* anticipated it, he would have
included it on the list of possible choices.
If you, as the programmer, want to make an unanticipated
choice for the user, then you are following the principles
of Thinking For You, which we have already decided earlier
this week is NOT the IDL way. Hence, IDL makes it impossible
to make this program design error. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: WIDGET_COMBOBOX [message #39288 is a reply to message #39287] |
Fri, 07 May 2004 06:28  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
PJL writes:
> That actually does not solve my problem. I don't want to add any items
> to the combobox list, or modify any items in the combobox list. I just
> want to be able to set the text in the editable portion of the
> combobox. Is this even possible??
No, that's what the *user* is suppose to do. :-)
If *you* want to do it, you include it in the list.
Otherwise, what is the point?
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: WIDGET_COMBOBOX [message #39289 is a reply to message #39288] |
Fri, 07 May 2004 06:17  |
portshome
Messages: 10 Registered: August 2003
|
Junior Member |
|
|
That actually does not solve my problem. I don't want to add any items
to the combobox list, or modify any items in the combobox list. I just
want to be able to set the text in the editable portion of the
combobox. Is this even possible??
PJ
|
|
|
Re: WIDGET_COMBOBOX [message #39290 is a reply to message #39289] |
Thu, 06 May 2004 19:23  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
PJL writes:
> Does anyone know a way that the text portion of the WIDGET_COMBOBOX
> can be manually updated? The IDL help does not document as such, all
> there seems to be is COMBOX_ADDITEM which adds the item to the list.
> But surely there must be some way to edit just the text box from
> within the program since the user can manually type something in if
> the EDITABLE keyword is set.
I'm not sure it is always straightforward to know what to
do with the value of the combobox. If you are trying to set
the value to a value in the list, it is easy. But if you
are trying to set the value to something *not* on the list,
what do you do?
Here is one way to solve the problem:
;*****************************************************
PRO test_event, event
box = Widget_Info(event.top, /Child)
Widget_Control, box, get_value=values
name = Tag_Names(event, /Structure_Name)
IF name NE 'WIDGET_BUTTON' THEN RETURN
Widget_Control, event.id, Get_Value=buttonValue
CASE buttonValue OF
'Set It to Moe': BEGIN
index = Where(values EQ 'Moe')
IF index GT 0 THEN Widget_Control, box, Set_ComboBox_Select=index
END
'Set It to Fred': BEGIN
; Is the current value Fred?
name = Widget_Info(box, ComboBox_GetText=1)
index = Where(StrUpCase(values) EQ StrUpCase(name), count)
IF count GT 0 THEN BEGIN
I = Where(StrUpCase(values) EQ 'FRED', count)
IF count GT 0 THEN BEGIN
Widget_Control, box, Set_ComboBox_Select=I
ENDIF ELSE BEGIN
values[index] = 'Fred'
Widget_Control, box, Set_Value=values
Widget_Control, box, Set_ComboBox_Select=index
ENDELSE
ENDIF ELSE BEGIN
values = [values, 'Fred']
Widget_Control, box, Set_Value=values
Widget_Control, box, Set_ComboBox_Select=N_Elements(values)-1
ENDELSE
END
ENDCASE
END
PRO Test
tlb = Widget_Base(Column=1)
box_values = ['Larry', 'Moe', 'Curley']
box = Widget_Combobox(tlb, value=box_values, /Editable)
button = Widget_Button(tlb, Value='Set It to Moe')
button = Widget_Button(tlb, Value='Set It to Fred')
Widget_Control, tlb, /Realize, Set_UValue=box_values
XManager, 'test', tlb, /No_Block
END
;*****************************************************
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|