cursor: check type ?

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

cursor: check type ?

Barth
Hello,


I am trying to use the cursor tools of chaco to get information on a plot.
I developped a new ToolbarButton to place two cursors on a plot. I would
like to make a modification of this button so that if the cursors are
already there, it supresses them.

The current code in the following:

class CursorButton(ToolbarButton):
    label = "Get Cursors"
    tooltip = 'Get Cursors'
    image = 'application-vnd-ms-excel'

    orientation = Enum('v', 'h')
    def perform(self, event):
        img_plot=self.container.component.imgplot[0]

        csr1 = CursorTool(img_plot,drag_button="right",color='blue')
        self.cursor1 = csr1
        csr1.current_position = 1, 1
        img_plot.overlays.append(csr1)

        csr2 = CursorTool(img_plot,drag_button="right",color='white')
        self.cursor2 = csr2
        csr2.current_position = 1, 1
        img_plot.overlays.append(csr2)


The modification i want to make is the following: first, check if there are
already cursors, so that i have to search img_plot.overlays and try to see
if some of its items are cursors:

for item in img_plot.overlays:
     if type(item) is ***:
    ...
    ...

My question is: how can i write the last line "if" so that it gives True if
item is a cursor, and False if not ?
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: cursor: check type ?

Didrik Pinte-2
On Thu, Feb 16, 2012 at 3:04 PM, Pierre Barthelemy <[hidden email]>wrote:

> Hello,
>
>
> I am trying to use the cursor tools of chaco to get information on a plot.
> I developped a new ToolbarButton to place two cursors on a plot. I would
> like to make a modification of this button so that if the cursors are
> already there, it supresses them.
>
> The current code in the following:
>
> class CursorButton(ToolbarButton):
>    label = "Get Cursors"
>    tooltip = 'Get Cursors'
>    image = 'application-vnd-ms-excel'
>
>    orientation = Enum('v', 'h')
>    def perform(self, event):
>        img_plot=self.container.component.imgplot[0]
>
>        csr1 = CursorTool(img_plot,drag_button="right",color='blue')
>        self.cursor1 = csr1
>        csr1.current_position = 1, 1
>        img_plot.overlays.append(csr1)
>
>        csr2 = CursorTool(img_plot,drag_button="right",color='white')
>        self.cursor2 = csr2
>        csr2.current_position = 1, 1
>        img_plot.overlays.append(csr2)
>
>
> The modification i want to make is the following: first, check if there are
> already cursors, so that i have to search img_plot.overlays and try to see
> if some of its items are cursors:
>
> for item in img_plot.overlays:
>     if type(item) is ***:
>    ...
>    ...
>
> My question is: how can i write the last line "if" so that it gives True if
> item is a cursor, and False if not ?
>
>
This should work :

if isinstance(item, CursorTool)

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