From 65830b4b7bfe485a5dad93a528933cb68e327863 Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Fri, 17 Jun 2011 09:31:10 +0200 Subject: [PATCH] make deletion hotkey configurable (fixes #10) --- sloth/annotations/model.py | 8 -------- sloth/conf/default_config.py | 11 ++++++----- sloth/core/labeltool.py | 5 +++++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/sloth/annotations/model.py b/sloth/annotations/model.py index 36d3e35..f2c59b8 100644 --- a/sloth/annotations/model.py +++ b/sloth/annotations/model.py @@ -530,14 +530,6 @@ class AnnotationTreeView(QTreeView): QTreeView.setModel(self, model) self.resizeColumns() - def keyPressEvent(self, event): - ## handle deletions of items - if event.key() == Qt.Key_Delete: - self.model().itemFromIndex(self.currentindex()).delete() - - ## it is important to use the keyPressEvent of QAbstractItemView, not QTreeView - QAbstractItemView.keyPressEvent(self, event) - def rowsInserted(self, index, start, end): QTreeView.rowsInserted(self, index, start, end) self.resizeColumns() diff --git a/sloth/conf/default_config.py b/sloth/conf/default_config.py index 120943e..20e33e4 100644 --- a/sloth/conf/default_config.py +++ b/sloth/conf/default_config.py @@ -61,11 +61,12 @@ LABELS = ( # third entry -- if present -- is expected to be a string describing the # action. HOTKEYS = ( - ('PgDown', lambda lt: lt.gotoNext(), 'Next image/frame'), - ('PgUp', lambda lt: lt.gotoPrevious(), 'Previous image/frame'), - ('Tab', lambda lt: lt.selectNextAnnotation(), 'Select next annotation'), - ('Shift+Tab', lambda lt: lt.selectPreviousAnnotation(), 'Select previous annotation'), - ('ESC', lambda lt: lt.exitInsertMode(), 'Exit insert mode'), + ('PgDown', lambda lt: lt.gotoNext(), 'Next image/frame'), + ('PgUp', lambda lt: lt.gotoPrevious(), 'Previous image/frame'), + ('Tab', lambda lt: lt.selectNextAnnotation(), 'Select next annotation'), + ('Shift+Tab', lambda lt: lt.selectPreviousAnnotation(), 'Select previous annotation'), + ('Del', lambda lt: lt.deleteSelectedAnnotations(), 'Delete selected annotations'), + ('ESC', lambda lt: lt.exitInsertMode(), 'Exit insert mode'), ) # CONTAINERS diff --git a/sloth/core/labeltool.py b/sloth/core/labeltool.py index fdec7cf..2e24e6a 100755 --- a/sloth/core/labeltool.py +++ b/sloth/core/labeltool.py @@ -347,6 +347,11 @@ class LabelTool(QObject): if self._mainwindow is not None: return self._mainwindow.scene.selectNextItem(reverse=True) + def deleteSelectedAnnotations(self): + if self._mainwindow is not None: + for item in self._mainwindow.scene.selectedItems(): + item.modelItem().delete() + def exitInsertMode(self): if self._mainwindow is not None: return self._mainwindow.buttonarea.exitInsertMode()