From ec94439df4a23d4d42e6cc97b62a7b3fd964b9f2 Mon Sep 17 00:00:00 2001 From: qu1ck Date: Fri, 23 Jun 2023 10:44:26 -0700 Subject: [PATCH] Footprints swig API: access shown text in fields --- pcbnew/python/swig/footprint.i | 23 +++++++++++++++------ qa/tests/CMakeLists.txt | 2 +- qa/tests/pcbnewswig/test_002_board_class.py | 10 ++++----- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pcbnew/python/swig/footprint.i b/pcbnew/python/swig/footprint.i index 5710befcd7..db646c6e37 100644 --- a/pcbnew/python/swig/footprint.i +++ b/pcbnew/python/swig/footprint.i @@ -30,7 +30,6 @@ %template(MAP_STRING_STRING) std::map; -%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) diff --git a/qa/tests/CMakeLists.txt b/qa/tests/CMakeLists.txt index d077d30593..a98e9ae9bd 100644 --- a/qa/tests/CMakeLists.txt +++ b/qa/tests/CMakeLists.txt @@ -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} ) diff --git a/qa/tests/pcbnewswig/test_002_board_class.py b/qa/tests/pcbnewswig/test_002_board_class.py index 5d5c6733c2..63bbde4f13 100644 --- a/qa/tests/pcbnewswig/test_002_board_class.py +++ b/qa/tests/pcbnewswig/test_002_board_class.py @@ -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'