Saturday, 16 September 2017

arcpy - Dynamically adding items into one python addin Combobox from another?


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):
"""Implementation for TestCombo_addin.combobox (ComboBox)"""
def __init__(self):
self.items = ["cb1item1", "cb1item2"]
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWW'
self.width = 'WWWWWW'
self.cb2=ComboBoxClass2()


def onSelChange(self, selection):
pythonaddins.MessageBox(selection,"Message",0)
self.cb2.items.append(selection)
self.cb2.refresh()
def onEditChange(self, text):
pass
def onFocus(self, focused):
pass
def onEnter(self):
pass

def refresh(self):
pass

class ComboBoxClass2(object):
"""Implementation for TestCombo_addin.combobox_1 (ComboBox)"""
def __init__(self):
self.items = ["cb2item1", "cb2item2"]
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):
pass
def onEnter(self):
pass

def refresh(self):
pass

Answer



I got a solution (Thanks to Freddie Gibson from ESRI.) I am curious to know if there are other solutions.


import arcpy
import pythonaddins

class ComboBoxClass1(object):
"""Implementation for TestCombo_addin.combobox (ComboBox)"""
def __init__(self):

self.items = ["cb1item1", "cb1item2"]
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWW'
self.width = 'WWWWWW'
ComboBoxClass1._hook=self
def onSelChange(self, selection):
pass

class ComboBoxClass2(object):

"""Implementation for TestCombo_addin.combobox_1 (ComboBox)"""
def __init__(self):
self.items = ["cb2item1", "cb2item2"]
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWW'
self.width = 'WWWWWW'
def onSelChange(self, selection):
ComboBoxClass1._hook.items.append(selection)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...