So I have a series of Comboboxes which I created to perform a "Quick-Jump" function in which a user can select AOIs at varying geography levels, and kind of quickly drill down into a very specific AOI without having to know where it is geographically.
The Comboboxes are Major Geographic Level (MajorGeoLevel.cbx) and Minor Geographic Level (MinorGeoLevel.cbx).
Major Geographic Level contains a static items list of containing the National Extent and 8 different regions around the US. When a user selects a region, the Combobox should:
I am having two issues.
1. The selection from MajorGeoLevel.cbx does not seem to be doing anything. ie. When I select National...nothing happens. It doesn't even reflect in the Combobox.
2. MinorGeoLevel.cbx is not becoming enabled once a selection is made in MajorGeoLevel. Because it's not becoming enabled, I can't even tell if it's updating the item list for MinorGeoLevel.cbx either.
Here is my code:
Any insight is greatly appreciated
The Comboboxes are Major Geographic Level (MajorGeoLevel.cbx) and Minor Geographic Level (MinorGeoLevel.cbx).
Major Geographic Level contains a static items list of containing the National Extent and 8 different regions around the US. When a user selects a region, the Combobox should:
- Perform a selection against the Regions Layer for the Region selected in the Combobox, zoom to the selected feature, turn the layer on, clear the selection and refresh the active view.
- Enable the MinorGeoLevel.cbx and update the items contained in the MinorGeoLevel.cbx with a predefined list of Minor Geographic Levels, which correspond to the selected item in the MajorGeoLevel.cbx, unless the item selected in MajorGeoLevel.cbx is 'National'.
I am having two issues.
1. The selection from MajorGeoLevel.cbx does not seem to be doing anything. ie. When I select National...nothing happens. It doesn't even reflect in the Combobox.
2. MinorGeoLevel.cbx is not becoming enabled once a selection is made in MajorGeoLevel. Because it's not becoming enabled, I can't even tell if it's updating the item list for MinorGeoLevel.cbx either.
Here is my code:
Code:
class QuickJump_MajorGeoLevel(object):
"""Implementation for QuickJump_MajorGeoLevel.cbx (ComboBox)"""
def __init__(self):
self.items = ["National", "National-Direct", "Region I", "Region II", "Region III", "Region IV", "Region V", "Region VI", "Region VII", "Region VIII"]
self.editable = False
self.enabled = True
self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXX'
self.width = 'XXXXXXXXXXXXXXXXXXXX'
def onSelChange(self, selection):
#Instantiate the current MXD as a variable
mxd = arcpy.mapping.MapDocument("Current")
#Jump to the selected MajorGeoLevel and initialize the MinorGeoLevel combobox, populated with the MinorGeoList that corresponds to the current selection
#If the current selection is 'National', jump to the NationalExtent. MinorGeoLevel.cbx and SubGeoLevel.cbx remain disabled from Initialization.
if selection == "National":
#Jump to the 'NationalExtent'
df = arcpy.mapping.ListDataFrames(mxd, "Business Analyst Map")[0]
NationalExtent = df.extent
NationalExtent.XMin, NationalExtent.YMin = -13978263.2599, -1547990.11744
NationalExtent.XMax, NationalExtent.YMax = -7429812.66299, 7011646.87809
df.extent = NationalExtent
arcpy.RefreshActiveView()
#if the current selection is National-Direct , refresh the MinorGeoLevel.cbx in the UI
elif selection == "National-Direct":
#Refresh the 'QuickJump_MinorGeoLevel' combobox which enables the combobox and updates the item list
QuickJump_MinorGeoLevel.refresh()
#Jump to the Full Extent of the National-Direct Region and Turn the layer On
for lyr in arcpy.mapping.ListLayers (mxd):
if lyr.name == "Regions_All":
#if the layer is not currently visible, make the layer visible and refresh the Map Display Window
if lyr.visible == False:
lyr.visible = True
#Establish the DataFrame and the 'Regions_All' variables
df = arcpy.mapping.ListDataFrames(mxd, "Business Analyst Map")[0]
Regions_All = arcpy.mapping.ListLayers(mxd, "Regions_All", df)
#Select 'Region 1' from the 'Regions_All' layer
arcpy.SelectLayerByAttribute_management ("Regions_All", "NEW_SELECTION", ' "REGION" = ND')
#Zoom to the selected feature
df.zoomToSelectedFeatures()
#Apply a 10% Buffer to the Extent of the Zoom
df.scale = df.scale * 1.1
#Clear the Selection
arcpy.SelectLayerByAttribute_management ("Regions_All", "CLEAR_SELECTION")
#Refresh the Map Display Window
arcpy.RefreshActiveView()
#Report an with a MessageBox if the 'Regions_All' layer is not loaded in the MXD
else:
pythonaddins.MessageBox('The layer Regions_All is not loaded in the MXD. Unable to turn layer on or jump to extent.', 'Layer not Found', 5)
class QuickJump_MinorGeoLevel(object):
"""Implementation for QuickJump_MinorGeoLevel.cbx (ComboBox)"""
def __init__(self):
#Create the Predefined Item Lists, which are initialized depending on the QuickJump_MajorGeoLevel Combobox's current selection
self.items= []
self.editable = False
self.enabled = False
self.dropdownWidth = 'WWWWWW'
self.width = 'WWWWWW'
def SelChange(self, selection):
pass
def refresh(self):
#Create the Predefined Minor Geography Item Lists, which are implemented in the QuickJump_MinorGeoLevel Combobox depending on the QuickJump_MajorGeoLevel Combobox's current selection
ND_MinorGeoList = ["Boston", "Los Angeles", "San Francisco", "Honolulu", "Chicago", "Minneapolis/St. Paul", "New York", "Philadelphia", "Wilmington"]
RegionI_MinorGeoList["New York-Northern New Jersey-Long Island, NY-NJ-PA"]
RegionII_MinorGeoList["New York-Northern New Jersey-Long Island, NY-NJ-PA"]
RegionIII_MinorGeoList["Bridgeport-Stamford-Norwalk, CT", "Hartford West-Hartford East, CT", "New Haven-Milford,CT", "New York-Northern New Jersey-Long Island, NY-NJ-PA", "Poughkeepsie-Newburgh-Middletown, NY", "Torrington, CT", "Trenton-Ewing, NJ", "Allentown-Bethlehem-Easton, PA-NJ", "Philadelphia-Camden-Wilmington, PA-NJ-DE-MD"]
RegionIV_MinorGeoList["Baltimore-Townsend, MD", "Cambridge, MD", "Dover, DE", "Easton, MD", "Gettysburg, PA", "Lexington Park, MD", "Ocean Pines, MD", "Salisbury, MD", "Seaford, DE", "Washington-Arlington-Alexandria, DC-VA-MD-WV", "York-Hanover, PA"]
RegionV_MinorGeoList["Baltimore-Townsend, MD", "Chambersburg, PA", "Charlottesville, VA", "Culpepper, VA", "Cumberland, MD-WV", "Gettysburg, PA", "Hagerstown-Martinsburg, MD-WV", "Harrisonburg, VA", "Richmond, VA", "Staunton-Waynesboro, VA", "Washington-Arlington-Alexandria, DC, VA-MD-WV", "Winchester,VA-WV"]
RegionVI_MinorGeoList["Athens, TX", "Bonham, TX", "Dallas-Fort Worth-Arlington, TX", "Durant, OK", "Gainesville, TX", "Palestine, TX", "Paris, TX", "Sherman-Denison, TX", "Sulpher Springs, TX", "Alexandria, LA", "Baton Rouge, LA", "Crowley, LA", "DeRidder, LA", "Fort Polk South, LA", "Jennings, LA", "Lufkin, TX", "Natchez, MS-LA", "Opelousas-Eunice, LA", "Bastrop, LA", "El Dorado, AR", "Jacksonville, TX", "Longview, TX", "Magnolia, AR", "MArshall, TX", "Minden, LA", "Monroe, LA", "Mount Pleasant, TX", "Nacogdoches, TX", "Natchitoches, LA", "Ruston, LA", "Shreveport-Bossier City, LA", "Tallulah, LA", "Texarkana, TX", "Tyler, TX", "Vicksburg, MS"]
RegionVII_MinorGeoList["Baton Rouge, LA", "Bogalusa, LA", "Crowley, LA", "Gulfport-Biloxi, MS", "Hammond, LA", "Houma-Bayou Cane-Thibodaux, LA", "Jennings, LA", "Lafayette, LA", "Lakes Charles, LA", "McComb, MS", "Morgan City, LA", "New Iberia, LA", "New Orleans-Metairie-Kenner, LA", "Opelousas-Eunice, LA", "Picayune, MS", "Pierre Part, LA"]
RegionVIII_MinorGeoList["Alice, TX", "Austin-Round Rock-San Marcos, TX", "Bay City, TX", "Brenham, TX", "Brownsville-Harlingen", "College Station-Bryan, TX", "Corpus Christi, TX", "El Campo, TX", "Huntsville, TX", "Kileen-Temple-Fort Hood, TX", "Kingsville, TX", "Marble Falls, TX", "McAllen-Edinburg-Mission, TX", "Raymondville, TX", "Rio Grande City-Roma, TX", "San Antonio-New Braunfels, TX", "Victoria, TX", "Abbeville, LA", "Beaumont-Port Arthur, TX", "DeRidder, LA", "Houston-Sugar Land-Baytown, TX", "Jennings, LA", "Lake Charles, LA"]
if QuickJump_MajorGeoLevel.selection == "National-Direct":
self.enabled = True
self.items = ND_MinorGeoList