6

I have not been able to figure out how the deactivate function of a Python Add-in Tool works in ArcGIS.

The help page that mentions the function, and that it 'causes the tool to no longer be the active tool' is here: http://resources.arcgis.com/en/help/main/10.1/index.html#/Tool/014p00000027000000/. I cannot find any examples of it being used.

The Tool class looks like this:

class ExampleTool(object):
    """Implementation for Example_addin.tool1 (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE"
    def onMouseDownMap(self, x, y, button, shift):
        # My code here, then..
        self.deactivate()
    def deactivate(self):
        # Do I need to add something here..?

The help file seems to imply that when the function is called, the tool will deactivate / lose focus, but maybe I need to add something to the function to make that happen..?

  • What happens when you click on another tool? by the looks of the onMouseDownMap it will just deactivate the tool which probably doesn't need to do anything. – user681 Aug 13 '14 at 9:36
  • onMouseDownMap will have a bunch of other code for whatever it is designed to do, and then finally self.deactivate(). When I click another tool, it deactivates. I guess I thought the deactivate function was provided so that you could manipulate when deactivation occurs. – XIY Aug 13 '14 at 10:50
  • You can use the extensions to listen for a specific event that would in turn make your tool no longer function, i.e. buttons on the toolbar would be greyed out. – F_Kellner Oct 10 '14 at 22:56
3

I found the answer here:

deactivate() is not a function that's intended for you (the programmer) to leverage. It's a function leveraged by the application so that ESRI tools can deactive it when they are selected. Otherwise, you'd never be able to select another tool.

In order to do what you're trying to do, you'd also need some sort of activate() function in order to default back to another tool like the cursor or pan tool because one tool always has to be active. Currently, there is no programmatic way to switch between tools that I know of.

-2

i think is ...

class ExampleTool(object):

    """Implementation for Example_addin.tool1 (Tool)"""

    def __init__(self):
        self.enabled = True
        self.shape = "NONE"

    def onMouseDownMap(self, x, y, button, shift):
        # My code here, then..

        self.enabled = False

    def deactivate(self):
        # Do I need to add something here..?
  • You think it is what? – Jason Scheirer Oct 10 '14 at 22:26
  • self.enabled = False – Ivan Villar Oct 13 '14 at 14:52
  • No, that disables the tool. I thought I could deactivate the tool (cause it to lose focus), which is different to disabling. – XIY Oct 21 '14 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.