Managing the state of Python Add-In extension

1465
2
11-24-2016 06:14 AM
SergeyNorin1
New Contributor

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?

Tags (2)
0 Kudos
2 Replies
LukeWebb
Occasional Contributor III

Not really sure, but im pretty sure that in my code...my IDs align better...for example where you have:

class Extension(object):

and:

extExtension.enabled = True



In my code I have:

class extExtension(object):



extExtension.enabled = True
0 Kudos
SergeyNorin1
New Contributor

extExtension is a name of an instance (from config.xml: class="Extension", ..., id="Sample_addin.extExtension")

0 Kudos