From 157a4173f3b330355389c4889d2bb9d295f57d66 Mon Sep 17 00:00:00 2001 From: Eduard Tamsa Date: Thu, 3 Oct 2019 22:26:09 +0300 Subject: [PATCH] Add Silent option for openDirDialog Add Silent option for openDirDialog to facilitate opening a directory at start up if the filePath provided is a directory without opening the file selector UI. --- labelImg.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/labelImg.py b/labelImg.py index 6e0e03ac..c3fcd607 100755 --- a/labelImg.py +++ b/labelImg.py @@ -474,7 +474,7 @@ class MainWindow(QMainWindow, WindowMixin): # Open Dir if deafult file if self.filePath and os.path.isdir(self.filePath): - self.openDirDialog(dirpath=self.filePath) + self.openDirDialog(dirpath=self.filePath, silent=True) def keyReleaseEvent(self, event): if event.key() == Qt.Key_Control: @@ -1170,7 +1170,7 @@ class MainWindow(QMainWindow, WindowMixin): filename = filename[0] self.loadPascalXMLByFilename(filename) - def openDirDialog(self, _value=False, dirpath=None): + def openDirDialog(self, _value=False, dirpath=None, silent=False): if not self.mayContinue(): return @@ -1179,10 +1179,13 @@ class MainWindow(QMainWindow, WindowMixin): defaultOpenDirPath = self.lastOpenDir else: defaultOpenDirPath = os.path.dirname(self.filePath) if self.filePath else '.' + if silent!=True : + targetDirPath = ustr(QFileDialog.getExistingDirectory(self, + '%s - Open Directory' % __appname__, defaultOpenDirPath, + QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)) + else: + targetDirPath = ustr(defaultOpenDirPath) - targetDirPath = ustr(QFileDialog.getExistingDirectory(self, - '%s - Open Directory' % __appname__, defaultOpenDirPath, - QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks)) self.importDirImages(targetDirPath) def importDirImages(self, dirpath):