comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » text widget example
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
text widget example [message #94945] Fri, 29 December 2017 11:35 Go to previous message
astroboy.20000 is currently offline  astroboy.20000
Messages: 39
Registered: August 2012
Member
Hello,

Does anyone have a snippet of code that shows how to process input from a text widget? What I'm asking about is that you have a text widget, you type in a string, and hit return, and the string is passed to the event_pro routine for that widget.

I would have thought this information would have been passed in the event structure but I can't find anything that explains if this is the case. What I have found is illustrated below in the code from Liam Gumley's book, where the string is passed via a variable in the uvalue. This seems like a complicated way to go about it, especially since in the program I'm writing I'd like to have about a dozen text widgets.

Thanks,

Mark







PRO WGETNAME_EVENT, EVENT

print, 'Event detected'

;- Get state information
widget_control, event.top, get_uvalue=infoptr
info = *infoptr

;- Identify widget which caused the event
widget_control, event.id, get_uvalue=widget
help, widget

;- Handle events
if (widget eq 'Text') or (widget eq 'OK') then begin
widget_control, info.text, get_value=name
info.name = name
info.status = 'OK'
endif else begin
info.name = ''
info.status = 'Cancel'
endelse


print,'name ',name

;- Save state information
*infoptr = info

;- Destroy the widget hierarchy
widget_control, event.top, /destroy

END

PRO WGETNAME_CLEANUP, ID

print, 'Cleaning up'

;- Get state information
widget_control, id, get_uvalue=infoptr



info = *infoptr

;- Save result
result = {name:info.name, status:info.status}
*infoptr = result

END

PRO WGETNAME, NAME, STATUS

print, 'Creating widgets'

;- Create top level base
device, get_screen_size=screen_size
xoffset = screen_size[0] / 3
yoffset = screen_size[1] / 3
tlb = widget_base(column=1, title='Name', $
xoffset=xoffset, yoffset=yoffset, tlb_frame_attr=1)

;- Create text entry widgets
tbase = widget_base(tlb, row=1)
label = widget_label(tbase, value='Enter your name: ')
text = widget_text(tbase, uvalue='Text', /editable)

;- Create button widgets
bbase = widget_base(tlb, row=1, /align_center)
bsize = 75
butta = widget_button(bbase, value='OK', $
uvalue='OK', xsize=bsize)
buttb = widget_button(bbase, value='Cancel', $
uvalue='Cancel', xsize=bsize)

;- Realize widgets
widget_control, tlb, /realize

;- Create and store state information
info = {text:text, name:'', status:'Cancel'}
infoptr = ptr_new(info)
widget_control, tlb, set_uvalue=infoptr

;- Manage events
xmanager, 'wgetname', tlb, cleanup='wgetname_cleanup'

;- Get result
result = *infoptr
ptr_free, infoptr
name = result.name
status = result.status

END
[Message index]
 
Read Message
Read Message
Previous Topic: New Google Group: idl-pvwave
Next Topic: Problem saving a simple png plot

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:16:37 PDT 2025

Total time taken to generate the page: 0.02862 seconds