Merge branch '149-python-vtk-improvements' into 'development'

don't add empty strings

Closes #149

See merge request damask/DAMASK!673
This commit is contained in:
Philip Eisenlohr 2022-11-28 20:05:40 +00:00
commit 3505fdee9a
2 changed files with 11 additions and 6 deletions

View File

@ -116,7 +116,10 @@ class VTK:
""" """
s = vtk.vtkStringArray() s = vtk.vtkStringArray()
s.SetName('comments') s.SetName('comments')
for c in util.tail_repack(comments,self.comments): comments_ = util.tail_repack(comments,self.comments) if comments[:len(self.comments)] == self.comments else \
[comments] if isinstance(comments,str) else \
comments
for c in comments_:
s.InsertNextValue(c) s.InsertNextValue(c)
self.vtk_data.GetFieldData().AddArray(s) self.vtk_data.GetFieldData().AddArray(s)
@ -547,9 +550,11 @@ class VTK:
Notes Notes
----- -----
See http://compilatrix.com/article/vtk-1 for further ideas. The first component is shown when visualizing vector datasets
(this includes tensor datasets because they are flattened).
""" """
# See http://compilatrix.com/article/vtk-1 for possible improvements.
try: try:
import wx import wx
_ = wx.App(False) # noqa _ = wx.App(False) # noqa

View File

@ -793,7 +793,7 @@ def tail_repack(extended: _Union[str, _Sequence[str]],
Parameters Parameters
---------- ----------
extended : (list of) str extended : (sequence of) str
Extended string list with potentially autosplitted tailing string relative to `existing`. Extended string list with potentially autosplitted tailing string relative to `existing`.
existing : list of str existing : list of str
Base string list. Base string list.
@ -811,9 +811,9 @@ def tail_repack(extended: _Union[str, _Sequence[str]],
['a','new','shiny','e','n','t','r','y'] ['a','new','shiny','e','n','t','r','y']
""" """
return [extended] if isinstance(extended,str) else existing + \ new = extended[len(existing):]
([''.join(extended[len(existing):])] if _np.prod([len(i) for i in extended[len(existing):]]) == 1 else return [extended] if isinstance(extended,str) else \
list(extended[len(existing):])) existing + list([''.join(new)] if _np.prod([len(i) for i in new]) == 1 else new)
def aslist(arg: _Union[_IntCollection, int, None]) -> _List: def aslist(arg: _Union[_IntCollection, int, None]) -> _List: