Draft: fix Draft_Label MaxChars property (#27478)
* Draft: fix Draft_Label MaxChars property Signed-off-by: Yash Suthar <yashsuthar983@gmail.com> * Minor tweak: moved/replaced call to self.onChanged --------- Signed-off-by: Yash Suthar <yashsuthar983@gmail.com> Co-authored-by: Roy-043 <70520633+Roy-043@users.noreply.github.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
# @{
|
||||
import math
|
||||
import sys
|
||||
import textwrap
|
||||
import pivy.coin as coin
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
@@ -189,6 +190,21 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
|
||||
self.onChanged(vobj, "ArrowSizeStart")
|
||||
self.onChanged(vobj, "Line")
|
||||
|
||||
def update_text(self, obj, vobj):
|
||||
"""Update the text string in the scene, wrapping it if needed."""
|
||||
self.text_wld.string.setValue("")
|
||||
self.text_scr.string.setValue("")
|
||||
_list = [l for l in obj.Text if l] if obj.Text else []
|
||||
|
||||
if _list and hasattr(vobj, "MaxChars") and vobj.MaxChars > 0:
|
||||
new_list = []
|
||||
for line in _list:
|
||||
new_list.extend(textwrap.wrap(line, vobj.MaxChars))
|
||||
_list = new_list
|
||||
|
||||
self.text_wld.string.setValues(_list)
|
||||
self.text_scr.string.setValues(_list)
|
||||
|
||||
def updateData(self, obj, prop):
|
||||
"""Execute when a property from the Proxy class is changed."""
|
||||
vobj = obj.ViewObject
|
||||
@@ -222,20 +238,11 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
|
||||
if vobj.Justification == "Right":
|
||||
vobj.Justification = "Left"
|
||||
|
||||
self.onChanged(
|
||||
obj.ViewObject, "DisplayMode"
|
||||
) # Property to trigger update_label and update_frame.
|
||||
# We could have used a different property.
|
||||
self.onChanged(vobj, "DisplayMode") # trigger update_label and update_frame.
|
||||
|
||||
elif prop == "Text" and obj.Text:
|
||||
self.text_wld.string.setValue("")
|
||||
self.text_scr.string.setValue("")
|
||||
|
||||
_list = [l for l in obj.Text if l]
|
||||
|
||||
self.text_wld.string.setValues(_list)
|
||||
self.text_scr.string.setValues(_list)
|
||||
self.onChanged(obj.ViewObject, "DisplayMode")
|
||||
self.update_text(obj, vobj)
|
||||
self.onChanged(vobj, "DisplayMode") # idem
|
||||
|
||||
def onChanged(self, vobj, prop):
|
||||
"""Execute when a view property is changed."""
|
||||
@@ -269,6 +276,13 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
|
||||
if can_update_frame:
|
||||
self.update_frame(obj, vobj)
|
||||
|
||||
elif prop == "MaxChars" and "MaxChars" in properties:
|
||||
self.update_text(obj, vobj)
|
||||
if can_update_label:
|
||||
self.update_label(obj, vobj)
|
||||
if can_update_frame:
|
||||
self.update_frame(obj, vobj)
|
||||
|
||||
elif prop == "ScaleMultiplier" and "ScaleMultiplier" in properties:
|
||||
if "ArrowSizeStart" in properties:
|
||||
s = vobj.ArrowSizeStart.Value * vobj.ScaleMultiplier
|
||||
|
||||
Reference in New Issue
Block a user