Any good ideas on implementing an Auto-Complete function within a combobox??I have three comboboxes:MAPSearch_item: Allows the user to select from a drop down, a layer to to execute the search againstMAPSearch_field: Allows the user to select from a drop down, the attribute field in the 'MAPSearch_item' to search withinMAPSearch_query: Allows the user to enter the value to search for in the selected field of the selected item. Once they hit enter, if the 'search value' is found, a select_analysis is executed and a feature class is added to the MXD containing the selected features.To prevent users from misspelling a search value which would result in an error being raised, I'd like the 'MAPSearch_query' combobox to try and autocomplete the search term as they type it into the combobox. Any nifty ideas here?Here's my code thus far:
class MAPSearch_item(object):
"""Implementation for MAPSearch.item (ComboBox)"""
def __init__(self):
self.items = ["Stores", "Customers"]
self.editable = False
self.enabled = True
self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
def onSelChange(self, selection):
global SearchItem
SearchItem = selection
if selection == "Stores":
try:
SearchLayer = arcpy.mapping.Layer(r"C:\ArcGIS\SYSTEM\COF\Data\Layers\
Stores.lyr")
except Exception as e:
pythonaddins.MessageBox("\
An unexpected error occured. Please contact the GIS Manager with the \
following error message: \
" + e.message, "ERROR", 0)
return
elif selection == "Customers":
try:
SearchLayer = arcpy.mapping.Layer(r"C:\ArcGIS\SYSTEM\COF\Data\Layers\
Customers.lyr")
except Exception as e:
pythonaddins.MessageBox("\
An unexpected error occured. Please contact the GIS Manager with the \
following error message: \
" + e.message, "ERROR", 0)
return
else:
pythonaddins.MessageBox("Item is not a valid selection.", "ERROR", 0)
return
def onEditChange(self, text):
pass
def onFocus(self, focused):
pass
def onEnter(self):
pass
def refresh(self):
self.refresh()
class MAPSearch_field(object):
"""Implementation for MAPSearch.field (ComboBox)"""
def __init__(self):
self.items = ["Name", "Store ID", "Street Address", "District", "Region", \
"Market", "Project Number", "Project Action", "Project Timing"]
self.editable = False
self.enabled = True
self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
def onSelChange(self, selection):
global SearchField
SearchField = selection
global SearchSet
try:
SearchSet = set(r[0] for r in arcpy.da.SearchCursor(SearchLayer,
SearchField))
except Exception as e:
pythonaddins.MessageBox("\
An unexpected error occured. Please contact the GIS Manager with the \
following error message: \
" + e.message, "ERROR", 0)
return
def onEditChange(self, text):
pass
def onFocus(self, focused):
pass
def onEnter(self):
pass
def refresh(self):
self.refresh()
class MAPSearch_query(object):
"""Implementation for MAPSearch.query (ComboBox)"""
def __init__(self):
self.items = []
self.editable = True
self.enabled = True
self.dropdownWidth = ''
self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
def onSelChange(self, selection):
pass
def onEditChange(self, text):
pass
def onFocus(self, focused):
pass
def onEnter(self):
SearchTerm = selection
if SearchTerm in SearchSet:
try:
ResultName = SearchItem + "_" + SearchTerm
Select_analysis(SearchLayer, ResultName,
'"' + SearchField + '" = ' + "'" + SearchTerm + "'")
except Exception as e:
pythonaddins.MessageBox("\
An unexpected error occured. Please contact the GIS Manager with the \
following error message: \
"+ e.message, "ERROR", 0)
else:
pythonaddins.MessageBox("\
The search term entered was not found in the selected attribute field for \
the selected item. Please check your spelling and ensure you have the \
correct search dataset and attribute field selected. If you need \
assistance with this issue, please contact the GIS Manager.", "ERROR", 0)
def refresh(self):
self.refresh()