I'm trying to dynamically edit the list of items in a combobox I made using python add in for a toolbar I'm working on. The list is calculated by another button. Here is the relevant code:

class SetLayer(object):
    """Implementation for stuff.button2 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        self.a = pythonaddins.GetSelectedCatalogWindowPath()
        self.a = self.a.encode('mbcs')#pretty sure this helps with string encoding
        print self.a
        self.b = os.path.split((self.a))
        self.c = self.b[0]
        self.d = os.path.split(self.c)
        self.e = (self.b[1]) #feature class
        self.f = (self.d[1]) #feature dataset
        self.g = (self.d[0]) #workspace
        print "Feature class: %r" % self.e
        print "Feature dataset: %r" % self.f
        print "Workspace: %r" % self.g
        connProp = arcpy.Describe(self.g).connectionProperties
        self.h = connProp.instance.split(":", 2)
        self.k = self.h[2].encode('mbcs')#instanceX
        self.i = connProp.database.encode('mbcs')#databaseX
        print "Instance is %r" % self.k
        print "Database is %r" % self.i
        print "Availible Versions:"
        self.List = arcpy.da.ListVersions(self.g)
        self.nameList = []
        #This creates the list that I want the combobox to use
        for version in self.List:

        print self.nameList
        print "Tool finished"

#working on editing this to provide dropdown
class setVersion(object):
    """Implementation for stuff.combobox2 (ComboBox)"""
    def __init__(self):
        #self.items = []
        self.editable = True
        self.enabled = True
        self.width = 'WWWWWW'*3
        self.dropdownWidth = 'WWWWW'*3
    def onSelChange(self, selection):
        self.version = selection#change this
        print self.version

How do I get the items to dynamically update? What did I do wrong?


I figured it out. The first mistake I made was appending the newList to a self.items in the setVersion object. That just adds the entire list in as one item. Instead do this:

self.items = button2.nameList

The other mistake I made was trying to get items to update in the onSelChange function. The list needs to be updated in a different function. I don't know why. I used the onEnter function. It looks like this:

def onEnter(self):
    self.items = button2.nameList

This enters the list I created with items into the combobox after entering enter in the combobox

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy