From 8eb63e2985f22369c5b8750b3b8541ce938198ae Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Fri, 11 May 2012 17:33:30 +0200 Subject: [PATCH] write more sensible error messages to console if items do not contain a 'class' key --- sloth/annotations/model.py | 6 +++++- sloth/gui/annotationscene.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/sloth/annotations/model.py b/sloth/annotations/model.py index 71112a0..4acb7ce 100644 --- a/sloth/annotations/model.py +++ b/sloth/annotations/model.py @@ -519,7 +519,11 @@ class AnnotationModelItem(KeyValueModelItem): def data(self, role=Qt.DisplayRole, column=0): if role == Qt.DisplayRole: if column == 0: - return self['class'] + try: + return self['class'] + except KeyError: + LOG.error('Could not find key class in annotation item. Please check your label file.') + return '' elif column == 1 and self.isUnconfirmed(): return '[unconfirmed]' else: diff --git a/sloth/gui/annotationscene.py b/sloth/gui/annotationscene.py index 52981de..b295034 100644 --- a/sloth/gui/annotationscene.py +++ b/sloth/gui/annotationscene.py @@ -98,7 +98,11 @@ class AnnotationScene(QGraphicsScene): child = self._image_item.childAt(row) if not isinstance(child, AnnotationModelItem): continue - label_class = child['class'] + try: + label_class = child['class'] + except KeyError: + LOG.error('Could not find key class in annotation item. Skipping this item. Please check your label file.') + continue item = self._itemfactory.create(label_class, child) if item is not None: self.addItem(item)