예제 #1
0
    def convertFolders(self):

        # Only process if the folder is not empty
        if self.directory is not None:

            # Get all the folders to save
            folders_to_save = []
            for i, crt_checkbox in enumerate(self.all_checkboxes):

                if crt_checkbox.isChecked():
                    folders_to_save.append(
                        os.path.join(self.directory, self.folders[i]))

            # Process the folders
            if len(folders_to_save) == 0:
                errorMessage(
                    "Empty selection",
                    "The current selection of folders to be converted is empty. Select at least one folder to proceed."
                )

            else:
                # Get the status of the checkbox
                delete_folders = self.deleteFoldersCheckbox.isChecked()

                # Process all the folders
                openWindow(self.parent,
                           ConvertFolderProgressBarWindow,
                           'progress_bar',
                           folder_list=folders_to_save,
                           delete_folders=delete_folders,
                           scheduler=self)
예제 #2
0
    def saveTrajectoryFile(self):

        # Check if a tab is open
        if len(self.parent.imageTabDisplay.displayedTabs) > 0:

            # Retrieve the current tab ID
            tab_id = self.parent.imageTabDisplay.currentIndex()
            crt_traj = self.parent.imageTabDisplay.displayedTabs[
                tab_id].image_class.trajectory

            # Save the trajectory in a file
            if crt_traj is not None:

                # Get the file name
                trajectory_file, _ = qtw.QFileDialog.getSaveFileName(
                    self.parent, "Save Trajectory...", "",
                    "Hierarchical Data (*.xml);;Comma-Separated Value (*.csv)")

                if trajectory_file != "":
                    crt_traj.save(file_name=trajectory_file)

            # Display message if there are no trajectory opened
            else:
                errorMessage(
                    "No Trajectory",
                    "There is no loaded trajectory to be saved in a file.")

        else:
            errorMessageNoImage()
예제 #3
0
    def newTracker(self):

        # Prompt the user for the file name
        tracker_name, ok = qtw.QInputDialog.getText(self, "Tracker Name", "Name of the new tracker?")

        if ok:

            # Raise an error if the 'Default' tracker is selected
            if tracker_name == 'Default':
                errorMessage('Forbidden Action',"The settings of the Default tracker cannot be edited.")

            else:

                # Check if the name is in the list
                _write = True
                trackers_list = listTrackerConfigs()
                if tracker_name in trackers_list:
                    _write = warningProceedMessage('Existing Tracker','The selected tracker name ('+tracker_name+') is already in the memory. Do you want to replace it?')

                if _write:

                    # Update the selection
                    self.updateDetectionSession()

                    # Collect the settings
                    self.current_tracker = tracker_name
                    self.trajectory_session.name = tracker_name
                    self.trajectory_session.modified = True

                    # Save the tracker session in file
                    editTrackerConfig(self.trajectory_session)
예제 #4
0
    def callOpenRecentFile(self, path=None):

        # Check if the file/dir exist
        if os.path.isdir(path) or os.path.isfile(path):

            # Get the name of the file
            _, _image_name = os.path.split(path)

            # Get the recommandations
            image_recommendations = getImagesInfos(path)
            _do_crop = image_recommendations['do_crop'] and self.parent.config.crop_image
            _crop_size = self.parent.config.crop_size
            _do_sign_correction = image_recommendations['do_sign_correction'] and self.parent.config.correct_signed
            _open_range = None
            _wait_range = False

            # Open the progress bar window
            openWindow(self.parent, OpenImageProgressBarWindow, 'progress_bar', image_path=path, name=_image_name, crop=_do_crop, crop_size=_crop_size, correct_sign=_do_sign_correction, scheduler=self)

            # Add the path to the recent file list
            appendRecentFiles(path)

        # Raise an error if the file doesn't exist anymore
        else:
            errorMessage("No Selection","The selected file or folder doesn't exist.")

            # Remove the file from the list
            deleteRecentFiles(path)
예제 #5
0
    def handleErrors(self, text):

        # Handle subnetwork exceptions
        if "SubnetOversizeException" in text:
            self.close()
            errorMessage(
                "Subnetwork Oversize",
                "Too many points have been found in the subnetwork. Reduce the search range or increase the intensity threshold before trying again."
            )
예제 #6
0
    def editTracker(self):

        # Raise an error if the 'Default' tracker is selected
        if self.current_tracker == 'Default':
            errorMessage('Forbidden Action',"The settings of the Default tracker cannot be edited.")

        else:
            if warningProceedMessage('Overwrite Tracker','Are you sure you want to replace the settings of the tracker '+self.current_tracker+' in the memory?'):

                # Update the selection
                self.updateDetectionSession()

                # Edit the tracker settings
                self.trajectory_session.modified = True
                editTrackerConfig(self.trajectory_session)
예제 #7
0
    def getImageFromPath(self):

        # Get the name of the file
        _, image_name = os.path.split(self.image_path)

        # Get the correction to apply
        _do_crop = self.cropCheckBox.isChecked()
        _crop_size = int(self.cropSizeEntry.text())
        _do_sign_correction = self.signCorrectionCheckBox.isChecked()
        _start, _end = self.frameRangeSelection.getRange()
        _open_range = _start - 1, _end

        # Check the crop size
        _proceed = True
        if _do_crop:
            if _crop_size > np.amin(
                [self.image_infos['size'][0], self.image_infos['size'][1]]):
                errorMessage(
                    'Cropping Error',
                    'The requested crop size is greater than the image size.')
                _proceed = False

        # Load the image
        if _proceed:
            self.image_class = None

            # Open the progress bar window
            openWindow(self.parent,
                       OpenImageProgressBarWindow,
                       'progress_bar',
                       image_path=self.image_path,
                       name=image_name,
                       open_range=_open_range,
                       crop=_do_crop,
                       crop_size=_crop_size,
                       correct_sign=_do_sign_correction,
                       scheduler=self)

            # Add the image to the list of recent items
            appendRecentFiles(self.image_path)
예제 #8
0
    def cropImage(self):

        # Raise an error if there is no selection
        if self.selection_pointA is None or self.selection_pointB is None:
            errorMessage("No Selection",
                         "A selection is required to crop the image.")

        # Crop the image
        else:

            # Get the selection
            selection = qtc.QRect(self.selection_pointA, self.selection_pointB)
            origin = int(selection.x() / self.zoom), int(selection.y() /
                                                         self.zoom)
            dimensions = int(selection.width() / self.zoom), int(
                selection.height() / self.zoom)

            # Get the current tab
            tab_id = self.parent.imageTabDisplay.currentIndex()
            old_class = self.parent.imageTabDisplay.displayedTabs[
                tab_id].image_class

            # Crop the array
            new_array = cropImage(old_class.image.source,
                                  dimensions,
                                  origin=origin)

            # Load the array in a file
            new_class = ImageCollection(new_array,
                                        name=old_class.name,
                                        space_scale=self.parent.space_scale,
                                        space_unit=self.parent.space_unit,
                                        frame_rate=self.parent.frame_rate)

            # Replace the array in the tab
            self.parent.imageTabDisplay.replaceTab(tab_id, new_class)

            # Close the image
            self.close()
예제 #9
0
    def exportTracker(self):

        # Prepare the list of exportable settings
        all_trackers = listTrackerConfigs()
        tracker_list = [x for x in all_trackers if x != 'Default']

        # Proceed if there are enough trackers in the memory
        if len(tracker_list) >= 1:

            # Get the tracker to export
            tracker_name, ok = qtw.QInputDialog.getItem(
                self, "Tracker Selection", "Tracker to export?", tracker_list,
                0, False)

            # Export the selection
            if ok:

                # Get the file name
                tracker_file, _ = qtw.QFileDialog.getSaveFileName(
                    self.parent, "Save Tracker...", "",
                    "JSON Archive (*.json)")

                if tracker_file != "":

                    # Load the selection
                    export_session = loadTrackerConfig(tracker_name)

                    # Save the selection in file
                    export_session.session.save(tracker_file)

                    # Message to confirm the export
                    notificationFileSaved(tracker_file)

        # Display an error message if there are nothing
        else:
            errorMessage("No Tracker",
                         "There is no tracker to export in the memory.")
예제 #10
0
    def browseDirectory(self):

        # Open the browser
        directoryPath = qtw.QFileDialog.getExistingDirectory(
            self.parent, "Open Directory...")

        # Process only if an image has been selected
        if directoryPath != "":
            folder_list, folder_infos = getImageFolderList(directoryPath)

            # Check that the folder list is not empty
            if len(folder_list) == 0:
                errorMessage(
                    'No folder found',
                    'No image folder was found in the selected directory.')

            else:
                self.directory = directoryPath
                self.folders = folder_list
                self.infos = folder_infos

                # Refresh the display
                self.browseEntry.lineEdit.setText(directoryPath)
                self.populateTable()