Odd Behavior with PythonAddins Combo Box

337
1
10-24-2017 12:53 PM
JoeBorgione
MVP Emeritus

I've been working on an application that utilizes a pythonaddins combo box, and it works most of the time as intended. It allows for the user to enter a name and then with the click of a button, that name is passed to an initial search cursor.  If that search cursor finds an exact match, it selects the record(s) of a table that is the exact match.  If it does not make an exact match, it goes onto a second search cursor (not nested, completely separate) and performs searches based on the first word and the first few letters of that first word.

The data table it searches on resides in a file geodatabse, and all the names in the table are upper case.  I mention this because if I do not have caps lock on and enter the name as lower case, it does not find it.  Okay, that's not so odd.  But what is odd to me is that if I enter the name with upper case and click the button the execute the search, nothing happens: just a button click.

If I then shutdown arcmap, and restart it, the combo box works until I make that same mistake again.  Should I be looking at one or more of the combo def blocks?  

class ComboBoxClass1(object):
    """Implementation for CheckStreetName_addin.combobox (ComboBox)"""
    def __init__(self):
        self.items = []
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWWWWWWWWW'
        self.width = 'WWWWWWWWWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        global comboin
        comboin = text
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass
That should just about do it....
0 Kudos
1 Reply
JoeBorgione
MVP Emeritus

I've done a couple things to overcome this shortcoming:  First thing is to use .upper() on the combo variable:  

comboin= comboin.upper()

 I also force a "clear selected set" upon the button click: 

    def onClick(self):
        arcpy.SelectLayerByAttribute_management("FullNameOnly","CLEAR_SELECTION")
        # clears anything that is selected
        with arcpy.da.SearchCursor("FullNameOnly","NameOnly") as cursor:
            #starts the search cursor
            for row in cursor:
                fromlist = row[0]
                fromlist = fromlist.upper()‍‍‍‍‍‍
                # ensures the data from the table is upper case as well
                arcpy.blah_blah...‍‍‍‍‍‍‍‍‍‍
That should just about do it....
0 Kudos