Problems with Python Add-In Combo Box

1618
2
Jump to solution
12-05-2016 12:44 PM
BenjaminMittler
Occasional Contributor III

Hi all, 

I'm creating a python combobox add-in where the user can pick from a predefined list of counties and when selected, a data layer for that county will be added to the TOC. The functionality of the Add-in works which I am happy about but I'm having a bit of an issue with some format particulars. First off, is there a way to control what text displays as the default in the combobox? I'd like it to display something like "Choose a County Below". Secondly, whatever text I input as the "Caption" when creating the combobox in the add-in wizard displays to the left of my combobox. Is there any way to control this so that the text isnt there? Two more.... I have like 50 something counties in the list and when you hit the dropdown it shows them all, id like it to only show 10 and allow you to scroll down but cant figure this one out. Last one, If open up the combo list and hit the letter  "C" id like it to highlight "Calhoun", instead it just automatically adds the Calhoun county data to the map. 

I know its a lot but ESRI's help on this subject wasn't exactly the best. Thanks in Advanced!

Ben

import arcpy
import pythonaddins

class ComboBoxClass1(object):
    """Implementation for OSTDS_3_addin.combobox (ComboBox)"""
    def __init__(self):
        self.items = ["Alachua","Baker","Bay","Bradford", "Brevard", "Broward", "Calhoun", "Charlotte", "Citrus", "Clay", "Collier", "Columbia", "Dade", "Desoto", "Dixie", "Duval", "Escambia", "Flagler", "Franklin", "Gadsden", "Gilchrist", "Glades", "Gulf", "Hamilton", "Hardee", "Hendry", "Hernando", "Highlands", "Hillsborough", "Holmes", "IndianRiver", "Jackson", "Jefferson", "Lafayette", "Lake", "Lee", "Leon", "Levy", "Liberty", "Madison", "Manatee", "Marion", "Martin", "Monroe", "Nassau", "Okaloosa", "Okeechobee", "Orange", "Osceola", "PalmBeach", "Pasco", "Pinellas", "Polk", "Putnam", "SantaRosa", "Sarasota", "Seminole", "StJohns", "StLucie", "Sumter", "Suwannee", "Taylor", "Union", "Volusia", "Wakulla", "Walton", "Washington"]
        self.editable = False
        self.enabled = True
        self.dropdownWidth = 'WWWWWWWWW'
        self.width = 'WWWWWWWWW'
    def onSelChange(self, selection):
        
        mxd = arcpy.mapping.MapDocument("CURRENT")
        dataFrame = arcpy.mapping.ListDataFrames(mxd, "*")[0]
        county = (selection)
        county_name = str(county)
        gdb_path = r"my\\path\\ex.gdb\\"
        county_path = gdb_path + county_name
        newlayer = arcpy.mapping.Layer(county_path)
        arcpy.mapping.AddLayer(dataFrame, newlayer, "BOTTOM")
        arcpy.RefreshActiveView()
        arcpy.RefreshTOC()

        del county, county_name, newlayer

    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass
        ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
BenjaminMittler
Occasional Contributor III

1 & 2 have been solved. You have to open up the config xml file. Adding  hintText="your box text" under <ComboBox> will input "your box text" within the combobox by default. Deleting the text for caption=  and leaving just ""under <ComboBox> will delete the text to the left of the ComboBox. 


					
				
			
			
				
			
			
				
			
			
				

View solution in original post

0 Kudos
2 Replies
BenjaminMittler
Occasional Contributor III

1 & 2 have been solved. You have to open up the config xml file. Adding  hintText="your box text" under <ComboBox> will input "your box text" within the combobox by default. Deleting the text for caption=  and leaving just ""under <ComboBox> will delete the text to the left of the ComboBox. 


					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos
TimWitt2
MVP Alum

Hey Ben,

I know this is a little late but the drop down count is determinant but the size of the self.items property in the def __init__ (self). Maybe the following works?

import arcpy
import pythonaddins

class ComboBoxClass1(object):
    """Implementation for OSTDS_3_addin.combobox (ComboBox)"""
    def __init__(self):
        self.items = ["","","","","","","","","",""]
        self.editable = False
        self.enabled = True
        self.dropdownWidth = 'WWWWWWWWW'
        self.width = 'WWWWWWWWW'
    def onSelChange(self, selection):
        
        mxd = arcpy.mapping.MapDocument("CURRENT")
        dataFrame = arcpy.mapping.ListDataFrames(mxd, "*")[0]
        county = (selection)
        county_name = str(county)
        gdb_path = r"my\\path\\ex.gdb\\"
        county_path = gdb_path + county_name
        newlayer = arcpy.mapping.Layer(county_path)
        arcpy.mapping.AddLayer(dataFrame, newlayer, "BOTTOM")
        arcpy.RefreshActiveView()
        arcpy.RefreshTOC()

        del county, county_name, newlayer

    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
          if focused:
               self.items = ["Alachua","Baker","Bay","Bradford", "Brevard", "Broward", "Calhoun", "Charlotte", "Citrus", "Clay", "Collier", "Columbia", "Dade", "Desoto", "Dixie", "Duval", "Escambia", "Flagler", "Franklin", "Gadsden", "Gilchrist", "Glades", "Gulf", "Hamilton", "Hardee", "Hendry", "Hernando", "Highlands", "Hillsborough", "Holmes", "IndianRiver", "Jackson", "Jefferson", "Lafayette", "Lake", "Lee", "Leon", "Levy", "Liberty", "Madison", "Manatee", "Marion", "Martin", "Monroe", "Nassau", "Okaloosa", "Okeechobee", "Orange", "Osceola", "PalmBeach", "Pasco", "Pinellas", "Polk", "Putnam", "SantaRosa", "Sarasota", "Seminole", "StJohns", "StLucie", "Sumter", "Suwannee", "Taylor", "Union", "Volusia", "Wakulla", "Walton", "Washington"]
        
    def onEnter(self):
        pass
    def refresh(self):
        pass

Tim

0 Kudos