1

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:
 self.nameList.append(version.name)
 print self.nameList
 print "Tool finished"
 pass
#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.items.append(button2.nameList)
 self.version = selection#change this
 print self.version
 pass

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

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 14, 2016 at 23:28

1 Answer 1

1

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

answered Jul 18, 2016 at 21:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.