Managing the state of Python Add-In extension

Discussion created by Olimpiysky on Nov 24, 2016
Latest reply on Nov 24, 2016 by Olimpiysky

I have a python add-in that includes a toolbar and an extension. A button on the toolbar should turn extension on and off.

A code for the button:

class Switch(object):# Implementation for Sample_addin.btnSwitch (Button)def __init__(self):    self.enabled = True    self.checked = Falsedef onClick(self):    if not self.checked:        self.checked = True        print "Extension ON"        # extExtension.__init__()        extExtension.enabled = True    else:        self.checked = False        print "Extension OFF"        extExtension.enabled = False

A code for the extension:

class Extension(object):# Implementation for Sample_addin.extExtension (Extension)def __init__(self):    self.enabled = True    print 'Initialized'# and so on...

And a part of config.xml:

<Extension  autoLoad="true"            category="Tool"            class="Extension"            description="description"            id="Sample_addin.extExtension"            name="Extension"            productName="Extension"            showInExtensionDialog="true" />

Everything seems to be OK. When I click the button, it freezes in 'checked' state and the extension gets marked in Extension dialog (Customize -> Extensions). But after this the extension doesn't start working (I have many functions in it like 'onCreate' and so on). If I toggle it manually in Extensions dialog - everything is OK, it works.

And the raverse case - when the Extension works and I want to switch it off by clicking on the button, it only changes its state in Extensin dialog but not in reality.

I've tried to reinitialize the extension by calling extExtension.__init__(). This gave me nothing (and no errors too, only this print statement).

So... How to track the state of an extension in python add-in and change it?