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

Home » Public Forums » archive » Re: How to get windows id or title by clicking on it
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 get windows id or title by clicking on it [message #66881] Thu, 18 June 2009 21:12
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeanphi62 writes:


> With
>
>
> tlb = widget_base(title="mywindow", MBAR=mbar, /col, $
> event_pro='test_function')
>
>
>
> and
>
>
>
> pro test_function, event
> print, "hello"
> end
>
>
>
> There is no "hello" printed when I click on the widget_base...

Well, if this is your code, you don't have any events turned
on for the base widget! ;-)

This code will generate events.

pro test_tlb_events, event
thisEvent = tag_names(event, /structure_name)
Print, thisEvent
end

pro test
tlb = widget_base(title="mywindow", MBAR=mbar, /col, $
/tlb_size_events, $
/tlb_move_events, $
/tlb_kill_request_events)
draw = widget_draw(tlb, xsize=400, ys=400)
widget_control, tlb, /realize
xmanager, 'test', tlb, /no_block, event_handler='test_tlb_events'
end

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to get windows id or title by clicking on it [message #66883 is a reply to message #66881] Thu, 18 June 2009 21:10 Go to previous message
Jeanphi62 is currently offline  Jeanphi62
Messages: 10
Registered: June 2009
Junior Member
All right, it works now
The key was to write :

tlb = widget_base(title="mywindow", MBAR=mbar, /col, $
/tlb_kill_request_events, /kbrd_focus_events)

Thank you very much for your time David. I really appreciated it.

Cheers.

Jeanphi
Re: How to get windows id or title by clicking on it [message #66884 is a reply to message #66883] Thu, 18 June 2009 20:56 Go to previous message
Jeanphi62 is currently offline  Jeanphi62
Messages: 10
Registered: June 2009
Junior Member
With


tlb = widget_base(title="mywindow", MBAR=mbar, /col, $
event_pro='test_function')



and



pro test_function, event
print, "hello"
end



There is no "hello" printed when I click on the widget_base...
Re: How to get windows id or title by clicking on it [message #66885 is a reply to message #66884] Thu, 18 June 2009 20:49 Go to previous message
Jeanphi62 is currently offline  Jeanphi62
Messages: 10
Registered: June 2009
Junior Member
Yes I wrote it in quotes in my source code...
Re: How to get windows id or title by clicking on it [message #66886 is a reply to message #66885] Thu, 18 June 2009 20:45 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeanphi62 writes:

> The way you described to create and call the events doesn't seem to
> work.
> I wrote exactly what you proposed me and it seems that no event is
> linked with the widget_base
> Indeed, I have just added a print, "hello" just at the beginning of
> pro eventhandler, event and IDL doesn't come inside as I click on the
> widget_base...

Did you put the name of the event handler in quotes?
It is a string. You didn't have it in quotes in your
example, but I just assumed you knew to do this.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to get windows id or title by clicking on it [message #66887 is a reply to message #66886] Thu, 18 June 2009 20:40 Go to previous message
Jeanphi62 is currently offline  Jeanphi62
Messages: 10
Registered: June 2009
Junior Member
Thanks for the links.
The way you described to create and call the events doesn't seem to
work.
I wrote exactly what you proposed me and it seems that no event is
linked with the widget_base
Indeed, I have just added a print, "hello" just at the beginning of
pro eventhandler, event and IDL doesn't come inside as I click on the
widget_base...
Re: How to get windows id or title by clicking on it [message #66888 is a reply to message #66887] Thu, 18 June 2009 20:17 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeanphi62 writes:

> tlb = widget_base(title="mywindow", MBAR=mbar, /col, $
> event_pro=eventHandler) ??

It *used* to be the case, although probably not anymore,
that you would get very strange results if you used the
EVENT_PRO keyword to assign an event handler to a widget
that was going to be managed directly by XMANAGER (as
the tlb is here). It still makes me nervous to see it,
although I have seen it in ITTVIS code, too, presumably
without ill effect.

But I still assign the TLB event handler with the EVENT_HANDLER
keyword on the XMANAGER call. Old habits die hard, I guess. :-)

Cheers,

Dav d



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to get windows id or title by clicking on it [message #66889 is a reply to message #66888] Thu, 18 June 2009 20:12 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeanphi62 writes:

> Is that what you mean ?

Yes, that's what I mean. :-)

I can tell you are not building this program using
the IDL Best Practices Manual, but here is an article that
might save you a LOT of time in the future debugging
your programs:

http://www.dfanning.com/tips/namefiles.html

You can see how I've named the routines in a large
widget application by looking, for example, at this
program:

http://www.dfanning.com/programs/xstretch.pro

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to get windows id or title by clicking on it [message #66890 is a reply to message #66889] Thu, 18 June 2009 20:03 Go to previous message
Jeanphi62 is currently offline  Jeanphi62
Messages: 10
Registered: June 2009
Junior Member
How do I create my widget_base then ?
tlb = widget_base(title="mywindow", MBAR=mbar, /col, $
event_pro=eventHandler) ??


and

pro eventHandler, event

thisEventName = Tag_Names(event)
CASE thisEventName OF

'WIDGET_KILL_REQUEST': BEGIN
close_window, event
return
end

'WIDGET_KBRD_FOCUS': BEGIN
test_window, event
return
end


ELSE: Print, 'Yikes. Do not have a clue!!'

ENDCASE

end

Is that what you mean ?
Re: How to get windows id or title by clicking on it [message #66891 is a reply to message #66890] Thu, 18 June 2009 19:53 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeanphi62 writes:

> I have to link the event tlb_kill_request_events with the function
> close_window.pro and the event kbrd_focus_events with the function
> test_window.pro (this function gives me the number of the window) so I
> tried :
>
> tlb = widget_base(title="mywindow", MBAR=mbar, /col, $
> /tlb_kill_request_events, event_pro=close_window, $
> /kbrd_focus_events, event_pro='test_window')
>
> but the software crashes.

No, no. You can only have one event handler for a widget.
When you get into that event handler, you can decide if the
event is a kill request or a keyboard focus event:

thisEventName = Tag_Names(event)
CASE thisEventName OF

'WIDGET_KILL_REQUEST': BEGIN....

'WIDGET_KBRD_FOCUS': BEGIN...

ELSE: Print, 'Yikes. Do not have a clue!!'

ENDCASE

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to get windows id or title by clicking on it [message #66892 is a reply to message #66891] Thu, 18 June 2009 19:44 Go to previous message
Jeanphi62 is currently offline  Jeanphi62
Messages: 10
Registered: June 2009
Junior Member
To sum up :
I have to link the event tlb_kill_request_events with the function
close_window.pro and the event kbrd_focus_events with the function
test_window.pro (this function gives me the number of the window) so I
tried :

tlb = widget_base(title="mywindow", MBAR=mbar, /col, $
/tlb_kill_request_events, event_pro=close_window, $
/kbrd_focus_events, event_pro='test_window')

but the software crashes.

If I just do :
tlb = widget_base(title="mywindow", MBAR=mbar, /col, $
/kbrd_focus_events, event_pro='test_window')
the software obviously doesn't link the will to destroy the widget
with the top right cross button with the function close_window
anymore.

I tried to create parent and child structure :
tlb0 = widget_base(title="mywindow", $
/tlb_kill_request_events, event_pro=close_window)
tlb = widget_base(GROUP_LEADER=tlb0, $
MBAR=mbar, /col, $
/kbrd_focus_events, event_pro='test_window')

but, one more time, IDL only considers the second key word and doesn't
link the will to destroy the widget with the top right cross button
with the function close_window.

So what could I do to link with this widget_base both events ?

Thank you for advance

Cheers

Jeanphi
Re: How to get windows id or title by clicking on it [message #66895 is a reply to message #66892] Thu, 18 June 2009 19:13 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeanphi62 writes:

> Now a now a new problem occurs, my widget_base need to be linked with
> /tlb_kill_request_events
> and the only mean to get the value I wanted previously is to add the
> keywork
> /kbrd_focus_events
>
> But it seems that IDL doesn't like a widget_base with 2 keywords...

What causes you to think that?

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to get windows id or title by clicking on it [message #66896 is a reply to message #66895] Thu, 18 June 2009 18:45 Go to previous message
Jeanphi62 is currently offline  Jeanphi62
Messages: 10
Registered: June 2009
Junior Member
Now a now a new problem occurs, my widget_base need to be linked with
/tlb_kill_request_events
and the only mean to get the value I wanted previously is to add the
keywork
/kbrd_focus_events

But it seems that IDL doesn't like a widget_base with 2 keywords...
Re: How to get windows id or title by clicking on it [message #66897 is a reply to message #66896] Thu, 18 June 2009 18:34 Go to previous message
Jeanphi62 is currently offline  Jeanphi62
Messages: 10
Registered: June 2009
Junior Member
yes !! KBRD_FOCUS_EVENTS works ! Thanks a lot !!!!!
Re: How to get windows id or title by clicking on it [message #66898 is a reply to message #66897] Thu, 18 June 2009 18:24 Go to previous message
Jeanphi62 is currently offline  Jeanphi62
Messages: 10
Registered: June 2009
Junior Member
Actually no.
In fact I am working on multiple screens. So I have one window in one
screen and the other on the other screen.
I need a method which would call a function as soon as I left click on
one of these windows. Then I know how to get the number of the window.
I have found some things when creating the widget_base
There are the keyworks /tlb_move_events or /tlb_iconify_events, and
with these keywords I manage to call a function when I move or iconify
a window. But it seems that there is nothing when we left click on a
window... Is it ?
Re: How to get windows id or title by clicking on it [message #66899 is a reply to message #66898] Thu, 18 June 2009 18:23 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Jeanphi62 writes:

> I work with a GUI which include up to 8 windows which have titles as
> "window 1 window 2 window 3...", and I would like to get the id of the
> window just exposing it (left click on the window) or the best should
> be to get the title of the window by left clicking on it as each one
> of these titles include the number of its window.
> I have already events linked with the drawing area inside of these
> windows, but as the user may avoid to move the mouse over the drawing
> area, I would need to get the event when clicking on the window itself
> (as every body does to put the window to the front-most window of the
> screen)
>
> Is there a simple function such as widget_control, event.top,
> get_window_title=title ??

No really, you can change a window title, but not get it.
Presumably you already know what it is. ;-)

You could set KBRD_FOCUS_EVENTS on your top-level base widgets,
but you couldn't always tell which window you selected. If you
were changing focus to the window, you could tell, or if you
changed focus to another window, you could tell. But if you
clicked a window that already had focus, you wouldn't hear
about that. You might be able to make something like that
work for you.

But, frankly, I've written a LOT of widget applications and
I've never thought I needed anything like this. Are you sure
this can't be solved with a design change?

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: How to get windows id or title by clicking on it [message #66900 is a reply to message #66899] Thu, 18 June 2009 18:16 Go to previous message
dosfun is currently offline  dosfun
Messages: 14
Registered: February 2009
Junior Member
On 6月19日, 上午7时37分, Jeanphi62 <jyjean...@gmail.com> wrote:
> Good morning every one
> I work with a GUI which include up to 8 windows which have titles as
> "window 1 window 2 window 3...", and I would like to get the id of the
> window just exposing it (left click on the window) or the best should
> be to get the title of the window by left clicking on it as each one
> of these titles include the number of its window.
> I have already events linked with the drawing area inside of these
> windows, but as the user may avoid to move the mouse over the drawing
> area, I would need to get the event when clicking on the window itself
> (as every body does to put the window to the front-most window of the
> screen)
>
> Is there a simple function such as widget_control, event.top,
> get_window_title=title ??
>
> I am looking forward to hearing from you !
>
> Thanks a lot !
>
> JeanPhi

widget_control, event.top, set_uvalue = 'window 1'

widget_control, event.top, get_uvalue = windowName

do you mean to something like these?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to get windows id or title by clicking on it
Next Topic: Re: Problems with tying ROI's to image

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

Current Time: Wed Oct 08 15:56:41 PDT 2025

Total time taken to generate the page: 0.01142 seconds