Skip to content

Commit

Permalink
Clean up widgets in plot_view layout correctly
Browse files Browse the repository at this point in the history
Iterating over the widgets in the layout in forward order when
attempting to delete all of the widgets in a layout resulted in
some widgets not getting deleted properly. Instead, they should
be interated over in reverse order so that the indices for each
widget do not change and all are deleted.

Fixes #5

Signed-off-by: Michael Jeronimo <michael.jeronimo@openrobotics.org>
  • Loading branch information
mjeronimo committed Oct 19, 2020
1 parent 65a6482 commit 152b6c0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rqt_bag/src/rqt_bag/timeline_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def show(self, context):
self._timeline.remove_listener(self._topic, self._viewer)
self._viewer = None

# clean out the layout
while self.layout().count() > 0:
item = self.layout().itemAt(0)
self.layout().removeItem(item)
# Clean out the layout. Loop backwards since removing
# from the beginning shifts items and changes the order
for i in reversed(range(self.layout().count())):
self.layout().itemAt(i).widget().setParent(None)

# create a new viewer
self._viewer = self._viewer_type(self._timeline, self, self._topic)
Expand Down

0 comments on commit 152b6c0

Please sign in to comment.