Re: widget_control and event generation [message #53391] |
Sun, 15 April 2007 17:52  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
pdoherty writes:
> It's as if the system thinks I have clicked on one of the tabs even
> though all I have done is selected a new tab using widget_control.
On closer inspection, this looks like what does in fact happen.
When I switch to a new tab programmatically with WIDGET_CONTROL
I *do* get a tab widget event in the event handler.
I guess this makes sense because I would like to know
when I switch to another window, generally, so I can
update the window contents, etc.
I do notice in my example, at least, I can suppress
the tab event if I do something like this:
widget_control, widget, set_tab_current=7
widget_control, widget, /clear_events
I thought I might need a short wait between commands,
so I didn't clear the stack before the event was placed
on it, but at least on my machine, it doesn't appear to
be needed.
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: widget_control and event generation [message #53393 is a reply to message #53391] |
Sun, 15 April 2007 12:43   |
pdoherty
Messages: 8 Registered: April 2007
|
Junior Member |
|
|
On Apr 15, 4:15 pm, David Fanning <n...@dfanning.com> wrote:
> pedohe...@earthlink.net writes:
>> When I use the following code to switch the currently selected tab in
>> a widget_tab:
>
>> widget = widget_info(info.tlb, find_by_uname='plot_tab')
>> oldtab = widget_info(widget, /tab_current)
>> widget_control, widget, set_tab_current=7
>
>> Do I generate an event?
>
> No, you don't generate an event. But I could believe that
> if you are using a button click to switch tabs that you
> may not be accounting for both the button DOWN and the button
> UP event in your event handler.
That's what I thought. The general idea is that if I press the right
mouse
button the plot_tab switches to a different tab, makes some plots as I
move
the cursor around, and then when I release the right button the tab
switches
back to the original tab. Here's the relevant code (edited) :
; handle right button press events
if ((event.type EQ 0) AND (event.press EQ 4)) then begin
info.mouse_right_down = 1
widget = widget_info(info.tlb, find_by_uname='plot_tab')
info.oldtab = widget_info(widget, /tab_current)
widget_control, widget, set_tab_current=7
endif
; handle right button release events
if ((event.type EQ 1) AND (event.release EQ 4)) then begin
info.mouse_right_down = 0
widget = widget_info(info.tlb, find_by_uname='plot_tab')
widget_control, widget, set_tab_current=info.oldtab
endif
I think I have taken into account DOWN vs UP events. What's strange is
that when I push the button DOWN, and before I release, my event
handler
catches an event for the widget with the uvalue = 'plot_tab', as in
widget_control, event.id, get_uvalue=widget
case widget of
'plot_tab' : ccd_plots, info
etc...
It's as if the system thinks I have clicked on one of the tabs even
though
all I have done is selected a new tab using widget_control.
No doubt, it's my fault. Computers always do what we tell them to do
(the
bas****s). It's just that I don't understand that I've told it to do
this.
- Peter Doherty
|
|
|
Re: widget_control and event generation [message #53394 is a reply to message #53393] |
Sun, 15 April 2007 13:15   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
pedoherty@earthlink.net writes:
> I won't describe the problem I'm having here in any great detail, it
> would take
> too many lines of text. I think (though I may be wrong) that I've
> narrowed the
> problem down. Here's my question:
>
> When I use the following code to switch the currently selected tab in
> a widget_tab:
>
> widget = widget_info(info.tlb, find_by_uname='plot_tab')
> oldtab = widget_info(widget, /tab_current)
> widget_control, widget, set_tab_current=7
>
> Do I generate an event?
No, you don't generate an event. But I could believe that
if you are using a button click to switch tabs that you
may not be accounting for both the button DOWN and the button
UP event in your event handler.
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: widget_control and event generation [message #53539 is a reply to message #53391] |
Sun, 15 April 2007 21:00  |
pdoherty
Messages: 8 Registered: April 2007
|
Junior Member |
|
|
On Apr 15, 8:52 pm, David Fanning <n...@dfanning.com> wrote:
> pdoherty writes:
>> It's as if the system thinks I have clicked on one of the tabs even
>> though all I have done is selected a new tab using widget_control.
>
> On closer inspection, this looks like what does in fact happen.
> When I switch to a new tab programmatically with WIDGET_CONTROL
> I *do* get a tab widget event in the event handler.
>
> ...
>
> I do notice in my example, at least, I can suppress
> the tab event if I do something like this:
>
> widget_control, widget, set_tab_current=7
> widget_control, widget, /clear_events
That's exactly what I have found, and what I have done to solve the
"problem". I also agree with what you wrote about it making some
sense in that it might be nice for the event handler to know that
the window has changed, in case there's something that needs doing.
So, while the behavior is logical enough, it was a little bit of
a surprise and took me a while to figure out.
Thank you for your help on this.
Peter Doherty
|
|
|