Browse Source

Merge branch '9-start-option-to-add-images' into 'master'

Resolve "start option to add images"

Closes #9

See merge request troebs/pycs!8
Eric Tröbs 4 years ago
parent
commit
0b4c006aa2
2 changed files with 23 additions and 34 deletions
  1. 2 0
      main.py
  2. 21 34
      pycs/ui/MainWindow.py

+ 2 - 0
main.py

@@ -14,6 +14,8 @@ def main(args):
 
 
     if len(args) > 1:
     if len(args) > 1:
         window.project_open(args[1])
         window.project_open(args[1])
+    if len(args) > 2:
+        window.predict_via_dialog(args[2:])
 
 
     retval = app.exec_()
     retval = app.exec_()
     return retval
     return retval

+ 21 - 34
pycs/ui/MainWindow.py

@@ -79,8 +79,8 @@ class MainWindow:
         # Help
         # Help
         self.ui.actionAbout.triggered.connect(self._help_about)
         self.ui.actionAbout.triggered.connect(self._help_about)
 
 
-        self.ui.actionPredict_Images.triggered.connect(self._predict_via_dialog)
-        self.ui.predictButton.clicked.connect(self._predict_via_dialog)
+        self.ui.actionPredict_Images.triggered.connect(self.predict_via_dialog)
+        self.ui.predictButton.clicked.connect(self.predict_via_dialog)
 
 
         self.ui.imageThumbnailGallery.currentRowChanged.connect(self._prediction_row_changed)
         self.ui.imageThumbnailGallery.currentRowChanged.connect(self._prediction_row_changed)
 
 
@@ -162,7 +162,7 @@ class MainWindow:
             if w_retval:
             if w_retval:
                 self._project = Project(w.project_root, w.project_config)
                 self._project = Project(w.project_root, w.project_config)
 
 
-    def project_open(self, path=None):
+    def project_open(self, path=False):
         """
         """
         opens a project by either using the optional parameter path or
         opens a project by either using the optional parameter path or
         or the value the user enters using the ui file dialog
         or the value the user enters using the ui file dialog
@@ -176,7 +176,7 @@ class MainWindow:
             return
             return
 
 
         # copy path to selection or question user if not given
         # copy path to selection or question user if not given
-        if path is not None and path != False:
+        if path is not False:
             selection = path
             selection = path
         else:
         else:
             selection, _ = QtWidgets.QFileDialog.getOpenFileName(self.ui, 'Select Project Folder', filter='project.json')
             selection, _ = QtWidgets.QFileDialog.getOpenFileName(self.ui, 'Select Project Folder', filter='project.json')
@@ -219,18 +219,28 @@ class MainWindow:
     #####################################
     #####################################
     # Prediction actions and management #
     # Prediction actions and management #
     #####################################
     #####################################
-    def _predict_via_dialog(self):
-        # '''
-        # {'filename': filename, 'filetype': filetype, 'jobs': ['detect-faces']}
+    def predict_via_dialog(self, selection=False):
+        """
+        loads images from given paths or ui file dialog
+        :param selection: array of image paths
+        :return:
+        """
+
+        # valid image and video extensions
         image_extensions = ['.jpg', '.png', '.jpeg']
         image_extensions = ['.jpg', '.png', '.jpeg']
         video_extensions = ['.mp4', '.avi', '.mkv', '.mpg', '.mpeg']
         video_extensions = ['.mp4', '.avi', '.mkv', '.mpg', '.mpeg']
 
 
-        name_list = ' '.join(['*' + extension for extension in image_extensions + video_extensions])
-        extensions = f'All supported files ({name_list})'
+        # ask user for input
+        if selection is False:
+            name_list = ' '.join(['*' + extension for extension in image_extensions + video_extensions])
+            extensions = f'All supported files ({name_list})'
 
 
+            selection, _ = QtWidgets.QFileDialog.getOpenFileNames(self.ui, 'Select Files To Add', filter=extensions)
+
+        # load jobs
         jobs = []
         jobs = []
-        selection = QtWidgets.QFileDialog.getOpenFileNames(self.ui, 'Select Files To Add', filter=extensions)
-        for filename in selection[0]:
+
+        for filename in selection:
             _, extension = os.path.splitext(filename)
             _, extension = os.path.splitext(filename)
             extension = extension.lower()
             extension = extension.lower()
 
 
@@ -260,29 +270,6 @@ class MainWindow:
         progress_dialog.close()
         progress_dialog.close()
         self._predictions += jobs
         self._predictions += jobs
 
 
-        '''
-        TODO: remove PredictionDialog.py
-
-        prediction_dialog = PredictionDialog(parent=self.ui)
-        if prediction_dialog.exec_():
-
-            # TODO extract callback and progress dialog to make it reusable
-            jobs = copy.deepcopy(prediction_dialog.jobs)
-            print(jobs)
-            progress_dialog = QtWidgets.QProgressDialog('Executing prediction jobs...', 'Abort', 0, 1000, self.ui)
-            progress_dialog.setWindowModality(QtCore.Qt.WindowModal)
-
-            def callback(progress):
-                progress_dialog.setValue(int(progress * 1000))
-                for i in range(10):
-                    QtWidgets.QApplication.processEvents()
-
-            self._project.execute(jobs, callback=callback)
-
-            progress_dialog.close()
-            self._predictions += jobs
-        '''
-
     def _update_prediction_ui(self):
     def _update_prediction_ui(self):
         # TODO implement better sync
         # TODO implement better sync
         self.ui.imageThumbnailGallery.clear()
         self.ui.imageThumbnailGallery.clear()