I've written a Python add-in, which includes two combo boxes and three buttons. So in my Python code I have five classes.
All five include identical code to get references to the current MapDocument, active dataframe, a particular layer that is expected to be present in the map document, and a database table that should be found in the same workspace as the layer.
The code for the combo box classes populates those combo boxes with the unique values found in the database table.
The three buttons all perform an identical selection based on attributes, one just does the selection, one does the selection then pans to the selected features, and the third does the selection then zooms to the selected features. All three have identical code except for the pan/zoom bit at the end.
What would be best practice in a situation like this to get rid of all that duplication? can I just put the duplicated code in a function outside the class definitions?
The add-in works great, I'm just wondering if and how I can tidy up the code a bit...
Thanks
Dan
All five include identical code to get references to the current MapDocument, active dataframe, a particular layer that is expected to be present in the map document, and a database table that should be found in the same workspace as the layer.
The code for the combo box classes populates those combo boxes with the unique values found in the database table.
The three buttons all perform an identical selection based on attributes, one just does the selection, one does the selection then pans to the selected features, and the third does the selection then zooms to the selected features. All three have identical code except for the pan/zoom bit at the end.
What would be best practice in a situation like this to get rid of all that duplication? can I just put the duplicated code in a function outside the class definitions?
The add-in works great, I'm just wondering if and how I can tidy up the code a bit...
Thanks
Dan