From 7b43446d61e97eb6029a578c6f5dfaacf34c4e8c Mon Sep 17 00:00:00 2001 From: Mika Fischer Date: Wed, 29 Jun 2011 14:26:32 +0200 Subject: [PATCH] Only query model for attribute values if necessary --- sloth/gui/propertyeditor.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/sloth/gui/propertyeditor.py b/sloth/gui/propertyeditor.py index b28cf40..6675ae8 100644 --- a/sloth/gui/propertyeditor.py +++ b/sloth/gui/propertyeditor.py @@ -5,6 +5,7 @@ from sloth.gui.utils import MyVBoxLayout from sloth.utils.bind import bind from PyQt4.QtCore import pyqtSignal, QSize, Qt from PyQt4.QtGui import QWidget, QGroupBox, QVBoxLayout, QPushButton, QScrollArea, QLineEdit, QDoubleValidator, QIntValidator, QShortcut, QKeySequence +import time import logging LOG = logging.getLogger(__name__) @@ -300,18 +301,22 @@ class PropertyEditor(QWidget): def onModelChanged(self, new_model): attrs = set([k for k, v in self._attribute_handlers.items() if v.autoAddEnabled()]) - attr2vals = {} - for item in new_model.iterator(AnnotationModelItem): - for attr in attrs: - if attr in item: - if attr not in attr2vals: - attr2vals[attr] = set((item[attr], )) - else: - attr2vals[attr] |= set((item[attr], )) - for attr, vals in attr2vals.items(): - h = self._attribute_handlers[attr] - for val in vals: - h.addValue(val, True) + if len(attrs) > 0: + start = time.time() + attr2vals = {} + for item in new_model.iterator(AnnotationModelItem): + for attr in attrs: + if attr in item: + if attr not in attr2vals: + attr2vals[attr] = set((item[attr], )) + else: + attr2vals[attr] |= set((item[attr], )) + diff = time.time() - start + LOG.info("Extracted annotation values from model in %.2fs" % diff) + for attr, vals in attr2vals.items(): + h = self._attribute_handlers[attr] + for val in vals: + h.addValue(val, True) def addLabelClass(self, label_config): # Check label configuration