From e0fa0534d5f039428f44dad76ae29e0121fdb07c Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Thu, 10 Apr 2014 19:30:44 +0200 Subject: [PATCH] Use the Enter key to finish the polygon Using abort() (aka Escape) is not the right way to finish the polygon. Use the Enter key instead. It works this way in Inkscape. Display a message to instruct the user to use the Enter key to finish the polygon. --- sloth/items/inserters.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sloth/items/inserters.py b/sloth/items/inserters.py index 35e0bc4..523c9dd 100644 --- a/sloth/items/inserters.py +++ b/sloth/items/inserters.py @@ -336,6 +336,8 @@ class PolygonItemInserter(ItemInserter): self._item.setPen(self.pen()) self._scene.addItem(item) self._current_image_item = image_item + + self._scene.setMessage("Press Enter to finish the polygon.") else: polygon = self._item.polygon() polygon.append(pos) @@ -353,9 +355,11 @@ class PolygonItemInserter(ItemInserter): event.accept() - def abort(self): - # XXX Is it abuse to handle the end of inserting here in abort()? - if self._item is not None: + def keyPressEvent(self, event, image_item): + """ + When the user presses Enter, the polygon is finished. + """ + if event.key() == Qt.Key_Return and self._item is not None: polygon = self._item.polygon() assert polygon.size() > 0 @@ -377,5 +381,6 @@ class PolygonItemInserter(ItemInserter): self._init_pos = None self._item = None self._current_image_item = None + self._scene.clearMessage() self.inserterFinished.emit()