Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a toolbar which enables a second and third combobox when a selection is made on the previous. I would like to add a button to 'reset' the toolbar. Basically reload the toolbar to it's original load state. Any thoughts?

Code follows:

import arcpy
import pythonaddins
layer = arcpy.mapping.ListLayers(arcpy.mapping.MapDocument("CURRENT"))[0]
arcpy.SelectLayerByAttribute_management(layer,"CLEAR_SELECTION")
arcpy.RefreshActiveView()

class Survey(object):
    """Implementation for DatabaseSearch_addin.combobox1 (ComboBox)"""
    def __init__(self):
        #in the initialisation of the addin
        self.items = []
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
        #set the map document reference
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        layer = arcpy.mapping.ListLayers(mxd)[0]
        # check if the layer exists
        if layer:
            #create a column name variable for the search cursor parameters
            column_BlockNo = "L1SURNAM"
            sc = arcpy.SearchCursor(layer,""""L1SURNAM" <> ' '""","",column_BlockNo,column_BlockNo)
            #Due to the multiple values stored in the attribute table a dictionary had to be used
            #Create a dictionary
            dictionary = {}
            #for loop to iterate through the attribute tables getting the values for the column
            for row in sc:
                #set the value as the row value in the column block number
                val = row.getValue(column_BlockNo)
                #the nature of dictionaries does not allow for duplicates thus handling the redundant block numbers in the data table for use in the combobox
                dictionary[val] = val
                #create a list of items for the dictionary's unique keys to be written to
            Items = []
            #for loop to iterate through the keys in the dictionary
            for key in dictionary.iterkeys():
                #append the key values to the list Items
                Items.append(key)
                #append the list of keys to the Blocknumber(self) item list
                self.items.append(key)
            #sort keys in ascending numeric order
            self.items.sort()
        del row
        del sc

    def onSelChange(self, selection):
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        layer = arcpy.mapping.ListLayers(mxd)[0]
        arcpy.SelectLayerByAttribute_management(layer,"NEW_SELECTION","L1SURNAM = '" + selection + "'")
        df.zoomToSelectedFeatures()
        arcpy.RefreshActiveView()
        #if the layer exists
        dictionary = {}
        if layer:
            #empty the lot number item list
            combobox2.items = []
            #create a variable for the lot number
            column_Lot = "L2BLOCK"
            #create a search cursor for the layer on the lot number field selecting all the values that are not an empty string
            sc = arcpy.SearchCursor(layer,""""L2BLOCK" <> ' '""","",column_Lot,column_Lot)
            #for loop to read through the values in the lot number field
            for row in sc:
                #set the value as the row value in the column block number
                val = row.getValue(column_Lot)
                #the nature of dictionaries does not allow for duplicates thus handling the redundant block numbers in the data table for use in the combobox
                dictionary[val] = val
                #create a list of items for the dictionary's unique keys to be written to
            #for loop to iterate through the keys in the dictionary
            for key in dictionary.iterkeys():
                #append the key values to the list Items
                combobox2.items.append(key)
                combobox2.items.sort()
                #append the list of keys to the Blocknumber(self) item list
                combobox2.enabled = True
        del row
        del sc
    def onEditChange(self, text):
        #create a variable to store the text in for the selection tool
        SurNam = text
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        layer = arcpy.mapping.ListLayers(mxd)[0]
        arcpy.SelectLayerByAttribute_management(layer,"NEW_SELECTION","L1SURNAM = '" + SurNam + "'")
        df.zoomToSelectedFeatures()

class Block(object):
    """Implementation for DatabaseSearch_addin.combobox2 (ComboBox)"""
    def __init__(self):
        self.items = []
        self.editable = True
        self.enabled = False
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        #set the map document reference
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        layer = arcpy.mapping.ListLayers(mxd)[0]
        arcpy.SelectLayerByAttribute_management(layer,"SUBSET_SELECTION","L2BLOCK = '" + selection + "'")
        df.zoomToSelectedFeatures()
        arcpy.RefreshActiveView()
        dictionary = {}
        if layer:
            #empty the lot number item list
            combobox3.items = []
            #create a variable for the lot number
            column_Sur = "L3SURNUM"
            sc = arcpy.SearchCursor(layer,""""L3SURNUM" <> ' '""","",column_Sur,column_Sur)
            #for loop to read through the values in the lot number field
            for row in sc:
                #set the value as the row value in the column block number
                val = row.getValue(column_Sur)
                #the nature of dictionaries does not allow for duplicates thus handling the redundant block numbers in the data table for use in the combobox
                dictionary[val] = val
                #create a list of items for the dictionary's unique keys to be written to
            #for loop to iterate through the keys in the dictionary
            for key in dictionary.iterkeys():
                #append the key values to the list Items
                combobox3.items.append(key)
                combobox3.items.sort()
                #append the list of keys to the Blocknumber(self) item list
                combobox3.enabled = True
        del row
        del sc

    def onEditChange(self, text):
        blockNum = text
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        layer = arcpy.mapping.ListLayers(mxd)[0]
        arcpy.SelectLayerByAttribute_management(layer,"SUBSET_SELECTION","L2BLOCK = '" + blockNum + "'")
        df.zoomToSelectedFeatures()

class Section(object):
    """Implementation for DatabaseSearch_addin.combobox3 (ComboBox)"""
    def __init__(self):
        self.items = []
        self.editable = True
        #only activated when survey name is populated
        self.enabled = False
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        mxd = arcpy.mapping.MapDocument("CURRENT")
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        layer = arcpy.mapping.ListLayers(mxd)[0]
        arcpy.SelectLayerByAttribute_management(layer,"SUBSET_SELECTION","L3SURNUM = '" + selection + "'")
        df.zoomToSelectedFeatures()
        arcpy.RefreshActiveView()

class Rest(object):
    """Implementation for DatabaseSearch_addin.button3 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        arcpy.SelectLayerByAttribute_management(layer,"CLEAR_SELECTION")
        combobox2.items()
        combobox2.enabled = False
        combobox3.items()   
        combobox3.enabled = False
        arcpy.RefreshActiveView()
share|improve this question
1  
Could you post your code? –  Fezter Feb 6 '13 at 5:45
    
Could the reset button delete the other comboboxes? Effectively resetting it? –  Fezter Feb 6 '13 at 5:45
    
I aim to have the reset button clear clear the 2nd and 3rd combobox and reload the first (original state). Here is what have. Thanks for the response! I am providing link to code... I was having trouble posting code to this site? First timer:) forums.arcgis.com/threads/76912-Reset-Python-Add-in @Fezter –  wtgeographer Feb 6 '13 at 14:45
1  
I added your code to the question. –  Fezter Feb 6 '13 at 22:11
    
Thanks @Fezter Any thoughts about a solution? –  wtgeographer Feb 7 '13 at 14:16
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.