How to dynamically add items into python addin Combobox from another addin combobox.

591
2
Jump to solution
01-23-2018 09:58 AM
Highlighted
New Contributor II

I have two combo boxes. I am trying to add items dynamically into the second combobox from the first combobox's "onSelChange(self, selection)" event.
due to some reason this is not working.

here is my sample code:

import arcpy
import pythonaddins
class ComboBoxClass1(object):
    def __init__(self):
        self.items = []
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
        self.refresh()
        pass
    def onEnter(self):
        pass
    def refresh(self):
        self.refresh()
        pass

class ComboBoxClass2(object):

    def __init__(self):
        self.items = ["Location1","Location2","Location3"]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWWW'
        self.width = 'WWWWWWW'
        self.cb1= ComboBoxClass1()
    def onSelChange(self, selection):
        self.cb1.items.append(selection)
        self.cb1.refresh()
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
      # When the combo box has focus, update the combo box with the list of layer names.
      pass
    def onEnter(self):
        pass
    def refresh(self):
        self.refresh()
        pass‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Regular Contributor II

Hi Surendran Neelakantan‌,

As per our phone conversation earlier, we implemented the following to resolve this issue. 

import arcpy
import pythonaddins

class cbxClass1(object):
    """Implementation for ComboBoxExample_addin.cbx1 (ComboBox)"""
    def __init__(self):
        self.items = [chr(n) * 3 for n in range(65, 65+3)] # [AAA, BBB, CCC]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
        cbxClass1._hook = self
    def onSelChange(self, selection):
        cbxClass2._hook.items.extend([selection])

class cbxClass2(object):
    """Implementation for ComboBoxExample_addin.cbx2 (ComboBox)"""
    def __init__(self):
        self.items = [chr(n) * 4 for n in range(90, 90 - 3, -1)] # [ZZZ, XXX, YYY]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
        cbxClass2._hook = self
    def onSelChange(self, selection):
        cbxClass1._hook.items.extend([selection])

As I stated on our call, there will be more than way to accomplish this. I will ensure that this approach is documentation on a public facing knowledge article. I will also pass this information along to the necessary parties to determine how we can better explain this workflow within our documentation. Please let me know if you have any problems with this. 

Freddie G.

View solution in original post

2 Replies
Highlighted
Regular Contributor II

Hi Surendran Neelakantan‌,

As per our phone conversation earlier, we implemented the following to resolve this issue. 

import arcpy
import pythonaddins

class cbxClass1(object):
    """Implementation for ComboBoxExample_addin.cbx1 (ComboBox)"""
    def __init__(self):
        self.items = [chr(n) * 3 for n in range(65, 65+3)] # [AAA, BBB, CCC]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
        cbxClass1._hook = self
    def onSelChange(self, selection):
        cbxClass2._hook.items.extend([selection])

class cbxClass2(object):
    """Implementation for ComboBoxExample_addin.cbx2 (ComboBox)"""
    def __init__(self):
        self.items = [chr(n) * 4 for n in range(90, 90 - 3, -1)] # [ZZZ, XXX, YYY]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
        cbxClass2._hook = self
    def onSelChange(self, selection):
        cbxClass1._hook.items.extend([selection])

As I stated on our call, there will be more than way to accomplish this. I will ensure that this approach is documentation on a public facing knowledge article. I will also pass this information along to the necessary parties to determine how we can better explain this workflow within our documentation. Please let me know if you have any problems with this. 

Freddie G.

View solution in original post

Highlighted
New Contributor II

Freddie,

This works !   Thank you  for the solution. I am excited  to know other options to accomplish the same goal.

Thank you

Reply
0 Kudos