Footprints swig API: access shown text in fields
This commit is contained in:
parent
7779a01d48
commit
ec94439df4
|
@ -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)
|
||||
|
|
|
@ -52,7 +52,7 @@ if( NOT (MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug") )
|
|||
# but the kicad binaries are linked to the debug mode python
|
||||
# Test that runs the QA tests through scripting
|
||||
add_test(NAME qa_python
|
||||
COMMAND ${PYTHON_EXECUTABLE} -m pytest ${CMAKE_CURRENT_SOURCE_DIR}/pcbnewswig ${PYTEST_ARGS_QACLI}
|
||||
COMMAND ${PYTHON_EXECUTABLE} -m pytest ${CMAKE_CURRENT_SOURCE_DIR}/pcbnewswig ${PYTEST_ARGS_QAPYTHON}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
|
|
|
@ -128,9 +128,9 @@ class TestBoardClass:
|
|||
}
|
||||
assert footprint.GetSheetfile() == 'custom_fields.kicad_sch'
|
||||
assert footprint.GetSheetname() == ''
|
||||
assert footprint.GetField('myfield') == 'myvalue'
|
||||
assert footprint.HasField('myfield') == True
|
||||
assert footprint.HasField('abcd') == False
|
||||
assert footprint.GetFieldText('myfield') == 'myvalue'
|
||||
assert footprint.HasField('myfield')
|
||||
assert not footprint.HasField('abcd')
|
||||
footprint.SetField('abcd', 'efgh')
|
||||
assert footprint.HasField('abcd') == True
|
||||
assert footprint.GetField('abcd') == 'efgh'
|
||||
assert footprint.HasField('abcd')
|
||||
assert footprint.GetFieldText('abcd') == 'efgh'
|
||||
|
|
Loading…
Reference in New Issue