<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Have Combobox Listen to AddLayer Event? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/have-combobox-listen-to-addlayer-event/m-p/6723#M586</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am building an addin combobox. The combobox will populate a list of all the layers that are in the TOC in ArcMap upon initialization of ArcMap. The user will choose a layer and some actions will take place.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want to do is have the comobox listen to the Table of Contents and update any time the user adds or removes a layer automatically. Is this possible?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jul 2015 21:58:07 GMT</pubDate>
    <dc:creator>MikeMacRae</dc:creator>
    <dc:date>2015-07-16T21:58:07Z</dc:date>
    <item>
      <title>Have Combobox Listen to AddLayer Event?</title>
      <link>https://community.esri.com/t5/python-questions/have-combobox-listen-to-addlayer-event/m-p/6723#M586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am building an addin combobox. The combobox will populate a list of all the layers that are in the TOC in ArcMap upon initialization of ArcMap. The user will choose a layer and some actions will take place.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want to do is have the comobox listen to the Table of Contents and update any time the user adds or removes a layer automatically. Is this possible?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 21:58:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/have-combobox-listen-to-addlayer-event/m-p/6723#M586</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2015-07-16T21:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Have Combobox Listen to AddLayer Event?</title>
      <link>https://community.esri.com/t5/python-questions/have-combobox-listen-to-addlayer-event/m-p/6724#M587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You would need to implement both the ComboBox and an Application Extension. The Application Extension would need to listen for changes in the TOC and you'd need to build a hook to feed the values to the ComboBox. I haven't tested it, but I'm thinking it'd look something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import pythonaddins

class ComboBoxClass(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for ComboBox"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.items = list()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.editable = self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.dropdownWidth = self.width = 'WWWWWW'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ComboBoxClass._hook = self&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

class ExtensionClass(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for Application Extension """
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ExtensionClass._hook = self
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; def itemAdded(self, new_item):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ComboBoxClass._hook.items.extend([new_item])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; def itemDeleted(self, deleted_item):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ComboBoxClass._hook.items.remove(deleted_item)&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:16:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/have-combobox-listen-to-addlayer-event/m-p/6724#M587</guid>
      <dc:creator>FreddieGibson</dc:creator>
      <dc:date>2021-12-10T20:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Have Combobox Listen to AddLayer Event?</title>
      <link>https://community.esri.com/t5/python-questions/have-combobox-listen-to-addlayer-event/m-p/6725#M588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HeyFreddie. You have me chasing down a better understanding of hooking in python. I've used your example and modified it a bit. This worked well. Thanks for the input.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jul 2015 22:31:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/have-combobox-listen-to-addlayer-event/m-p/6725#M588</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2015-07-31T22:31:50Z</dc:date>
    </item>
  </channel>
</rss>

