Skip to content

Commit

Permalink
Merge pull request #159 from UCL/158-return-strs
Browse files Browse the repository at this point in the history
Issue #158: Return empty string rather than None when there is no text
  • Loading branch information
tdowrick committed Oct 23, 2020
2 parents 60b93ff + 818acf0 commit 3564ce9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion sksurgeryvtk/text/text_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ def get_text(self):
Returns the current list of text annotations
:return: [bottom-left, bottom-right, top-left, top-right]
"""
return [self.text_actor.GetText(0),

text = [self.text_actor.GetText(0),
self.text_actor.GetText(1),
self.text_actor.GetText(2),
self.text_actor.GetText(3)]

# Set None values to ''
text_all_str = ['' if x is None else x for x in text]

return text_all_str

def set_text_on_top_left(self, text):
"""
Set the text on the top-left corner.
Expand Down
8 changes: 4 additions & 4 deletions tests/text/test_corner_annotaiton.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def test_setter_getter(corner_annotaiton):

initial = corner_annotaiton.get_text()
assert len(initial) == 4
assert initial[0] is None
assert initial[1] is None
assert initial[2] is None
assert initial[3] is None
assert initial[0] is ''
assert initial[1] is ''
assert initial[2] is ''
assert initial[3] is ''
stuff_to_set = ['Snappy', 'is', 'totally', 'awesome']
corner_annotaiton.set_text(stuff_to_set)
stuff_retrieved = corner_annotaiton.get_text()
Expand Down

0 comments on commit 3564ce9

Please sign in to comment.