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:
<SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">class</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">Switch</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">object</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">):</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"></SPAN><SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"># Implementation for Sample_addin.btnSwitch (Button)</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"></SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">def</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> __init__</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">self</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">):</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> self</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">enabled </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">True</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> self</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">checked </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">False</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"></SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">def</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> onClick</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">self</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">):</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">if</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">not</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> self</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">checked</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">:</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> self</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">checked </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">True</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">print</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"Extension ON"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"># extExtension.__init__()</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> extExtension</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">enabled </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">True</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">else</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">:</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> self</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">checked </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">False</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">print</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"Extension OFF"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> extExtension</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">enabled </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">False</SPAN>
A code for the extension:
<SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">class</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">Extension</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">object</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">):</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"></SPAN><SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"># Implementation for Sample_addin.extExtension (Extension)</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"></SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">def</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> __init__</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">self</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">):</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> self</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">enabled </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">True</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">print</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">'Initialized'</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"></SPAN><SPAN class="" style="color: #858c93; border: 0px; font-size: 13px;"># and so on...</SPAN>
And a part of config.xml:
<SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"><</SPAN><SPAN class="" style="color: #2b91af; border: 0px; font-size: 13px;">Extension</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> autoLoad</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"true"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> category</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"Tool"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #101094; border: 0px; font-size: 13px;">class</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"Extension"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> description</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"description"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> id</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"Sample_addin.extExtension"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> name</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"Extension"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> productName</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"Extension"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> showInExtensionDialog</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">=</SPAN><SPAN class="" style="color: #7d2727; border: 0px; font-size: 13px;">"true"</SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;"> </SPAN><SPAN class="" style="color: #303336; border: 0px; font-size: 13px;">/></SPAN>
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?