Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
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
Here's a very brief thing... pro thistext,event widget_control,event.id,get_value=text print,text end pro wget base=widget_base(title='test',/col) wtext=widget_text(base,value='',uname='textbox',/edit,event_ pro='thistext') widget_control,base,/realize state=ptr_new({wtext:wtext}) widget_control,base,set_uval=state xmanager,'wget',base,/no_block end if you put text in the box and hit return, then it will print that text to the terminal. -Russell PS... you might start using the new page set up by W. Landsman. this is loaded with spam. On Friday, December 29, 2017 at 2:35:18 PM UTC-5, Ann Nonymous wrote: > 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