Draft: Draft_Label fix label type list

This commit is contained in:
Roy
2021-12-10 18:40:43 +01:00
parent 306dc171f4
commit 418ca4a235
4 changed files with 31 additions and 20 deletions

View File

@@ -1016,11 +1016,11 @@ class DraftToolBar:
w.setWindowTitle(translate("draft","Label type", utf8_decode=True))
l = QtGui.QVBoxLayout(w)
combo = QtGui.QComboBox()
for s in ["Custom","Name","Label","Position","Length","Area","Volume","Tag","Material"]:
from draftobjects.label import get_label_types
types = get_label_types()
for s in types:
combo.addItem(s)
combo.setCurrentIndex(
["Custom","Name","Label","Position","Length","Area","Volume","Tag","Material"]\
.index(Draft.getParam("labeltype","Custom")))
combo.setCurrentIndex(types.index(Draft.getParam("labeltype","Custom")))
l.addWidget(combo)
QtCore.QObject.connect(combo,QtCore.SIGNAL("currentIndexChanged(int)"),callback)
self.pointUi(title=title, extra=w, icon="Draft_Label")

View File

@@ -82,8 +82,8 @@ class Label(gui_base_original.Creator):
def setmode(self, i):
"""Set the type of label, if it is associated to an object."""
self.labeltype = ["Custom", "Name", "Label", "Position",
"Length", "Area", "Volume", "Tag", "Material"][i]
from draftobjects.label import get_label_types
self.labeltype = get_label_types()[i]
utils.setParam("labeltype", self.labeltype)
def finish(self, closed=False, cont=False):

View File

@@ -33,10 +33,10 @@
import FreeCAD as App
import draftutils.gui_utils as gui_utils
import draftutils.utils as utils
import draftobjects.label as label
from draftutils.messages import _msg, _wrn, _err
from draftutils.translate import translate
from draftobjects.label import Label
if App.GuiUp:
from draftviewproviders.view_label import ViewProviderLabel
@@ -104,9 +104,8 @@ def make_label(target_point=App.Vector(0, 0, 0),
label_type: str, optional
It defaults to `'Custom'`.
It can be `'Custom'`, `'Name'`, `'Label'`, `'Position'`,
`'Length'`, `'Area'`, `'Volume'`, `'Tag'`, or `'Material'`.
It indicates the type of information that will be shown in the label.
See the get_label_types function in label.py for supported types.
Only `'Custom'` allows you to manually set the text
by defining `custom_text`. The other types take their information
@@ -270,12 +269,12 @@ def make_label(target_point=App.Vector(0, 0, 0),
try:
utils.type_check([(label_type, str)], name=_name)
except TypeError:
_err(translate("draft","Wrong input: must be a string, 'Custom', 'Name', 'Label', 'Position', 'Length', 'Area', 'Volume', 'Tag', or 'Material'."))
_err(translate("draft","Wrong input: label_type must be a string."))
return None
if label_type not in ("Custom", "Name", "Label", "Position",
"Length", "Area", "Volume", "Tag", "Material"):
_err(translate("draft","Wrong input: must be a string, 'Custom', 'Name', 'Label', 'Position', 'Length', 'Area', 'Volume', 'Tag', or 'Material'."))
types = label.get_label_types()
if label_type not in types:
_err(translate("draft", "Wrong input: label_type must be one of the following: ") + str(types).strip("[]"))
return None
_msg("custom_text: {}".format(custom_text))
@@ -334,7 +333,7 @@ def make_label(target_point=App.Vector(0, 0, 0),
new_obj = doc.addObject("App::FeaturePython",
"dLabel")
Label(new_obj)
label.Label(new_obj)
new_obj.TargetPoint = target_point
new_obj.Placement = placement

View File

@@ -217,12 +217,7 @@ class Label(DraftAnnotation):
"LabelType",
"Label",
_tip)
obj.LabelType = ["Custom", "Name", "Label", "Position",
"Length", "Area", "Volume",
"Tag", "Material",
"Label + Position", "Label + Length",
"Label + Area", "Label + Volume",
"Label + Material"]
obj.LabelType = get_label_types()
def onDocumentRestored(self, obj):
"""Execute code when the document is restored.
@@ -298,6 +293,23 @@ class Label(DraftAnnotation):
DraftLabel = Label
def get_label_types():
return ["Custom",
"Name",
"Label",
"Position",
"Length",
"Area",
"Volume",
"Tag",
"Material",
"Label + Position",
"Label + Length",
"Label + Area",
"Label + Volume",
"Label + Material"]
def return_info(target, typ, subelement=None):
"""Return the text list from the target and the given type.