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

Home » Public Forums » archive » Tip for using Compound Widgets
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
Tip for using Compound Widgets [message #31710] Sat, 03 August 2002 12:03 Go to next message
MKatz843 is currently offline  MKatz843
Messages: 98
Registered: March 2002
Member
I do a lot of widget programming in IDL, and I've recently come across
an elegant solution I'd like to share. Others have probably already
thought of this, or may have a better idea, so I hope I'll start a
dialog.

Suppose you have a complex compound widget with lots of differnt
functions. You want to tell it to do all kinds of things, but you
don't want to lose that "black box" aspect that makes cw_widgets so
powerful.

So for each differnt thing I want the widget to do, I encode the
command in the name of a structure and then pass that as a SET_VALUE
in a WIDGET_CONTROL as follows:

WIDGET_CONTROL, cw_ID, SET_VALUE={COMMAND_TYPE, arg1:val1, arg2:val2,
. . . }

so it might look like one of these:

WIDGET_CONTROL, cw_ID, SET_VALUE={NEW_IMAGE, img_ptr:ptr_new(image)}
WIDGET_CONTROL, cw_ID, SET_VALUE={SET_RANGE, range:[0, 16383]}
WIDGET_CONTROL, cw_ID, SET_VALUE={REFRESH_DISPLAY,
VIEWPLANE_RECT=[0,0,10,20]}

In order to make this work, a few things are required. Here are some
details.

1) The compound widget function is defined with a SET_VALUE routine.
That is, the first base you declare has a SET_VALUE explicitly set to
a routine that you're using to interpret these commands.

2) I use the IDL-recommended trick of storing a state variable
(generally a big structure with widget IDs and object pointers to
everything that needs to be changed) in the UVALUE of the first child
widget of the main base. I created a function and a procedure to get
and set the first child's UVALUE in one command (see below).
IMPORTANT NOTE: If you use this method, don't forget that every time
you update the state variable, you have to *save it* in the UVALUE of
the base's first child. Otherwise changes could be lost. So every call
of
"state = first_child_uvalue(id)" should be followed by a
"first_child_set_uvalue, base, state".

3) The compound widget's set_value procedure may look like this

;-----------
; Procedure to execute commands sent by SET_VALUE keyword to
WIDGET_CONTROL
;
pro cw_test_set_value, base, arg
state = first_child_uvalue(base, /NO_COPY) ;--- retrieve state
variable. Use NO_COPY for speed.

if size(arg, /type) NE 8 then return ;--- verify that it's a
structure
case struct_name(arg) of
'NEW_IMAGE': begin
. . .
end
'SET_RANGE': begin
. . .
end
'REFRESH_DISPLAY': begin
. . .
end
else: print, 'Unknown command in cw_test_set_value'
endcase

first_child_set_uvalue, base, state, /NO_COPY ;--- store state
variable. Very Important!

return
end

4) The following functions are convenient to use for the above.

;-----------
; Return the name of a structure variable
;
function struct_name, a
return, (size(a, /type) EQ 8) ? tag_names(a, /STRUCTURE_NAME) : ''
end

;-----------
; Return the contents of the UVALUE of the first child of base.
;
function first_child_uvalue, base, NO_COPY=NO_COPY
if not widget_info(base, /VALID_ID) then return, 0
first_child = widget_info(base, /CHILD)
if not widget_info(first_child, /VALID_ID) then return, 0
widget_control, first_child, GET_UVALUE=uval, NO_COPY=NO_COPY
return, uval
end

;-----------
; Set the contents of the UVALUE of the first child of base.
;
pro first_child_set_uvalue, base, uval, NO_COPY=NO_COPY
if not widget_info(base, /VALID_ID) then return
first_child = widget_info(base, /CHILD)
if not widget_info(first_child, /VALID_ID) then return
widget_control, first_child, SET_UVALUE=uval, NO_COPY=NO_COPY
end

I'd be interested to know if anyone else uses tricks like this, or has
a better way,

M. Katz
Re: Tip for using Compound Widgets [message #31942 is a reply to message #31710] Thu, 29 August 2002 11:57 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paul van Delst (paul.vandelst@noaa.gov) writes:

> My $0.02... go with the second option. You're already famous. :o)

You must know my wife. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Tip for using Compound Widgets [message #31943 is a reply to message #31710] Thu, 29 August 2002 11:36 Go to previous messageGo to next message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
David Fanning wrote:
>
> We are torn, at the moment, between wanting to become
> famous by writing a book that explains all this, or
> to become rich by writing programs with the system.

My $0.02... go with the second option. You're already famous. :o)

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
Ph: (301)763-8000 x7274
Fax:(301)763-8545
Re: Tip for using Compound Widgets [message #31945 is a reply to message #31710] Thu, 29 August 2002 10:51 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Rob Preece (Rob.Preece@msfc.nasa.gov) writes:

> Good grief! You are *this* close to creating a 'command macro' language
> for your widget objects (something I have been thinking about for some
> time, I might add!). All that is needed is a way to store lists of
> commands, so that they could be replayed at any time. It would be nice to
> edit, store and recall these lists. Finally, think about a *recordable*
> widget program: hit a button, and the following user actions are saved as
> a list of commands, to be available for later replay...

I think you are talking about my LinkedList object
and the LinkedList editor, that is built, but not
available to the public. :-)

Actually, the system we are building does all the
things you mention and more. To "process" an image,
we store "process" objects in its container. You
can add them, remove them, change their order, etc.

We are torn, at the moment, between wanting to become
famous by writing a book that explains all this, or
to become rich by writing programs with the system.
I'll let you know the next time you are in Fort
Collins. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Tip for using Compound Widgets [message #32014 is a reply to message #31710] Tue, 03 September 2002 10:01 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Pavel A. Romashkin (pavel_romashkin@hotmail.com) writes:

> David Fanning wrote:
>>
>> I'll let you know the next time you are in Fort
>> Collins. :-)
>
> Alas, this does not work. Tried it, but the Coyote found his way out of
> the trap :-(

Sorry, I should have said "the next time you are in Fort
Collins and I don't have high school tennis practice,
my own league tennis match, back to school night, and
my nephew's birthday party all scheduled on the same
night." :-)

Cheers,

David

P.S. Let's just say missing Back to School night
to play tennis is considered BAD JUDGEMENT by certain
people around here. :-(

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Tip for using Compound Widgets [message #32015 is a reply to message #31945] Tue, 03 September 2002 09:20 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
David Fanning wrote:
>
> I'll let you know the next time you are in Fort
> Collins. :-)

Alas, this does not work. Tried it, but the Coyote found his way out of
the trap :-(
Pavel
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: OG polygon to EPS problem
Next Topic: dynamically linking a C file

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

Current Time: Wed Oct 08 18:53:22 PDT 2025

Total time taken to generate the page: 0.00429 seconds