Can't Disable Python Addin Tool in Toolbar

2602
2
03-13-2014 10:27 AM
BrendanQuigley
New Contributor II
I can't get this code to grey out googletool when I switch to layout view.

I have watched the video copied the example code in the help files and read about it. I must be missing something.

I also tried to with print "Change" after def activeViewChanged(self): but nothing appeared in the python prompt in Arcgis when i switched from data view to layout view.

My googletool wont work in data view so I wanted to disable it.

Caption: Google Maps
Class Name: googlemaps
ID:My_addin.googletool


Any thoughts?
class activeview(object):
    """Implementation for MY_addin.extension24 (Extension)"""
    def __init__(self):
        # For performance considerations, please remove all unused methods in this class.
        self.enabled = True
    def activeViewChanged(self):
        mxd = arcpy.mapping.MapDocument('current')
        active_view = mxd.activeView
        # tool1 is the tool ID (without the namespace prefix)
        if active_view == 'PAGE_LAYOUT':
            googletool.enabled = False
        else:
            googletool.enabled = True
        arcpy.RefreshActiveView()
        return
Tags (2)
0 Kudos
2 Replies
T__WayneWhitley
Frequent Contributor
Sounds to me an object reference isn't quite right; I think everything must exist in the same namespace, for example I created a toolbar, tool button, and extension to toggle state in the same namespace - where's the rest of your code and are you using the Python Add-In Wizard?

For example here's my entire code only fleshing out the handling of enabling/disabling state of the button (only 1 button i.e., my variable ID minus the namespace is 'button'):
import arcpy
import pythonaddins
 
class ButtonClass3(object):
    """Implementation for testEnable_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        pass
 
class someClassName(object):
    """Implementation for testEnable_addin.extension2 (Extension)"""
    def __init__(self):
        # For performance considerations, please remove all unused methods in this class.
        self.enabled = True
    def activeViewChanged(self):
        mxd = arcpy.mapping.MapDocument('current')
        active_view = mxd.activeView
        if active_view == 'PAGE_LAYOUT':
            button.enabled = False
            print 'button has been disabled...'
        else:
            button.enabled = True
            print 'button re-enabled...'
        arcpy.RefreshActiveView()
        return


You don't need the print statements, but I left them in to illustrate the debugging using the ArcMap python window....the messages printed and coincided with the enabling/disabling as I toggled back and forth between data/layout views.

Hope that helps,
Wayne
0 Kudos
BrendanQuigley
New Contributor II
That makes a lot of sense. I will give that a try.

Thanks for the response.
0 Kudos