From 7460e4316b3de879c923c92bb346e8cf40730ce5 Mon Sep 17 00:00:00 2001 From: Jay Young Date: Wed, 8 Mar 2017 11:29:43 +0800 Subject: [PATCH] [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):