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

Home » Public Forums » archive » Re: how to exchange variable between modal dialog and the main window?
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
Re: how to exchange variable between modal dialog and the main window? [message #48064] Tue, 21 March 2006 06:40 Go to next message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
lindows wrote:
> I'm doing a project,about image processing.But I don't know how to how
> to exchange variable between modal dialog and the main window.I can't
> find more material about the message exchanging in IDL windows.Could
> someone can help me?
> Now I use the GUIBuilder,in main window,put a button and make a
> procedure like this:
>
> pro OnPress,event
> dlggui,group_leader=event.top
> end
>
> dlggui is another procedure,with
> files:dlggui.pro,dlggui_event.pro,dlg_gui.prc.
>
> I don't know how I can transfer a variable or point A from main window
> to dlggui,I want to change the value of dlggui,in main program.
>
> thanks.
>

Transferring the variable from the main window to the dialog is easy --
just pass it as a parameter or keyword. Returning it is more tricky:

If your dialog is modal, you probably want to return the variable to the
main window at the point when the modal dialog is closed. In this case,
write your modal dialog as function which returns the variable:

http://www.dfanning.com/widget_tips/popup.html

If your dialog is not modal, i.e. you want to exchange information while
it is running in parallel with the main window, you can either send
events (widget_control, id, send_event=...) or write the dialogs (at
least the recipient of the information) as an object and call an object
method. Ask back if you need more information.

Good luck,
Benjamin
Re: how to exchange variable between modal dialog and the main window? [message #48065 is a reply to message #48064] Tue, 21 March 2006 06:40 Go to previous message
Ricardo Bugalho is currently offline  Ricardo Bugalho
Messages: 22
Registered: March 2005
Junior Member
Hello,
I'm not familiar with the GUI builder but you need to use each widget's
UVALUE to keep a reference to the information you want to keep arround.
Let's assume your dialog reads a number and a string. I could do it like
this:

PRO OnPress,event
MyVars = { name: "", number: 0 }
; This dynamic variable will hold all the field
; I care about the dialog
MyVarsPtr = PTR_NEW(MyVars)
DlgGUI, MyVarsPtr, group_leader=event.top
; Now the data is acessible
IF (*MyVarsPtr).name EQ "John Smith" THEN ...
END

PRO DlgGUI, varsPtr, GROUP_LEADER=gl
dlgTLB = WIDGET_BASE(GROUP_LEADER=gl, /MODAL)
...
nameField = WIDGET_TEXT(dlgTlb, $
UVALUE=varsPtr, $
EVENT_PRO="dlggui_name")
...
numberField = WIDGET_TEXT(dlgTlb, $
UVALUE=varsPtr, $
EVENT_PRO="dlggui_number")
...
WIDGET_CONTROL, dlgTlb, /REALIZE
END

PRO dlggui_name, event
; Update the name field
WIDGET_CONTROL, event.id, GET_VALUE=name
WIDGET_CONTROL, event.id, GET_UVALUE=ptr
(*ptr).name = name
END

PRO dlggui_number,event
; Update the numnber field
WIDGET_CONTROL, event.id, GET_VALUE=numberStr
WIDGET_CONTROL, event.id, GET_UVALUE=ptr
number = 0
READS, numberStr, number
(*ptr).number = number
END


A better way to do it is to wrap it in a class, like this:

PRO OnPress,event
dlg = OBJ_NEW('DLGGUI', GROUP_LEADER=event.top)
myVars = dlg->getVars()
OBJ_DESTROY,dlg
END

FUNCTION DLGGUI::INIT,GROUP_LEADER=gl
self.tlb = WIDGET_BASE(GROUP_LEADER=gl, /MODAL)
...
nameWidget = WIDGET_TEXT(self.tlb, $
UVALUE={object:self, method:'onNameEvent})
...
numberWidget = CW_FIELD(self.tlb, /INTEGER, $
UVALUE={object:self, method:'onNumberEvent})
...
WIDGET_CONTROL,self.tlb,/REALIZE
RETURN,1
END

PRO DLGGUI::onNameEvent,event
WIDGET_CONTROL,event.id, GET_VALUE=name
self.name = name
END

PRO DLGGUI::onNameEvent,event
WIDGET_CONTROL,event.id, GET_VALUE=name
self.name = name
END

PRO DLGGUI::onNumberEvent,event
WIDGET_CONTROL, event.id, GET_VALUE=number
self.number = number
END

FUNCTION DLGGUI::GetVars
RETURN,{name:self.name, number:self.number}
END

PRO DLGGUI__DEFINE
strcut = { DLGGUI, $
tlb: 0L, $
name: "", $
number: 0 $
}
END

PRO EVENT_HANDLER, event
; Event dispatcher for all my widgets
Widget_Control, event.id, GET_UVALUE=msg
IF event.top EQ 0 THEN top = event.id ELSE top = event.top
CALL_METHOD, msg.method, msg.object, event
END


On Mon, 2006-03-20 at 23:52 -0800, lindows wrote:
> I'm doing a project,about image processing.But I don't know how to how
> to exchange variable between modal dialog and the main window.I can't
> find more material about the message exchanging in IDL windows.Could
> someone can help me?
> Now I use the GUIBuilder,in main window,put a button and make a
> procedure like this:
>
> pro OnPress,event
> dlggui,group_leader=event.top
> end
>
> dlggui is another procedure,with
> files:dlggui.pro,dlggui_event.pro,dlg_gui.prc.
>
> I don't know how I can transfer a variable or point A from main window
> to dlggui,I want to change the value of dlggui,in main program.
>
> thanks.
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: How do I reduce active memory used by program?
Next Topic: Re: How to debug seg fault.

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

Current Time: Wed Oct 08 15:52:09 PDT 2025

Total time taken to generate the page: 0.00545 seconds