Skip to content

Commit

Permalink
bitcraze#349 Changed the anchor status update function to avoid delet…
Browse files Browse the repository at this point in the history
…ing and recreating Qt labels.

The constant recreation of labels forced the plots to be slightly resized, which in turn slowly zoomed the plots. Now the plots are stable after status updates.
  • Loading branch information
krichardsson committed Sep 5, 2018
1 parent 12e5d5b commit 3fa5b30
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/cfclient/ui/tabs/locopositioning_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,33 +828,39 @@ def _loco_sys_received(self, timestamp, data, logconf):
def _update_ranging_status_indicators(self):
container = self._anchor_stats_container

while not container.isEmpty():
label = container.takeAt(0).widget()
label.deleteLater()

ids = sorted(self._anchors.keys())

col = 1
row = 1

# Update existing labels or add new if needed
count = 0
for id in ids:
label = QLabel()
col = count % 8
row = int(count / 8)

if count < container.count():
label = container.itemAtPosition(row, col).widget()
else:
label = QLabel()
label.setMinimumSize(30, 0)
label.setProperty('frameShape', 'QFrame::Box')
label.setAlignment(Qt.AlignCenter)
container.addWidget(label, row, col)

label.setText(str(id))
label.setMinimumSize(30, 0)
label.setProperty('frameShape', 'QFrame::Box')
label.setAlignment(Qt.AlignCenter)

if self._anchors[id].is_active():
label.setStyleSheet(STYLE_GREEN_BACKGROUND)
else:
label.setStyleSheet(STYLE_RED_BACKGROUND)

container.addWidget(label, row, col)
count += 1

col += 1
if col > 8:
col = 1
row += 1
# Remove labels if there are too many
for i in range(count, container.count()):
col = i % 8
row = int(i / 8)

label = container.itemAtPosition(row, col).widget()
label.deleteLater()

def _logging_error(self, log_conf, msg):
"""Callback from the log layer when an error occurs"""
Expand Down

0 comments on commit 3fa5b30

Please sign in to comment.