WIDGET ID FINDING FUNCTION [message #41050] |
Thu, 23 September 2004 18:42  |
algosat
Messages: 7 Registered: September 2004
|
Junior Member |
|
|
Im not sure if I am allowed to actually post code here but anyhoo.
The following code is a function for finding widget ids of realized
widgets. Very handy as you dont have to carry around a pointer or
what-not to all of your pop-up windows you get it on demand.
Cheers
Andrew
FUNCTION FIND_WID, UNAME, NOMSG=NOMSG
; NAME:
; FIND_WID
; PURPOSE:
; To find the widget ID of the widget with uname, where uname is a
string
; passed in by the user.
; CATEGORY:
; Widget Utility
; CALLING SEQUENCE:
; RESULT=FIND_WID(UNAME)
; KEYWORDS:
; NOMSG: Use this keyword to to suppress dialog_messge pop-ups
; INPUTS:
; UNAME: A string with the user name of the widget whose ID is sought.
; OUTPUTS:
; The widget ID, if found, of the widget with the user name uname.
; If no widget ID is found a zero is returned to the user.
; RESTRICTIONS:
; The widget must be realized, and managed by xmanager
; EXAMPLE:
;1) you have 2 popups open and you want to use the set
; routine on 1 based on the state in the other, and you are
; in your TLB event handler.
;
; test_id=find_wid('state_widg')
; if test_id ne 0 then popup_set,test_id,state
;
;2) you are using a CW that is a second popup from the main
; TLB, and you have told xmanager that the main TLB
; event handler is to be used. So unless you have passed the
; state information, or a pointer to it, from the tlb->CW->TLB event
handler
; you will have lost the tlb id(well I always did), and hence access
; to the state info. So now you just do the following
;
; test_id=find_wid('main_tlb_uname_or_state_widget_uname')
; if test_id ne 0 then
widget_control,(test_id,/child),get_uvalue=state
;
; The above assumes you are using the first child widget uvalue
; to store the state info.
;
; MODIFICATION HISTORY:
; Written by: Andrew P. Rodger, September 24 2004
test_ids=widget_info(/managed)
;if only one result make sure its not zero
if (n_elements(test_ids) eq 1) then begin
if (test_ids eq 0) then begin
IF NOT KEYWORD_SET(NOMSG) THEN mess=dialog_message('No IDL
managed Widgets are running!',/error)
ret=0L
endif else begin
id=widget_info(test_ids,find_by_uname=uname)
if id eq 0 then begin
IF NOT KEYWORD_SET(NOMSG) THEN mess=dialog_message('No
widgets with the uname '+uname+' could be found',/error)
ret=0L
endif else begin
ret=long(id)
endelse
endelse
endif else begin
;see what windows are opened
ids=lonarr(n_elements(test_ids))
for i=0,n_elements(test_ids)-1 do begin
ids[i]=widget_info(test_ids[i],find_by_uname=uname)
endfor
nz=where(ids ne 0,count)
if (count gt 0) then begin
ret=long(ids[nz[0]]) ;this assumes that only one value is
going to be found
;who knows maby there are more: put in
warning
endif else begin
IF NOT KEYWORD_SET(NOMSG) THEN mess=dialog_message('No
widgets with the uname '+uname+' could be found',/error)
ret=0L
endelse
endelse
return,ret
end
|
|
|
Re: WIDGET ID FINDING FUNCTION [message #41268 is a reply to message #41050] |
Mon, 04 October 2004 06:17  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Andrew Rodger wrote:
>> The PURPOSE of this function is quite the same as you used for yours.
>> id=WIDGET_INFO(event.top,FIND_BY_UNAME='TEXT')
>> you should give here more details, what's the differences are.
>>
>
>
> The main difference between the posted code and the WIDGET_INFO
> function is that the user is not required to specify the event.top id
> only the uname of the widget. I wrote this because I kept losing my
> event.top under a set of various circumstances. Also it did not matter
> where and when you ran the function. You could run it in a pop-up that
> had no connection to the main TLB and still find and pass information.
>
> It worked, I thought it was cool, but in the end I took D. Fannings
> advice and took a closer look at pointers. I still think its a handy
> little tool though.
It is cool!
cheers
Reimar
|
|
|
Re: WIDGET ID FINDING FUNCTION [message #41273 is a reply to message #41050] |
Sun, 03 October 2004 21:23  |
algosat
Messages: 7 Registered: September 2004
|
Junior Member |
|
|
> The PURPOSE of this function is quite the same as you used for yours.
> id=WIDGET_INFO(event.top,FIND_BY_UNAME='TEXT')
> you should give here more details, what's the differences are.
>
The main difference between the posted code and the WIDGET_INFO
function is that the user is not required to specify the event.top id
only the uname of the widget. I wrote this because I kept losing my
event.top under a set of various circumstances. Also it did not matter
where and when you ran the function. You could run it in a pop-up that
had no connection to the main TLB and still find and pass information.
It worked, I thought it was cool, but in the end I took D. Fannings
advice and took a closer look at pointers. I still think its a handy
little tool though.
|
|
|
Re: WIDGET ID FINDING FUNCTION [message #41282 is a reply to message #41050] |
Sun, 03 October 2004 00:28  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Andrew Rodger wrote:
> Im not sure if I am allowed to actually post code here but anyhoo.
>
> The following code is a function for finding widget ids of realized
> widgets. Very handy as you dont have to carry around a pointer or
> what-not to all of your pop-up windows you get it on demand.
>
> Cheers
> Andrew
Dear Andrew
you could post code here if it's not a whole library. You could put it on
your website or on the RSI site and post a link.
The PURPOSE of this function is quite the same as you used for yours.
id=WIDGET_INFO(event.top,FIND_BY_UNAME='TEXT')
you should give here more details, what's the differences are.
from the online help:
WIDGET_INFO:
FIND_BY_UNAME This keyword applies to all widgets. Set this keyword to a
UNAME value that will be searched for in the widget hierarchy, and if a
widget with the given UNAME is in the hierarchy, its ID is returned. The
search starts in the hierarchy with the given widget ID and travels down,
and this keyword returns the widget ID of the first widget that has the
specified UNAME value. If a widget is not found, 0 is returned.
cheers
Reimar
>
> FUNCTION FIND_WID, UNAME, NOMSG=NOMSG
> ; NAME:
> ; FIND_WID
> ; PURPOSE:
> ; To find the widget ID of the widget with uname, where uname is a
> string
> ; passed in by the user.
> ; CATEGORY:
> ; Widget Utility
> ; CALLING SEQUENCE:
> ; RESULT=FIND_WID(UNAME)
> ; KEYWORDS:
> ; NOMSG: Use this keyword to to suppress dialog_messge pop-ups
> ; INPUTS:
> ; UNAME: A string with the user name of the widget whose ID is sought.
> ; OUTPUTS:
> ; The widget ID, if found, of the widget with the user name uname.
> ; If no widget ID is found a zero is returned to the user.
> ; RESTRICTIONS:
> ; The widget must be realized, and managed by xmanager
> ; EXAMPLE:
> ;1) you have 2 popups open and you want to use the set
> ; routine on 1 based on the state in the other, and you are
> ; in your TLB event handler.
> ;
> ; test_id=find_wid('state_widg')
> ; if test_id ne 0 then popup_set,test_id,state
> ;
> ;2) you are using a CW that is a second popup from the main
> ; TLB, and you have told xmanager that the main TLB
> ; event handler is to be used. So unless you have passed the
> ; state information, or a pointer to it, from the tlb->CW->TLB event
> handler
> ; you will have lost the tlb id(well I always did), and hence access
> ; to the state info. So now you just do the following
> ;
> ; test_id=find_wid('main_tlb_uname_or_state_widget_uname')
> ; if test_id ne 0 then
> widget_control,(test_id,/child),get_uvalue=state
> ;
> ; The above assumes you are using the first child widget uvalue
> ; to store the state info.
> ;
> ; MODIFICATION HISTORY:
> ; Written by: Andrew P. Rodger, September 24 2004
> test_ids=widget_info(/managed)
> ;if only one result make sure its not zero
> if (n_elements(test_ids) eq 1) then begin
> if (test_ids eq 0) then begin
> IF NOT KEYWORD_SET(NOMSG) THEN mess=dialog_message('No IDL
> managed Widgets are running!',/error)
> ret=0L
> endif else begin
> id=widget_info(test_ids,find_by_uname=uname)
> if id eq 0 then begin
> IF NOT KEYWORD_SET(NOMSG) THEN mess=dialog_message('No
> widgets with the uname '+uname+' could be found',/error)
> ret=0L
> endif else begin
> ret=long(id)
> endelse
> endelse
> endif else begin
> ;see what windows are opened
> ids=lonarr(n_elements(test_ids))
> for i=0,n_elements(test_ids)-1 do begin
> ids[i]=widget_info(test_ids[i],find_by_uname=uname)
> endfor
> nz=where(ids ne 0,count)
> if (count gt 0) then begin
> ret=long(ids[nz[0]]) ;this assumes that only one value is
> going to be found
> ;who knows maby there are more: put in
> warning
> endif else begin
> IF NOT KEYWORD_SET(NOMSG) THEN mess=dialog_message('No
> widgets with the uname '+uname+' could be found',/error)
> ret=0L
> endelse
> endelse
> return,ret
> end
--
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
|
|
|