From 0b20e5c92976a42762a925f952f36cbd52b7036d Mon Sep 17 00:00:00 2001 From: Tomas Raila Date: Thu, 25 Jan 2018 12:04:47 +0200 Subject: [PATCH] Show cursor coordinates in status bar --- labelImg.py | 7 ++++++- libs/canvas.py | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/labelImg.py b/labelImg.py index 735bf72f..8e6c8152 100755 --- a/labelImg.py +++ b/labelImg.py @@ -176,7 +176,7 @@ class MainWindow(QMainWindow, WindowMixin): self.zoomWidget = ZoomWidget() self.colorDialog = ColorDialog(parent=self) - self.canvas = Canvas() + self.canvas = Canvas(parent=self) self.canvas.zoomRequest.connect(self.zoomRequest) scroll = QScrollArea() @@ -456,6 +456,10 @@ class MainWindow(QMainWindow, WindowMixin): self.populateModeActions() + # Display cursor coordinates at the right of status bar + self.labelCoordinates = QLabel('') + self.statusBar().addPermanentWidget(self.labelCoordinates) + ## Support Functions ## def noShapes(self): @@ -525,6 +529,7 @@ class MainWindow(QMainWindow, WindowMixin): self.imageData = None self.labelFile = None self.canvas.resetState() + self.labelCoordinates.clear() def currentItem(self): items = self.labelList.selectedItems() diff --git a/libs/canvas.py b/libs/canvas.py index a211c4b9..6e79af5c 100644 --- a/libs/canvas.py +++ b/libs/canvas.py @@ -104,6 +104,12 @@ class Canvas(QWidget): """Update line with last point and current coordinates.""" pos = self.transformPos(ev.pos()) + # Update coordinates in status bar if image is opened + window = self.parent().window() + if window.filePath is not None: + self.parent().window().labelCoordinates.setText( + 'X: %d; Y: %d' % (pos.x(), pos.y())) + # Polygon drawing. if self.drawing(): self.overrideCursor(CURSOR_DRAW)