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

Home » Public Forums » archive » How to return Values from an options dialog widget to the main program (Pointers)
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How to return Values from an options dialog widget to the main program (Pointers) [message #54030] Sun, 13 May 2007 03:18
Patrique is currently offline  Patrique
Messages: 3
Registered: May 2007
Junior Member
Hi all,

Since about 1 year IDL is the main language I'm programming my data-
analysis tools with. Now, that my *main tool* becomes more and more
sophisticated, I've come to the point where a modal options dialog
widget might be helpful. This widget can be called from the menu bar.
As I figured out at David Fannings web site, pointers should be the
most convenient way to get the variables that can be set in the
options dialog back to my main program. Well...that's the point that
leads to my question:

Below I attached the short widget-program 'testgui' with the event-
handler routine 'testgui_event' to illustrate my problem. The main
widget includes 3 buttons. The first button 'button_press' calls the
child widget 'OptionsDialog' that has an event-handler routine
'OptionsDialog_event'. In that modal widget I can type in a text
string. After pressing the 'Accept' Button, the string is stored in
pointer 'ptr' (according to a tutorial of David Fanning) and the child
widget 'Options Dialog/B_10' is destroyed.
When I now press the button 'Show Ptr Value' (uvalue: Button_doit) in
the main window I would like to see the string value stored in ptr
appearing in the IDL log (respective source code framed by '='signs).
But, even though a pointer exists in memory, I don't know how to
access my pointer ptr.
What am I doing wrong? What else do I have to take care of? How can I
reference to this HeapVariable that exists in the memory? It seems to
me as I did not understand right how to access a pointer outside of
the routine where it was created.

I appreciate any help!
Cheers and Thank you,
Patrique.



pro OptionsDialog_event, event
Widget_Control, event.top, Get_UValue=info
CASE event.ID OF
info.cancelID: Widget_Control, event.top, /Destroy
ELSE: BEGIN
Widget_Control, info.Wstartyear, Get_Value=startyear
(*info.ptr).syear = startyear[0]

Widget_Control, event.top, /Destroy
ENDCASE
ENDCASE
end

pro OptionsDialog, event
B_10 = Widget_Base( GROUP_LEADER=event.top, UNAME='B_10' $
,Column=1, /Modal)

Wstartyear = Widget_Text(B_10, /Editable, value="A Number")

buttonBase = Widget_Base(B_10, Row=1, /Align_Center)
cancelID = Widget_Button(buttonBase, Value='Cancel')
acceptID = Widget_Button(buttonBase, Value='Accept')

ptr = Ptr_New({syear:"",cancel:1})
info = {ptr:ptr,cancelID:cancelID,Wstartyear:Wstartyear}


Widget_Control, B_10, Set_UValue=info, /No_Copy
Widget_Control, B_10, /Realize
XManager, 'OptionsDialog', B_10
end


pro testgui_event, Event
case Event.id of
Widget_Info(Event.top, FIND_BY_UNAME='button_press'): begin
if (Tag_Names(Event, /STRUCTURE_NAME) eq 'WIDGET_BUTTON') then
begin
;Call OptionsDialog where *ptr is defined
OptionsDialog, Event
endif
end

;=========================================================== ==============
Widget_Info(Event.top, FIND_BY_UNAME='button_doit'): begin
if (Tag_Names(Event, /Structure_name) eq 'WIDGET_BUTTON') then
begin
;Just look whether there is a pointer somewhere in memory
print, ptr_valid()
;Tell me, if pointer ptr is still valid and, if it is,
;print me the value *ptr.syear
if (PTR_VALID(PTR)) eq 1 then print, (*ptr).syer
endif
end
;=========================================================== ==============

Widget_Info(Event.top, FIND_BY_UNAME='button_exit'): begin
if (Tag_Names(Event,/Structure_name) eq 'WIDGET_BUTTON') then
begin
PTR_FREE, PTR_VALID()
widget_control, Event.top, /destroy
endif
end
else:
endcase
end

pro testgui, Group_Leader=wGroup, _Extra=_VWBExtra_
B_00 = Widget_Base( GROUP_LEADER=wGroup, UNAME='B_00' $
,xsize=100, column=1 )

Button_00 = Widget_Button(B_00, UNAME='button_press', VALUE='Make
Ptr Value')
Button_01 = Widget_Button(B_00, UNAME='button_doit' ,
VALUE='Show Ptr Value')
Button_02 = Widget_Button(B_00, UNAME='button_exit' ,
VALUE='EXIT')

Widget_Control, /REALIZE, B_00
XManager, 'testgui', B_00
end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Extracting zeros from array
Next Topic: Re: ENVI_CONVERT_FILE_COORDINATES returning negative values

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

Current Time: Wed Oct 08 19:20:13 PDT 2025

Total time taken to generate the page: 0.00500 seconds