From ab721f663a5b9ffc71e1224196e9010b3afe6e20 Mon Sep 17 00:00:00 2001 From: healthonrails Date: Thu, 30 May 2024 09:48:35 -0400 Subject: [PATCH] Clear flag widget when there is no string after 'flags' in the text prompt Ensures the flag widget is cleared of all items if there is no string after 'flags' in the text prompt. This prevents any outdated or irrelevant items from being displayed, maintaining an accurate and clean state for the widget. --- annolid/gui/app.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/annolid/gui/app.py b/annolid/gui/app.py index 90d2457..cf4c11f 100644 --- a/annolid/gui/app.py +++ b/annolid/gui/app.py @@ -619,10 +619,15 @@ def _grounding_sam(self): return # Check if the prompt starts with 'flags:' and contains flags separated by commas - if prompt_text.startswith('flags:') and ',' in prompt_text: + if prompt_text.startswith('flags:'): flags = {k.strip(): False for k in prompt_text.replace( - 'flags:', '').split(',')} - self.loadFlags(flags) + 'flags:', '').split(',') if len(k.strip()) > 0} + if len(flags.keys()) > 0: + self.loadFlags(flags) + else: + # # If there is no string after 'flags' + # in the text prompt, clear the flag widget + self.flag_widget.clear() else: self.canvas.predictAiRectangle(prompt_text) @@ -1186,6 +1191,13 @@ def predict_is_ready(self, messege): self, "Prediction Ready", "Predictions for the video frames have been generated!") + def loadFlags(self, flags): + for key, flag in flags.items(): + item = QtWidgets.QListWidgetItem(key) + item.setFlags(item.flags() | Qt.ItemIsUserCheckable) + item.setCheckState(Qt.Checked if flag else Qt.Unchecked) + self.flag_widget.addItem(item) + def saveLabels(self, filename): lf = LabelFile() has_zone_shapes = False