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.
This commit is contained in:
Roy-043
2021-05-18 21:08:02 +02:00
committed by GitHub
parent 3d3f93470b
commit 9b2ebec35d

View File

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