From 9b2ebec35dca5497b1595d97682768a196ad348b Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Tue, 18 May 2021 21:08:02 +0200 Subject: [PATCH 1/3] Draft: Fixed make_label to accept list of strings for custom_text The make_label function should accept a list of strings for custom_text. Compare the make_text function. The new code was mostly taken from there. --- src/Mod/Draft/draftmake/make_label.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Mod/Draft/draftmake/make_label.py b/src/Mod/Draft/draftmake/make_label.py index 6a92c203e9..ef1ac958dc 100644 --- a/src/Mod/Draft/draftmake/make_label.py +++ b/src/Mod/Draft/draftmake/make_label.py @@ -119,8 +119,10 @@ def make_label(target_point=App.Vector(0, 0, 0), - `'Area'` will show the `Area` of the target object's `Shape`, or of the indicated `'FaceN'` in `target`. - custom_text: str, optional + custom_text: str, or list of str, optional It defaults to `'Label'`. + If it is a list, each element in the list represents a new text line. + It is the text that will be displayed by the label when `label_type` is `'Custom'`. @@ -280,11 +282,18 @@ def make_label(target_point=App.Vector(0, 0, 0), if not custom_text: custom_text = "Label" try: - utils.type_check([(custom_text, str)], name=_name) + utils.type_check([(custom_text, (str, list))]) except TypeError: - _err(translate("draft","Wrong input: must be a string.")) + _err(translate("draft","Wrong input: must be a list of strings or a single string.")) return None + if not all(isinstance(element, str) for element in custom_text): + _err(translate("draft","Wrong input: must be a list of strings or a single string.")) + return None + + if isinstance(custom_text, str): + custom_text = [custom_text] + _msg("direction: {}".format(direction)) if not direction: direction = "Horizontal" From 98e563c3d9f465003c01e83c1829d698c235d76c Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Sat, 22 May 2021 16:33:12 +0200 Subject: [PATCH 2/3] Update make_label.py If custom_text is a string there is no need to put it in a list. --- src/Mod/Draft/draftmake/make_label.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Mod/Draft/draftmake/make_label.py b/src/Mod/Draft/draftmake/make_label.py index ef1ac958dc..5ffac5b2fb 100644 --- a/src/Mod/Draft/draftmake/make_label.py +++ b/src/Mod/Draft/draftmake/make_label.py @@ -291,9 +291,6 @@ def make_label(target_point=App.Vector(0, 0, 0), _err(translate("draft","Wrong input: must be a list of strings or a single string.")) return None - if isinstance(custom_text, str): - custom_text = [custom_text] - _msg("direction: {}".format(direction)) if not direction: direction = "Horizontal" From 57de4681ec87995ced847751df403c66d81325e8 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Mon, 24 May 2021 18:42:27 +0200 Subject: [PATCH 3/3] Update make_label.py Brought back name=_name. Added type(custom_text) is list check. --- src/Mod/Draft/draftmake/make_label.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Mod/Draft/draftmake/make_label.py b/src/Mod/Draft/draftmake/make_label.py index 5ffac5b2fb..c4505b8178 100644 --- a/src/Mod/Draft/draftmake/make_label.py +++ b/src/Mod/Draft/draftmake/make_label.py @@ -282,12 +282,13 @@ def make_label(target_point=App.Vector(0, 0, 0), if not custom_text: custom_text = "Label" try: - utils.type_check([(custom_text, (str, list))]) + utils.type_check([(custom_text, (str, list))], name=_name) except TypeError: _err(translate("draft","Wrong input: must be a list of strings or a single string.")) return None - if not all(isinstance(element, str) for element in custom_text): + if (type(custom_text) is list + and not all(isinstance(element, str) for element in custom_text)): _err(translate("draft","Wrong input: must be a list of strings or a single string.")) return None