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] 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"