From 494cab9fbde9fa52c48a458365eac3f5d8db350f Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Mon, 31 Jan 2011 12:35:23 +0100 Subject: [PATCH] allow labeling of ids --- annotationmodel.py | 9 +++++++++ annotationscene.py | 22 +++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/annotationmodel.py b/annotationmodel.py index 8955675..6d27a89 100644 --- a/annotationmodel.py +++ b/annotationmodel.py @@ -433,6 +433,15 @@ class AnnotationModel(QAbstractItemModel): return index + def asDictList(self): + """return annotations as python list of dictionary""" + # TODO + annotations = [] + if self.root_ is not None: + for child in self.root_.children_: + pass + + ####################################################################################### # proxy model diff --git a/annotationscene.py b/annotationscene.py index e00d9bb..1f6c3c4 100644 --- a/annotationscene.py +++ b/annotationscene.py @@ -148,6 +148,7 @@ class AnnotationScene(QGraphicsScene): self.inserter_ = None self.debug_ = True self.message_ = "" + self.last_key_ = None self.setBackgroundBrush(Qt.darkGray) @@ -222,6 +223,7 @@ class AnnotationScene(QGraphicsScene): def insertItems(self, first, last): assert self.model_ is not None assert self.root_.isValid() + print "insertItems" for row in range(first, last+1): child = self.root_.child(row, 0) @@ -299,8 +301,8 @@ class AnnotationScene(QGraphicsScene): QGraphicsScene.mouseReleaseEvent(self, event) def mouseMoveEvent(self, event): - if self.debug_: - print "mouseMoveEvent", self.sceneRect().contains(event.scenePos()), event.scenePos() + #if self.debug_: + # print "mouseMoveEvent", self.sceneRect().contains(event.scenePos()), event.scenePos() if self.inserter_ is not None: # insert mode self.inserter_.mouseMoveEvent(event, self.root_) @@ -329,7 +331,21 @@ class AnnotationScene(QGraphicsScene): index = item.index() index.model().removeAnnotation(index) event.accept() - return + return + + if ord('0') <= event.key() <= ord('9'): + if self.last_key_ is None: + self.last_key_ = event.key() + else: + id = chr(self.last_key_) + chr(event.key()) + print "id=", id + for item in self.selectedItems(): + index = item.index() + data = dict(index.data(DataRole).toPyObject().iteritems()) + if data['type'] == 'rect': + data['id'] = id + index.model().setData(index, QVariant(data), DataRole) + self.last_key_ = None event.ignore()