Whenever I have any interaction with the Table of Contents in ArcMAP 10.1, ArcGIS 10.1 SP1 for Desktop my Python Add-in (see included code) does not work properly.Items in the Table of Contents appear to flicker and the processing is delayed considereably. When I am using normal sized feature classes (instead of small test classes) and /or .mxds with imagery in the background, it appears to hang indefinitely.Interactions can be: opening the TOC from the Windows tab, adding new layers using the Add Data menu, or simply clicking any where in the TOC window.I would appreciate any help finding the problem with my code!I have attached a small .zip file with a test .mxd (Turnout_test.zip) if this might be helpful.Thanks!
import arcpy
import pythonaddins
class TurnoutComboClass(object):
"""Implementation for Turnout_addin.combobox (ComboBox)"""
def __init__(self):
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWWWWWWWW'
self.width = 'WWWWWWWWWWWWWWWW'
def onSelChange(self, selection):
query = '"Station_ID" = ' + '\'' + str(selection) + '\''
arcpy.SelectLayerByAttribute_management("Turnouts", "NEW_SELECTION", query)
query = '"turnoutnumber" = ' + '\'' + str(selection) + '\''
arcpy.SelectLayerByAttribute_management("FarmFieldsE", "ADD_TO_SELECTION", query)
self.dataframe = arcpy.mapping.ListDataFrames(self.mxd, "Layers") [0]
self.dataframe.zoomToSelectedFeatures()
self.dataframe.scale = 10000
def onEditChange(self, text):
pass
def onFocus(self, focused):
# When the combo box has focus, update the combo box with the list of structure IDs.
if focused:
self.mxd = arcpy.mapping.MapDocument('current')
# Clear any previously selected layers
arcpy.SelectLayerByAttribute_management("Turnouts", "CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management("FarmFieldsE", "CLEAR_SELECTION")
# Paopulate the drop down list
layers = arcpy.mapping.ListLayers(self.mxd)
self.items = []
for layer in layers:
if layer.longName == "Turnouts":
number_records = arcpy.SearchCursor(layer)
for record_index in number_records:
self.items.append(record_index.Station_ID)
# Clean up
del record_index
del number_records
# Clean up
del layer
del layers
def onEnter(self):
query = '"Station_ID" = ' + '\'' + str(self.value) + '\''
arcpy.SelectLayerByAttribute_management("Turnouts", "NEW_SELECTION", query)
query = '"turnoutnumber" = ' + '\'' + str(self.value) + '\''
arcpy.SelectLayerByAttribute_management("FarmFieldsE", "ADD_TO_SELECTION", query)
self.dataframe = arcpy.mapping.ListDataFrames(self.mxd, "Layers") [0]
self.dataframe.zoomToSelectedFeatures()
self.dataframe.scale = 10000
def refresh(self):
pass