Select to view content in your preferred language

How can I programatically deactivate my python addin tool?

3134
23
08-31-2016 08:48 AM
GregoryAllspaw
Occasional Contributor

How can I programatically deactivate my python addin tool at the end of tool execution?  In other words, I want to select my tool, click the map to execute my script logic, and then I want the tool to automatically deactivate or select a different tool by default.  Is this possible?  I'm currently working in ArcGIS 10.2, but I'm planning  to move on to 10.4, if this matters.

Tags (2)
0 Kudos
23 Replies
GregoryAllspaw
Occasional Contributor

Yes, I'm using a tool class.  It is a tool that is used to click once on the map, and then the script uses the mousedown point to execute some code.  I would like for the last action of the code to be the deactivation of the tool.  If the user wanted to click another point using this tool they would have to reselect the tool from the toolbar.  As it stands right now, the tool remains active and the user can click the map as many times as they want.  This would be fine if it were not for the conflict with the tikinter dialog that is launched from several other buttons (not tools).  Clicking a button does not deactivate a tool...at least, not automatically.  I would love to know how to code that, if possible.  I'm not necessarily against the tool staying active, but it isn't necessary in most circumstances and I'm just trying to eliminate the conflict with my other addin items.

0 Kudos
NobbirAhmed
Esri Regular Contributor

Here is an idea – just tried and it works for me.

In any of the methods of the Tool class, such as OnDblClick, write this line of code:

self.enabled = False

So, whenever you want to deactivate the tool, just double-click anywhere on the map.

I’m still trying to figure out how can I activate it back. If you have any other button or tool you can use one of those methods to enable it to True. I’ll get back once I get a solution.

0 Kudos
GregoryAllspaw
Occasional Contributor

Nobbir, I really appreciate your help on this, but we are still having a miscommunication.  I don't want to disable the tool...I want to deactivate it.  These are two different things.  I still want the user to be able to select the tool whenever they want. I just don't want it to be left as the active tool after they click the map.  After they click the map with this tool, they will be briefly handling the result of clicking the tool (which does not logically include selecting a different tool), and then they will be moving on to something else entirely....which is likely to include clicking one of the buttons that initiates a tkinter dialog.  I could, of course, instruct my users to make sure they select a different tool before moving on (selecting any esri standard tool would do the trick and produce the desired result).  However, I think this is kind of a ridiculous thing to ask of my users...they are going to forget, and it is going to keep crashing when they do.  Nobody is accustomed to a GUI that insists that you 'unpress' one button before you press another....that should be handled by the coding behind the GUI.

0 Kudos
NobbirAhmed
Esri Regular Contributor

Greg – I understand your problem. Right now I don’t see any other way to “deactivate”. The deactivate method in Tool class is only triggered when the tool is disabled. I’m end of my ideas ☹

Please share with us if you find a good way to achieve your goal.

0 Kudos
DanPatterson_Retired
MVP Emeritus

going back to my original comment, perhaps it needs to become 'deactivated' rather than 'deactivate' a small but subtle difference in meaning, so perhaps a note to the linking page, asking for elaboration on what it actually does would go a long way... I will leave it in the hands of those still active on deactivate

0 Kudos
GregoryAllspaw
Occasional Contributor

Nobbir and Dan, thanks for your prompt attention to my post.  I appreciate your time, and I will definitely let you know if I find a solution.

Nobbir, I did toy around with your disabling idea, hoping that I could do something like:

self.enabled = False

self.enabled = True

I was hoping that disabling would kick the active tool to some other tool by default and then enabling again immediately would make my tool available again (but not active)..... but it didn't work.

Dan, I will take your advice and see if I can alert the appropriate people to this issue.

0 Kudos
NobbirAhmed
Esri Regular Contributor

If you haven’t browsed this topic yet ☺

http://desktop.arcgis.com/en/arcmap/latest/analyze/python-addins/managing-the-state-of-add-in-types.htm#GUID-F8454EED-0371-49E9-BFC7-D820B00C62C4

0 Kudos
GregoryAllspaw
Occasional Contributor

Ok, so I'm trying to go the route of temporarily disabling the tool as part of the script execution of one of my other buttons.

The name of my tool class that I'm trying to disable is 'Identify'.

If I add this line to my button script:

Identify.enabled = False

it runs without error, but does nothing.  My Identify tool is still enabled and functioning.

Any thoughts?

0 Kudos
NobbirAhmed
Esri Regular Contributor

Can you message me the config file (located where the makeaddin.py file is)? There might be some name conflict.

0 Kudos
GregoryAllspaw
Occasional Contributor

Nobbir,

Did you receive my config file and have a chance to look at it?

0 Kudos