Re: problems with passing structures around in gui widgets [message #40399] |
Thu, 05 August 2004 13:53 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Jeff Guerber writes:
> Naah. You just always reference "(*info)" (including parentheses!)
> instead of just "info". Everything else stays the same:
>
> *info.data = BytArr(50, 100)
> *(*info).data = BytArr(50, 100)
I suppose. But when I read my code I think it looks
like a Beetle Bailey cartoon with Sarge yelling at
the troops. "Beetle, you *&%* nincompoop!"
> (Well, that's what I _used_ to do, until I learned how to do all this
> in objects. Now it's just "self", and I don't have to check it in OR out.
> Wooo!)
Yes, it is a natural progression, isn't it? You would
love my library, where even the widgets are objects.
Sometimes I think I have completely forgotten how
to write a *real* widget program. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: problems with passing structures around in gui widgets [message #40400 is a reply to message #40399] |
Thu, 05 August 2004 13:14  |
Jeff Guerber
Messages: 41 Registered: July 2000
|
Member |
|
|
On Thu, 5 Aug 2004, David Fanning wrote:
> M. Katz writes:
>
>> That's true unless the UVALUE is also a pointer. In which case you
>> don't have to "check it back" when you're done with the event handler.
>> I've found out the hard way that checking-out the state variable and
>> checking it back later can lead to some nasty conflicts when you have
>> event-driven code, multiple things going on at once, and significant
>> subroutines called from the event handler.
>
> Well, by making it a pointer I think you trade
> errors in logic for errors in syntax. :-)
Naah. You just always reference "(*info)" (including parentheses!)
instead of just "info". Everything else stays the same:
*info.data = BytArr(50, 100)
*(*info).data = BytArr(50, 100)
That's what I do. (Although instead of "info" I like to call it "statep"
(pointer to state).)
(Well, that's what I _used_ to do, until I learned how to do all this
in objects. Now it's just "self", and I don't have to check it in OR out.
Wooo!)
Jeff Guerber
* I don't speak for NASA or Raytheon! *
|
|
|
Re: problems with passing structures around in gui widgets [message #40410 is a reply to message #40400] |
Thu, 05 August 2004 10:03  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
M. Katz writes:
> That's true unless the UVALUE is also a pointer. In which case you
> don't have to "check it back" when you're done with the event handler.
> I've found out the hard way that checking-out the state variable and
> checking it back later can lead to some nasty conflicts when you have
> event-driven code, multiple things going on at once, and significant
> subroutines called from the event handler.
Well, by making it a pointer I think you trade
errors in logic for errors in syntax. :-)
Cheers,
David
P.S. Let's just say I've written enough programs
with NO_COPYs to know the method works. :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: problems with passing structures around in gui widgets [message #40411 is a reply to message #40410] |
Thu, 05 August 2004 09:56  |
MKatz843
Messages: 98 Registered: March 2002
|
Member |
|
|
David Fanning <davidf@dfanning.com> wrote
> The standard rule is to check the info structure
> out at the top of the event handler, and check it
> back in before you exit the event handler:
That's true unless the UVALUE is also a pointer. In which case you
don't have to "check it back" when you're done with the event handler.
I've found out the hard way that checking-out the state variable and
checking it back later can lead to some nasty conflicts when you have
event-driven code, multiple things going on at once, and significant
subroutines called from the event handler.
M. Katz
|
|
|
|
Re: problems with passing structures around in gui widgets [message #40417 is a reply to message #40412] |
Thu, 05 August 2004 08:38  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Reimar Bauer writes:
> How often do you have answered this ?
Well, enough times to get me over the activation curve
to write a book. :-)
Cheers,
David
P.S. Let's just say if the frequency of iTools questions
increases only a bit more, I might just get over the hump
and write some documentation for this Catalyst Library. :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: problems with passing structures around in gui widgets [message #40418 is a reply to message #40417] |
Thu, 05 August 2004 06:30  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
How often do you have answered this ?
Cheers
Reimar
David Fanning wrote:
> RS writes:
>
>> I'm writing a GUI to streamline some data reductions and have run into
>> two problems passing information from the main program to the event
>> handler and back:
>>
>> 1) I can't reassign arrays to arrays of different size.
>> I have created a 1x1 array (as close to empty as IDL could get-- [0])
>> in the main (base widget) that I want to assign 1024x1024 or 1024x160
>> values during event handler calls. However, IDL won't write a larger
>> array over a smaller one in this case, even though it will at the
>> command line... ex:
>> a=indgen(1,1,1)
>> a=indgen(2,2,2)
>>
>> 2) I can only access (& change) the data from the main once and then
>> IDL spews back this message:
>> % Expression must be a structure in this context: INFO.
>> % Execution halted at: INTERFACE_EVENT 16
>> % WIDGET_PROCESS_EVENTS
>> % $MAIN$
>> Which is great, except that info IS a structure that I'm using in the
>> main to contain everything I want to be able to alter during the
>> events and setting it to be the uvalue of the top-level base. So, I
>> can load the data, but not perform any operations on it, because that
>> would require calling a second event. Peachy.
>>
>> Any ideas as to workarounds?
>
> Oh, dear. You need a book. :-)
>
> When something in a structure is changing (either size or data type)
> we make that field a pointer:
>
> info = { name:'Coyote', data:Ptr_New(/Allocate_Heap)}
>
> Then, you can put whatever you like into it:
>
> *info.data = FltArr(10)
> *info.data = BytArr(50, 100)
>
> Be sure to free you pointer in your CLEANUP procedure.
> What!? You don't have a clean up procedure? Better read
> the documentation on the XMANAGER command. :-)
>
> PRO Myprogram_Cleanup, tlb
> Widget_Control, tlb, Get_UValue=info
> Ptr_Free, info.data
> END
>
> The most common reason for your error message is
> that you took the info structure out of your TLB with
> a NO_COPY and forgot to put it back before you left
> that event handler. This means you can process one
> event, but no more.
>
> The standard rule is to check the info structure
> out at the top of the event handler, and check it
> back in before you exit the event handler:
>
> PRO MyProgram_Events, event
> Widget_Control, event.top, Get_UValue=info, /No_Copy
>
> info.data = blahblahblah
>
> Widget_Control, event.top, Set_UValue=info, /No_Copy
> END
>
> Cheers,
>
> David
>
>
>
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|
Re: problems with passing structures around in gui widgets [message #40435 is a reply to message #40418] |
Wed, 04 August 2004 13:11  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
RS writes:
> I'm writing a GUI to streamline some data reductions and have run into
> two problems passing information from the main program to the event
> handler and back:
>
> 1) I can't reassign arrays to arrays of different size.
> I have created a 1x1 array (as close to empty as IDL could get-- [0])
> in the main (base widget) that I want to assign 1024x1024 or 1024x160
> values during event handler calls. However, IDL won't write a larger
> array over a smaller one in this case, even though it will at the
> command line... ex:
> a=indgen(1,1,1)
> a=indgen(2,2,2)
>
> 2) I can only access (& change) the data from the main once and then
> IDL spews back this message:
> % Expression must be a structure in this context: INFO.
> % Execution halted at: INTERFACE_EVENT 16
> % WIDGET_PROCESS_EVENTS
> % $MAIN$
> Which is great, except that info IS a structure that I'm using in the
> main to contain everything I want to be able to alter during the
> events and setting it to be the uvalue of the top-level base. So, I
> can load the data, but not perform any operations on it, because that
> would require calling a second event. Peachy.
>
> Any ideas as to workarounds?
Oh, dear. You need a book. :-)
When something in a structure is changing (either size or data type)
we make that field a pointer:
info = { name:'Coyote', data:Ptr_New(/Allocate_Heap)}
Then, you can put whatever you like into it:
*info.data = FltArr(10)
*info.data = BytArr(50, 100)
Be sure to free you pointer in your CLEANUP procedure.
What!? You don't have a clean up procedure? Better read
the documentation on the XMANAGER command. :-)
PRO Myprogram_Cleanup, tlb
Widget_Control, tlb, Get_UValue=info
Ptr_Free, info.data
END
The most common reason for your error message is
that you took the info structure out of your TLB with
a NO_COPY and forgot to put it back before you left
that event handler. This means you can process one
event, but no more.
The standard rule is to check the info structure
out at the top of the event handler, and check it
back in before you exit the event handler:
PRO MyProgram_Events, event
Widget_Control, event.top, Get_UValue=info, /No_Copy
info.data = blahblahblah
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|