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

Home » Public Forums » archive » widget event structure doesn't transfer
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
widget event structure doesn't transfer [message #81051] Mon, 13 August 2012 13:45 Go to next message
Oana Coman is currently offline  Oana Coman
Messages: 27
Registered: December 2011
Junior Member
hi guys,
I have a widget base(1) with a couple of buttons on it, and when i click one of the buttons it brings up a base widget(2) containing a draw widget and a couple of fields from which I want to save the input to do stuff in that first widget with all the bottons (so when i click a button there, i can use the data I got from (2) to do stuff in (1)).

The code for widget 1 is in one .pro file, and the code for widget 2 is in another. Would this be the reason the information is not transferring between the two? I thought that would be ok. Or maybe my code is crazy (which is most probable)


here is what I have in the widget 1 definition module to get to widget 2 (the .......'s are just to save space):
w_userRoi= widget_button(p,value = 'Get User Defined ROI',frame = 2,$
event_pro = 'userROI')
widget_control,w_top , set_uval = { .........,$
userROI: -1L,$ ;since I don't have an event structure yet. Maybe I should put something else here??
userCon: w_userCon,$
cx1: w_cx1 ,$
..........,$etcetcetc}

and here is my actual UserROI code, in UserROI.pro

Pro UserROI, event

tlb = Widget_Base(Title='User Defined ROI', row=4,xsize=260, $
/Base_Align_Center, Group_Leader=event.top)
drawID = Widget_Draw(tlb, Xsize=260,Ysize=260, uvalue=13)
widget_control, drawID, get_value=wid
wset, wid

;get data from widget 1
widget_control, event.top, get_uval = w
widget_control, w.imagevu, get_uval = w
widget_control, w.cw_image, get_uval=w
widget_control, w.data, get_uval = d
widget_control, w.stretch, get_uval=s
widget_control,s.smin, get_valu=smin
widget_control,s.smax, get_valu=smax

image=congrid(d.image, 260,260)

xlabelbase = Widget_Base(tlb, Row=1)
w_xStart = cw_field(xlabelbase, /text, title='X:', frame=2, valu=0, xsize=6)
w_xDelta= cw_field(xlabelbase, /text, title='dx:', frame=2, valu=0, xsize=6)

ylabelbase = Widget_Base(tlb, Row=1)
w_yStart= cw_field(ylabelbase, /text, title='Y:', frame=2, valu=0, xsize=6)
w_yDelta= cw_field(ylabelbase, /text, title='dy:', frame=2,valu=0, xsize=6)

buttonBase = Widget_Base(tlb, column=3, /align_center, /base_align_center)
cancelID = Widget_Button(buttonBase, Value='Cancel', event_pro='userROI_quit')
viewID = Widget_Button(buttonBase, Value='View', event_pro='userROI_view')
acceptID = Widget_Button(buttonBase, Value='Accept', event_pro='userROI_accept')
; Realize the widget hierarchy.

Widget_Control, tlb, /Realize

tvimage1, bytscl(image, smin, smax)

info = { use:0,$
image:image,$
origImage:d.image,$
wid:wid,$
drawID: drawID,$
xstart:w_xStart,$
xdelta:w_xDelta,$
ystart:w_yStart,$
ydelta:w_yDelta,$
xend:-1L,$
yend:-1L}

Widget_Control, tlb, Set_UValue=info, /No_Copy


widget_control, event.top, get_uval=w
w.userROI = tlb
widget_control, event.top, set_uval=w


XManager, 'textbox', tlb
END

When I try to call my userROI data in widget 1, I get:
% WIDGET_CONTROL: Invalid widget identifier: 143.


Do you have any thoughts on this? Where did I go wrong?
Thanks.
Re: widget event structure doesn't transfer [message #81134 is a reply to message #81051] Tue, 14 August 2012 18:29 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kat writes:

> I have the book and it's definitely my go-to widget guide. I have a
bit of an idea how to run normal widgets using procedures but once I try
to figure out the functions and these popup dialogs it's like a whole
new ballgame (I am also a little slow haha so I'm sure that doesn't
help). I've looked at the Pop-up Dialog page a lot and though I get the
overall idea, I'm not sure how to carry it out.
>
> For example, textbox is defined:
> FUNCTION TextBox, Title=title, Label=label, Cancel=cancel, $
> Group_Leader=groupleader, XSize=xsize, Value=value
>
> but if I want it to launch when i click a button, the code (and i'm assuming this is how i would call it):
> w_userRoi= widget_button(p,value = 'Get User Defined ROI',frame = 2,$
> event_func = 'textbox')
> wouldn't have anywhere to input the various arguments. How would I put those in the function? (i tried taking them all out and calling it that way, but I'm still getting an "incorrect number of arguments" error"). But either way, I do want to have at least one argument.

Event handler routines (what you are defining with the EVENT_FUNC or
EVENT_PRO keywords) are all written in exactly the same way: with one
and only one parameter, which is the event structure that the window
manager passes to it. In general, you never call event handlers
yourself. They are called for you.

What you *do* in an event handler is entirely up to you.
You could, for example, call any other IDL procedure or
function you wanted to, including those that implement
other widget programs. You can pass these IDL procedures
and functions any variables that you have defined in the
context of the procedure or function, via either arguments
or keywords.

> Also, do I even need all those?

You need whatever makes sense for the program you are calling.
That's all you need.

> All I want the function to use is the uservalues of the original
widget (since I want to do stuff with those), and I guess the Cancel
variable. But then there's the issue of not knowing how to call the
function correctly.

You call it exactly like you would call any other function in IDL,
passing appropriate arguments and keywords.

> Finally, where does my return value save to? Would it be w_userRoi, or somewhere else?

If it is information that is only going to be used in that
event handler module, you don't have to save it anywhere. Just
use it. If it is information that you are going to need to run
your program, then you save it in the info structure will all
the other stuff you need to run your program.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: widget event structure doesn't transfer [message #81138 is a reply to message #81051] Tue, 14 August 2012 14:30 Go to previous message
Oana Coman is currently offline  Oana Coman
Messages: 27
Registered: December 2011
Junior Member
Hi,
I have the book and it's definitely my go-to widget guide. I have a bit of an idea how to run normal widgets using procedures but once I try to figure out the functions and these popup dialogs it's like a whole new ballgame (I am also a little slow haha so I'm sure that doesn't help). I've looked at the Pop-up Dialog page a lot and though I get the overall idea, I'm not sure how to carry it out.

For example, textbox is defined:
FUNCTION TextBox, Title=title, Label=label, Cancel=cancel, $
Group_Leader=groupleader, XSize=xsize, Value=value

but if I want it to launch when i click a button, the code (and i'm assuming this is how i would call it):
w_userRoi= widget_button(p,value = 'Get User Defined ROI',frame = 2,$
event_func = 'textbox')
wouldn't have anywhere to input the various arguments. How would I put those in the function? (i tried taking them all out and calling it that way, but I'm still getting an "incorrect number of arguments" error"). But either way, I do want to have at least one argument.

Also, do I even need all those? All I want the function to use is the uservalues of the original widget (since I want to do stuff with those), and I guess the Cancel variable. But then there's the issue of not knowing how to call the function correctly.

Finally, where does my return value save to? Would it be w_userRoi, or somewhere else?

Thanks for the help.





On Tuesday, August 14, 2012 6:22:29 AM UTC-7, David Fanning wrote:
> Kat writes:
>
>
>
>> When I try to call my userROI data in widget 1, I get:
>
>> % WIDGET_CONTROL: Invalid widget identifier: 143.
>
>>
>
>>
>
>> Do you have any thoughts on this? Where did I go wrong?
>
>
>
> Well, it appears you have gone wrong almost from the get-go. :-)
>
>
>
> Mostly what I think you need to know is that IDL doesn't
>
> suspend it's rules about local variables being protected
>
> inside of procedures and functions just because you are
>
> writing a widget program. Widget identifiers are local
>
> variables. (This is your immediate problem, but there
>
> are many others, too.)
>
>
>
> You might want to read up on widget programming a bit.
>
> IDL Programming Techniques is *very* old and outdated,
>
> but the widget section is still pretty good. If you
>
> could find a copy of that, it would help you a great
>
> deal, I think.
>
>
>
> If you want to call a second widget program to provide
>
> information to the first, we call that a "pop-up" or
>
> "dialog" widget. It is written as a function that returns
>
> data (usually in the form of a structure) to the calling
>
> program. You can read more about how to write it here:
>
>
>
> http://www.idlcoyote.com/widget_tips/popup.html
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: widget event structure doesn't transfer [message #81146 is a reply to message #81051] Tue, 14 August 2012 06:22 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Kat writes:

> When I try to call my userROI data in widget 1, I get:
> % WIDGET_CONTROL: Invalid widget identifier: 143.
>
>
> Do you have any thoughts on this? Where did I go wrong?

Well, it appears you have gone wrong almost from the get-go. :-)

Mostly what I think you need to know is that IDL doesn't
suspend it's rules about local variables being protected
inside of procedures and functions just because you are
writing a widget program. Widget identifiers are local
variables. (This is your immediate problem, but there
are many others, too.)

You might want to read up on widget programming a bit.
IDL Programming Techniques is *very* old and outdated,
but the widget section is still pretty good. If you
could find a copy of that, it would help you a great
deal, I think.

If you want to call a second widget program to provide
information to the first, we call that a "pop-up" or
"dialog" widget. It is written as a function that returns
data (usually in the form of a structure) to the calling
program. You can read more about how to write it here:

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

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to prevent proliferation of leftover objects when NG plots are included in unit tests.
Next Topic: multiple contour plots with common color range

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

Current Time: Wed Oct 08 13:47:55 PDT 2025

Total time taken to generate the page: 0.00582 seconds