Footprints swig API: access shown text in fields

This commit is contained in:
qu1ck
2023-06-29 20:36:27 +00:00
committed by Jon Evans
parent 7779a01d48
commit ec94439df4
3 changed files with 23 additions and 12 deletions
+17 -6
View File
@@ -30,7 +30,6 @@
%template(MAP_STRING_STRING) std::map<wxString, wxString>;
%rename(GetFieldsNative) FOOTPRINT::GetFields;
%feature("flatnested");
%include footprint.h
%feature("flatnested", "");
@@ -59,18 +58,30 @@
# the object in the garbage collector
#
def GetFields(self):
""" Returns footprint fields map. """
fields = self.GetFieldsNative()
def GetFieldsText(self):
""" Returns footprint fields name to text map. """
fields = self.GetFields()
return {str(field.GetName()): str(field.GetText()) for field in fields}
def GetField(self, key):
""" Returns Field with a given key if it exists, throws KeyError otherwise. """
def GetFieldsShownText(self):
""" Returns footprint fields name to shown text map. """
fields = self.GetFields()
return {str(field.GetName()): str(field.GetShownText(False)) for field in fields}
def GetFieldText(self, key):
""" Returns Field text with a given key if it exists, throws KeyError otherwise. """
if self.HasFieldByName(key):
return self.GetFieldByName(key).GetText()
else:
raise KeyError("Field not found: " + key)
def GetFieldShownText(self, key):
""" Returns Field shown text with a given key if it exists, throws KeyError otherwise. """
if self.HasFieldByName(key):
return self.GetFieldByName(key).GetShownText(False)
else:
raise KeyError("Field not found: " + key)
def SetField(self, key, value):
if self.HasFieldByName(key):
self.GetFieldByName(key).SetText(value)