Chaco tool order

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Chaco tool order

Fredrik Östlund
Hi

I have a question about chaco. Have a plot with a pan tool and a legend
(obviously a condensed example). The legend has a LegendTool for moving the
legend around. All is nice and pretty. Now, to make things complicated, I
would like both the tools to use the right mouse button. In this case the
pan tool always gets precedence, effectively shutting down the LegendTool.
This seems to be independent of the order the tools are added to the plot.

Is there anyway I can change this behavior, so that the legend moves if the
mouse is right-clicked when over the legend and otherwise the pan-tool gets
selected? I know that I could get around the problem by deactivating the pan
tool temporarily (through a menu or something), but I'm interested in
attacking the problem heads-on since I don't really understand why the pan
tool always gets precendence. (also, I would fully understand if this
question has a pretty low priority...)

best regards

Fredrik Östlund


from enthought.chaco.api import *
from enthought.chaco.tools.api import *
from enthought.traits.api import *
from enthought.traits.ui.api import *
from enthought.enable.component_editor import ComponentEditor
import numpy as np

class MyClass(HasTraits):
    plot = Instance(Plot)
    plot_data = Instance(ArrayPlotData)

    def __init__(self):
        super(MyClass, self).__init__()

        x = np.linspace(0,10,100)
        y = np.sin(x)
        pd = ArrayPlotData(x=x, y=y)
        plot = Plot(pd)
        plot.plot(
            ('x', 'y'),
            color='blue')


        # Add zoom and pan tools
        plot.tools.append(PanTool(plot, drag_button='right'))

        # legend tool
        plot.legend.visible = True
        legendtool = LegendTool(component=plot.legend, drag_button='right' )
        plot.tools.append(legendtool)
        self.plot = plot



    view = View(
        UItem('plot', editor=ComponentEditor()),
        resizable = True
    )




if __name__ == '__main__':
    MyClass().configure_traits()

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco tool order

Peter Wang
On Fri, Oct 22, 2010 at 5:33 AM, Fredrik Östlund
<[hidden email]> wrote:

> I have a question about chaco. Have a plot with a pan tool and a legend
> (obviously a condensed example). The legend has a LegendTool for moving the
> legend around. All is nice and pretty. Now, to make things complicated, I
> would like both the tools to use the right mouse button. In this case the
> pan tool always gets precedence, effectively shutting down the LegendTool.
> This seems to be independent of the order the tools are added to the plot.
>
> Is there anyway I can change this behavior, so that the legend moves if the
> mouse is right-clicked when over the legend and otherwise the pan-tool gets
> selected? I know that I could get around the problem by deactivating the pan
> tool temporarily (through a menu or something), but I'm interested in
> attacking the problem heads-on since I don't really understand why the pan
> tool always gets precendence. (also, I would fully understand if this
> question has a pretty low priority...)
Hi Frederik,

This behavior results from the fact that the PanTool and the
LegendTool, while both appearing to the user as "drag-like" tools, are
actually implemented via two different mechanisms.  The PanTool was
implemented first, and has its own internal logic for handling drag
state, including determining when a drag action actually begins.  The
LegendTool was implemented later and uses the DragTool base class, and
has improved logic for this interaction.  Different subclasses of
DragTool should interact well with each other, because they internally
have a "button-down-but-not-yet-dragging" mode which mitigates the
focus-stealing problem that you are seeing.  However, the PanTool
greedily grabs focus as soon as the mouse goes down, and the
LegendTool never gets a chance to really enter the "dragging" state.

The real fix is to re-implement the PanTool as a subclass of DragTool.
 I have been putting off doing this, but your email has motivated me
to get it done.  I am attaching an initial version of it; please check
it out and put it through its paces, and let me know if you find any
problems.  (It definitely solves the problem you reported above.)
After some testing, I will commit it into trunk as the new PanTool,
and deprecate the old one, renaming it to OldPanTool or something, in
case someone really needs the old event-handling behavior.


Thanks,
Peter

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev

pan_tool2.py (9K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Chaco tool order

bryce hendrix-2
On Fri, Oct 29, 2010 at 11:44 AM, Peter Wang <[hidden email]> wrote:
The real fix is to re-implement the PanTool as a subclass of DragTool.
 I have been putting off doing this, but your email has motivated me
to get it done.  I am attaching an initial version of it; please check
it out and put it through its paces, and let me know if you find any
problems.  (It definitely solves the problem you reported above.)
After some testing, I will commit it into trunk as the new PanTool,
and deprecate the old one, renaming it to OldPanTool or something, in
case someone really needs the old event-handling behavior.


WorsePanTool? ;)

This does remind me, is it about time to retire the SimpleZoomTool and change ZoomTool to use the BetterZoomTool?

Bryce 

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco tool order

Peter Wang
On Fri, Oct 29, 2010 at 11:53 AM, bryce hendrix <[hidden email]> wrote:
> WorsePanTool? ;)
> This does remind me, is it about time to retire the SimpleZoomTool and
> change ZoomTool to use the BetterZoomTool?

Yes.
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco tool order

bryce hendrix-2

On Fri, Oct 29, 2010 at 12:04 PM, Peter Wang <[hidden email]> wrote:
On Fri, Oct 29, 2010 at 11:53 AM, bryce hendrix <[hidden email]> wrote:
> WorsePanTool? ;)
> This does remind me, is it about time to retire the SimpleZoomTool and
> change ZoomTool to use the BetterZoomTool?

Yes.


I'll do it this afternoon, and update the demos where necessary. 

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco tool order

Fredrik Östlund
In reply to this post by Fredrik Östlund
>On Fri, Oct 22, 2010 at 5:33 AM, Fredrik ?stlund
>>[hidden email]> wrote:
>> I have a question about chaco. Have a plot with a pan tool and a legend
>> (obviously a condensed example). The legend has a LegendTool for moving
>> the
>> legend around. All is nice and pretty. Now, to make things complicated, I
>> would like both the tools to use the right mouse button. In this case the
>> pan tool always gets precedence, effectively shutting down the
>> LegendTool.
>> This seems to be independent of the order the tools are added to the
>> plot.
>>
>> Is there anyway I can change this behavior, so that the legend moves if
>> the
>> mouse is right-clicked when over the legend and otherwise the pan-tool
>> gets
>> selected? I know that I could get around the problem by deactivating the
>> pan
>> tool temporarily (through a menu or something), but I'm interested in
>> attacking the problem heads-on since I don't really understand why the
>> pan
>> tool always gets precendence. (also, I would fully understand if this
>> question has a pretty low priority...)
>
>Hi Frederik,
>
>This behavior results from the fact that the PanTool and the
>LegendTool, while both appearing to the user as "drag-like" tools, are
>actually implemented via two different mechanisms.  The PanTool was
>implemented first, and has its own internal logic for handling drag
>state, including determining when a drag action actually begins.  The
>LegendTool was implemented later and uses the DragTool base class, and
>has improved logic for this interaction.  Different subclasses of
>DragTool should interact well with each other, because they internally
>have a "button-down-but-not-yet-dragging" mode which mitigates the
>focus-stealing problem that you are seeing.  However, the PanTool
>greedily grabs focus as soon as the mouse goes down, and the
>LegendTool never gets a chance to really enter the "dragging" state.
>
>The real fix is to re-implement the PanTool as a subclass of DragTool.
>I have been putting off doing this, but your email has motivated me
>to get it done.  I am attaching an initial version of it; please check
>it out and put it through its paces, and let me know if you find any
>problems.  (It definitely solves the problem you reported above.)
>After some testing, I will commit it into trunk as the new PanTool,
>and deprecate the old one, renaming it to OldPanTool or something, in
>case someone really needs the old event-handling behavior.
>
>
>Thanks,
>Peter


Outstanding Peter, that worked like a charm! Fits in my application without
any problems.

Many thanks,
Fredrik

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev