From 7460e4316b3de879c923c92bb346e8cf40730ce5 Mon Sep 17 00:00:00 2001 From: Jay Young Date: Wed, 8 Mar 2017 11:29:43 +0800 Subject: [PATCH 1/4] [FIX]when startup with out specify image, self.filePath will be None, but when loadFile get it, the filePath is 'None', so if there real is a img name as None, it will open it unexceptly [FIX]when open file, QImageReader.supportedImageFormats() gives items in QbyteArray type, so if do str(fmt) will gives bbmp so that open prompt will not be able to open any thing [FIX]in PyQT5, QFileDialog.getOpenFileName returns a tuple with (filename,filters) --- labelImg.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/labelImg.py b/labelImg.py index eac0ac76..4d828a8f 100755 --- a/labelImg.py +++ b/labelImg.py @@ -442,7 +442,7 @@ class MainWindow(QMainWindow, WindowMixin): self.updateFileMenu() # Since loading the file may take some time, make sure it runs in the # background. - self.queueEvent(partial(self.loadFile, self.filePath)) + self.queueEvent(partial(self.loadFile, self.filePath or "")) # Callbacks: self.zoomWidget.valueChanged.connect(self.paintCanvas) @@ -1014,13 +1014,14 @@ class MainWindow(QMainWindow, WindowMixin): return path = os.path.dirname(str(self.filePath))\ if self.filePath else '.' - formats = ['*.%s' % str(fmt).lower() - for fmt in QImageReader.supportedImageFormats()] + formats = ['*.%s' % fmt.data().decode("ascii").lower() for fmt in QImageReader.supportedImageFormats()] filters = "Image & Label files (%s)" % \ ' '.join(formats + ['*%s' % LabelFile.suffix]) filename = QFileDialog.getOpenFileName(self, '%s - Choose Image or Label file' % __appname__, path, filters) if filename: + if isinstance(filename, (tuple,list)): + filename=filename[0] self.loadFile(filename) def saveFile(self, _value=False): From 4d1ed6f7e6aa48f5ff74f6209f8850ab1e0dc81a Mon Sep 17 00:00:00 2001 From: Jay Young Date: Wed, 8 Mar 2017 11:41:06 +0800 Subject: [PATCH 2/4] [FIX]move hot key for open annotation from ctrl+q to Ctrl+Shift+O to avoid colision with Mac universial application quit key Command+Q --- labelImg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labelImg.py b/labelImg.py index 4d828a8f..097bbb73 100755 --- a/labelImg.py +++ b/labelImg.py @@ -204,7 +204,7 @@ class MainWindow(QMainWindow, WindowMixin): 'Ctrl+r', 'open', u'Change default saved Annotation dir') openAnnotation = action('&Open Annotation', self.openAnnotation, - 'Ctrl+q', 'openAnnotation', u'Open Annotation') + 'Ctrl+Shift+O', 'openAnnotation', u'Open Annotation') openNextImg = action('&Next Image', self.openNextImg, 'd', 'next', u'Open Next') From f631ce9339708bebaf51cee12c62210d2784db42 Mon Sep 17 00:00:00 2001 From: Jay Young Date: Wed, 8 Mar 2017 12:30:12 +0800 Subject: [PATCH 3/4] [FIX]in PyQT5, scroll does not work, because PyQT5 deprecated the orientation and delte method under QWheelEvent and replaced by angleDelta, so I add some code to detect what version of qt and use the correspond method to get delta --- libs/canvas.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/libs/canvas.py b/libs/canvas.py index 431ee87d..5efd13bb 100644 --- a/libs/canvas.py +++ b/libs/canvas.py @@ -512,16 +512,29 @@ class Canvas(QWidget): return super(Canvas, self).minimumSizeHint() def wheelEvent(self, ev): - if ev.orientation() == Qt.Vertical: + qt_version = 4 if hasattr(ev, "delta") else 5 + if qt_version == 4: + if ev.orientation() == Qt.Vertical: + v_delta = ev.delta() + h_delta = 0 + else: + h_delta = ev.delta() + v_delta = 0 + else: + delta = ev.angleDelta() + h_delta = delta.x() + v_delta = delta.y() + + if v_delta: mods = ev.modifiers() if Qt.ControlModifier == int(mods): - self.zoomRequest.emit(ev.delta()) + self.zoomRequest.emit(v_delta) else: - self.scrollRequest.emit(ev.delta(), + self.scrollRequest.emit(v_delta, Qt.Horizontal if (Qt.ShiftModifier == int(mods)) else Qt.Vertical) else: - self.scrollRequest.emit(ev.delta(), Qt.Horizontal) + self.scrollRequest.emit(h_delta, Qt.Horizontal) ev.accept() def keyPressEvent(self, ev): From 3778c43fad574a8912f23119d5972e4e8ad7d1b8 Mon Sep 17 00:00:00 2001 From: Jay Young Date: Wed, 8 Mar 2017 12:35:33 +0800 Subject: [PATCH 4/4] [IMP] For PyQt5, make scroll can happen on vertical and horizontal at the same time --- libs/canvas.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/libs/canvas.py b/libs/canvas.py index 5efd13bb..99866487 100644 --- a/libs/canvas.py +++ b/libs/canvas.py @@ -525,16 +525,12 @@ class Canvas(QWidget): h_delta = delta.x() v_delta = delta.y() - if v_delta: - mods = ev.modifiers() - if Qt.ControlModifier == int(mods): - self.zoomRequest.emit(v_delta) - else: - self.scrollRequest.emit(v_delta, - Qt.Horizontal if (Qt.ShiftModifier == int(mods)) - else Qt.Vertical) + mods = ev.modifiers() + if Qt.ControlModifier == int(mods) and v_delta: + self.zoomRequest.emit(v_delta) else: - self.scrollRequest.emit(h_delta, Qt.Horizontal) + v_delta and self.scrollRequest.emit(v_delta, Qt.Vertical) + h_delta and self.scrollRequest.emit(h_delta, Qt.Horizontal) ev.accept() def keyPressEvent(self, ev):