From d47cd439489b9b658c5e523f39674956a6d42cc6 Mon Sep 17 00:00:00 2001 From: Mike Gerber Date: Wed, 8 Oct 2014 14:50:47 +0200 Subject: [PATCH] Add a plugin to enumerate the corners of polygon items --- sloth/plugins/__init__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sloth/plugins/__init__.py b/sloth/plugins/__init__.py index 6c33bff..a62638d 100644 --- a/sloth/plugins/__init__.py +++ b/sloth/plugins/__init__.py @@ -85,3 +85,27 @@ class CopyAnnotationsPlugin(QObject): def action(self): return self._sc + + +class PolygonEnumeratorPlugin(QObject): + """Enumerate the corners of polygons.""" + + def __init__(self, labeltool): + QObject.__init__(self) + + # Decorate the paint() method with our enumerating paint: + from sloth.items import PolygonItem + oldpaint = PolygonItem.paint + + def paint(self, painter, option, widget=None): + oldpaint(self, painter, option, widget) + for i, p in enumerate(self._polygon): + painter.drawText(p, str(i)) + + import functools + functools.update_wrapper(paint, oldpaint) + + PolygonItem.paint = paint + + def action(self): + return None