From 10afed2005948a591bc239d85cd018fb76bf00a6 Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Sat, 10 Mar 2012 13:08:25 +0100 Subject: [PATCH] add support to goto image by index --- sloth/annotations/model.py | 13 ++++++++----- sloth/core/labeltool.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/sloth/annotations/model.py b/sloth/annotations/model.py index 69e4c0e..0aadaad 100644 --- a/sloth/annotations/model.py +++ b/sloth/annotations/model.py @@ -46,6 +46,9 @@ class ModelItem: def childHasChildren(self, row): return self.childAt(row).hasChildren() + def row(self): + return self._row + def rowCount(self): return len(self._children) @@ -91,15 +94,15 @@ class ModelItem: return self._children[pos] def getPreviousSibling(self): - if self._parent is not None: - if self._row > 0: - return self._parent.childAt(self._row-1) - return None + return self.getSibling(self._row-1) def getNextSibling(self): + return self.getSibling(self._row+1) + + def getSibling(self, row): if self._parent is not None: try: - return self._parent.childAt(self._row+1) + return self._parent.childAt(row) except: pass return None diff --git a/sloth/core/labeltool.py b/sloth/core/labeltool.py index 4fca683..d7ac801 100755 --- a/sloth/core/labeltool.py +++ b/sloth/core/labeltool.py @@ -281,6 +281,18 @@ class LabelTool(QObject): def model(self): return self._model + def gotoIndex(self, idx): + if self._model is None: + return + + current = self._current_image + if current is None: + current = self._model.iterator(ImageModelItem).next() + + next_image = current.getSibling(idx) + if next_image is not None: + self.setCurrentImage(next_image) + def gotoNext(self, step=1): if self._model is not None: if self._current_image is not None: