diff --git a/sloth/gui/annotationscene.py b/sloth/gui/annotationscene.py index 182921c..a6d9f69 100644 --- a/sloth/gui/annotationscene.py +++ b/sloth/gui/annotationscene.py @@ -173,7 +173,7 @@ class AnnotationScene(QGraphicsScene): # # key event handlers #______________________________________________________________________________________________________ - def selectNextItem(self): + def selectNextItem(self, reverse=False): # disable inserting # TODO: forward this to the ButtonArea self.inserter_ = None @@ -182,24 +182,27 @@ class AnnotationScene(QGraphicsScene): if len(self.views()) > 0: self.views()[0].setFocus(True) - if len(self.selectedItems()) == 0: - for item in self.items(): - if (item.flags() & QGraphicsItem.ItemIsSelectable): - item.setSelected(True) - break - else: + # get the current selected item if there is any + selected_item = None + found = True + if len(self.selectedItems()) > 0: selected_item = self.selectedItems()[0] - idx = -1 - found = False - for i, item in enumerate(self.items() + self.items()): - if item is selected_item: - found = True - if found and item is not selected_item: - if (item.flags() & QGraphicsItem.ItemIsSelectable): - item.setSelected(True) - break selected_item.setSelected(False) + found = False + items = [item for item in self.items() + if item.flags() & QGraphicsItem.ItemIsSelectable] * 2 + if reverse: + items.reverse() + + for item in items: + if item is selected_item: + found = True + continue + + if found and item is not selected_item: + item.setSelected(True) + break def keyPressEvent(self, event): if self.debug_: diff --git a/sloth/gui/labeltool.py b/sloth/gui/labeltool.py index bc3cd3b..dacfd58 100755 --- a/sloth/gui/labeltool.py +++ b/sloth/gui/labeltool.py @@ -80,6 +80,13 @@ class MainWindow(QMainWindow): self.ui.menuPlugins.addAction(selectNextItem) self.shortcuts.append(selectNextItem) + selectPreviousItem = QAction("Select previous item", self) + selectPreviousItem.setShortcut(QKeySequence("Shift+Tab")) + selectPreviousItem.setEnabled(True) + selectPreviousItem.triggered.connect(lambda: self.scene.selectNextItem(True)) + self.ui.menuPlugins.addAction(selectPreviousItem) + self.shortcuts.append(selectPreviousItem) + ### ### GUI/Application setup ###___________________________________________________________________________________________