实现wx界面的下拉框,可以动态变化的下拉框(arcpy中读取shp的字段,以及选择可以使用)
#encoding: utf-8
import arcpy
import os
import wx
def get_field_names(self, input_feature_class):
# 检查路径是否存在
if not os.path.exists(input_feature_class):
print("Error: File does not exist.")
return []
# 设置工作空间
arcpy.env.workspace = os.path.dirname(input_feature_class)
# 列出要素类的字段
fields = arcpy.ListFields(input_feature_class)
# 创建一个空列表来存储字段名
field_names1 = []
# 将字段名追加到列表中
for field in fields:
field_names1.append(field.name)
# 返回字段名列表
return field_names1
self.combo1 = wx.ComboBox(parent=panel1, id=-1, size=(100, 180), pos=(340, 200), value="")
def OnCombo1Select(self, event):
field_names = self.get_field_names(self.editname5.GetValue())
self.combo1.SetItems(field_names)
def OnClick5(self, event):
wildcard = 'Raster (*.shp)|*.shp'
dialog = wx.FileDialog(None, 'Browse for File', os.getcwd(), '', wildcard, wx.FD_OPEN)
if dialog.ShowModal() == wx.ID_OK:
self.editname5.SetValue(dialog.GetPath())
dialog.Destroy
self.OnCombo1Select(wx.CommandEvent(wx.EVT_COMBOBOX.typeId, self.combo1.GetId()))