示例#1
0
    def export_measurement_profiles(self):
        exp = ExportDialog(self.settings.measurement_profiles, StringViewer)
        if not exp.exec_():
            return
        dial = QFileDialog(self, "Export settings profiles")
        dial.setDirectory(self.settings.get("io.export_directory", ""))
        dial.setFileMode(QFileDialog.AnyFile)
        dial.setAcceptMode(QFileDialog.AcceptSave)
        dial.setNameFilter("measurement profile (*.json)")
        dial.setDefaultSuffix("json")
        dial.selectFile("measurements_profile.json")

        if dial.exec_():
            file_path = str(dial.selectedFiles()[0])
            self.settings.set("io.export_directory", file_path)
            data = {
                x: self.settings.measurement_profiles[x]
                for x in exp.get_export_list()
            }
            with open(file_path, "w") as ff:
                json.dump(data,
                          ff,
                          cls=self.settings.json_encoder_class,
                          indent=2)
            self.settings.set("io.save_directory", os.path.dirname(file_path))
 def export_plans(self):
     choose = ExportDialog(self.settings.batch_plans, PlanPreview)
     if not choose.exec_():
         return
     dial = QFileDialog(self, "Export calculation plans")
     dial.setFileMode(QFileDialog.AnyFile)
     dial.setAcceptMode(QFileDialog.AcceptSave)
     dial.setDirectory(
         dial.setDirectory(
             self.settings.get("io.batch_plan_directory",
                               str(Path.home()))))
     dial.setNameFilter("Calculation plans (*.json)")
     dial.setDefaultSuffix("json")
     dial.selectFile("calculation_plans.json")
     dial.setHistory(dial.history() + self.settings.get_path_history())
     if dial.exec_():
         file_path = str(dial.selectedFiles()[0])
         self.settings.set("io.batch_plan_directory",
                           os.path.dirname(file_path))
         self.settings.add_path_history(os.path.dirname(file_path))
         data = {
             x: self.settings.batch_plans[x]
             for x in choose.get_export_list()
         }
         with open(file_path, "w") as ff:
             json.dump(data,
                       ff,
                       cls=self.settings.json_encoder_class,
                       indent=2)
示例#3
0
 def import_profiles(self):
     dial = QFileDialog(self, "Import profile segment")
     dial.setFileMode(QFileDialog.ExistingFile)
     dial.setAcceptMode(QFileDialog.AcceptOpen)
     dial.setDirectory(
         self._settings.get("io.save_directory", str(Path.home())))
     dial.setNameFilter("Segment profile (*.json)")
     dial.setHistory(dial.history() + self._settings.get_path_history())
     if dial.exec_():
         file_path = dial.selectedFiles()[0]
         save_dir = os.path.dirname(file_path)
         self._settings.set("io.save_directory", save_dir)
         self._settings.add_path_history(save_dir)
         profs, err = self._settings.load_part(file_path)
         if err:
             QMessageBox.warning(
                 self, "Import error",
                 "error during importing, part of data were filtered.")
         profiles_dict = self._settings.segmentation_profiles
         imp = ImportDialog(profs, profiles_dict, ProfileDictViewer)
         if not imp.exec_():
             return
         for original_name, final_name in imp.get_import_list():
             profiles_dict[final_name] = profs[original_name]
         self._settings.dump()
         self.update_profile_list()
示例#4
0
 def export_pipeline(self):
     exp = ExportDialog(self._settings.segmentation_pipelines,
                        ProfileDictViewer)
     if not exp.exec_():
         return
     dial = QFileDialog(self, "Export pipeline segment")
     dial.setFileMode(QFileDialog.AnyFile)
     dial.setAcceptMode(QFileDialog.AcceptSave)
     dial.setDirectory(self._settings.get("io.save_directory", ""))
     dial.setNameFilter("Segment pipeline (*.json)")
     dial.setDefaultSuffix("json")
     dial.selectFile("segment_pipeline.json")
     dial.setHistory(dial.history() + self._settings.get_path_history())
     if dial.exec_():
         file_path = dial.selectedFiles()[0]
         data = {
             x: self._settings.segmentation_pipelines[x]
             for x in exp.get_export_list()
         }
         with open(file_path, "w") as ff:
             json.dump(data,
                       ff,
                       cls=self._settings.json_encoder_class,
                       indent=2)
         self._settings.set("io.save_directory", os.path.dirname(file_path))
         self._settings.add_path_history(os.path.dirname(file_path))
示例#5
0
 def folder_dialog(self, *args, **kwargs):
     dialog = QFileDialog(self)
     if not self._is_file_dialog_opened:
         # set the initial directory to HOME
         dialog.setDirectory(os.path.expanduser("~"))
         self._is_file_dialog_opened = True
     dir_name = None
     dialog.setWindowTitle("Open .edi Directory...")
     dialog.setFileMode(QFileDialog.DirectoryOnly)
     while dir_name is None:
         if dialog.exec_() == QDialog.Accepted:
             dir_name = dialog.selectedFiles()[0]
             dir_name = str(dir_name)
             file_list = [
                 os.path.join(dir_name, edi) for edi in os.listdir(dir_name)
                 if edi.endswith("edi")
             ]
             if not file_list:
                 # empty list
                 QMessageBox.information(
                     self, "NOTE",
                     "Directory does not contain any .edi file, please select again."
                 )
                 dir_name = None  # will read again
             else:
                 self._progress_bar.setMaximumValue(len(file_list))
                 self._progress_bar.onStart()
                 self._add_files(file_list, os.path.basename(dir_name))
                 self._update_tree_view()
                 self._progress_bar.onFinished()
         else:
             break
 def import_plans(self):
     dial = QFileDialog(self, "Import calculation plans")
     dial.setFileMode(QFileDialog.ExistingFile)
     dial.setAcceptMode(QFileDialog.AcceptOpen)
     dial.setDirectory(
         self.settings.get("io.open_directory", str(Path.home())))
     dial.setNameFilter("Calculation plans (*.json)")
     dial.setDefaultSuffix("json")
     dial.setHistory(dial.history() + self.settings.get_path_history())
     if dial.exec_():
         file_path = dial.selectedFiles()[0]
         plans, err = self.settings.load_part(file_path)
         self.settings.set("io.batch_plan_directory",
                           os.path.dirname(file_path))
         self.settings.add_path_history(os.path.dirname(file_path))
         if err:
             QMessageBox.warning(
                 self, "Import error",
                 "error during importing, part of data were filtered.")
         choose = ImportDialog(plans, self.settings.batch_plans,
                               PlanPreview)
         if choose.exec_():
             for original_name, final_name in choose.get_import_list():
                 self.settings.batch_plans[final_name] = plans[
                     original_name]
             self.update_plan_list()
示例#7
0
 def pick_output_dir(self):
     '''
     Sets the output directory.
     '''
     dialog = QFileDialog(parent=self)
     dialog.setFileMode(QFileDialog.DirectoryOnly)
     dialog.setOption(QFileDialog.ShowDirsOnly)
     dialog.setWindowTitle('Select a location to store the generated minidsp config files')
     if dialog.exec():
         selected = dialog.selectedFiles()
         if len(selected) > 0:
             if os.path.abspath(selected[0]) == os.path.abspath(self.__beq_dir):
                 QMessageBox.critical(self, '',
                                      f"Output directory cannot be inside the input directory, choose a different folder",
                                      QMessageBox.Ok)
             else:
                 abspath = os.path.abspath(f"{selected[0]}{os.path.sep}beq_minidsp")
                 if not os.path.exists(abspath):
                     try:
                         os.mkdir(abspath)
                     except:
                         QMessageBox.critical(self, '', f"Unable to create directory - {abspath}", QMessageBox.Ok)
                 if os.path.exists(abspath):
                     self.outputDirectory.setText(abspath)
     self.__enable_process()
示例#8
0
    def select_file(self):
        dial = QFileDialog()
        dial.setFileMode(QFileDialog.ExistingFile)
        dial.setAcceptMode(QFileDialog.AcceptOpen)

        if dial.exec():
            self.first_text.setText(dial.selectedFiles()[0])
示例#9
0
 def select_manual_output_folder(self):
     # _current_folder = self.main_window.current_folder
     dlg = QFileDialog(parent=self.main_window,
                       caption="Select or Define Output Directory")
     dlg.setFileMode(QFileDialog.Directory)
     if dlg.exec_():
         output_folder_name = str(dlg.selectedFiles()[0])
         self.main_window.autonom_ui.manual_output_folder_field.setText(output_folder_name)
示例#10
0
 def showDefaultOutputDirectoryPicker(self):
     dialog = QFileDialog(parent=self)
     dialog.setFileMode(QFileDialog.DirectoryOnly)
     dialog.setWindowTitle(f"Select Extract Audio Output Directory")
     if dialog.exec():
         selected = dialog.selectedFiles()
         if len(selected) > 0:
             self.defaultOutputDirectory.setText(selected[0])
示例#11
0
def open_a_file_dialog(parent=None,
                       default_suffix=None,
                       directory=None,
                       file_filter=None,
                       accept_mode=None,
                       file_mode=None):
    """
    Open a dialog asking for a file location and name to and return it
    :param parent: QWidget; The parent QWidget of the created dialog
    :param default_suffix: String; The default suffix to be passed
    :param directory: String; Directory to which the dialog will open
    :param file_filter: String; The filter name and file type e.g. "Python files (*.py)"
    :param accept_mode: enum AcceptMode; Defines the AcceptMode of the dialog, check QFileDialog Class for details
    :param file_mode: enum FileMode; Defines the FileMode of the dialog, check QFileDialog Class for details
    :return: String; The filename that was selected, it is possible to return a directory so look out for that
    """
    global _LAST_SAVE_DIRECTORY
    dialog = QFileDialog(parent)

    # It is the intention to only save the user's last used directory until workbench is restarted similar to other
    # applications (VSCode, Gedit etc)
    if _LAST_SAVE_DIRECTORY is not None and directory is None:
        dialog.setDirectory(_LAST_SAVE_DIRECTORY)
    elif directory is not None:
        dialog.setDirectory(directory)
    else:
        dialog.setDirectory(os.path.expanduser("~"))

    if file_filter is not None:
        dialog.setFilter(QDir.Files)
        dialog.setNameFilter(file_filter)

    if default_suffix is not None:
        dialog.setDefaultSuffix(default_suffix)

    if file_mode is not None:
        dialog.setFileMode(file_mode)

    if accept_mode is not None:
        dialog.setAcceptMode(accept_mode)

    # Connect the actual filename setter
    dialog.fileSelected.connect(_set_last_save)

    # Wait for dialog to finish before allowing continuation of code
    if dialog.exec_() == QDialog.Rejected:
        return None

    filename = _LAST_SAVE_DIRECTORY

    # Make sure that the _LAST_SAVE_DIRECTORY is set as a directory
    if _LAST_SAVE_DIRECTORY is not None and not os.path.isdir(
            _LAST_SAVE_DIRECTORY):
        # Remove the file for last directory
        _LAST_SAVE_DIRECTORY = os.path.dirname(
            os.path.abspath(_LAST_SAVE_DIRECTORY))

    return filename
示例#12
0
 def choose_data_prefix(self):
     dial = QFileDialog()
     dial.setAcceptMode(QFileDialog.AcceptOpen)
     dial.setFileMode(QFileDialog.Directory)
     dial.setDirectory(self.base_prefix.text())
     dial.setHistory(dial.history() + self.settings.get_path_history())
     if dial.exec_():
         dir_path = str(dial.selectedFiles()[0])
         self.base_prefix.setText(dir_path)
示例#13
0
 def select_directory(self):
     dial = QFileDialog(self, "Select directory")
     dial.setDirectory(
         self.settings.get("io.batch_directory", self.settings.get("io.load_image_directory", str(Path.home())))
     )
     dial.setFileMode(QFileDialog.Directory)
     if dial.exec_():
         self.paths_input.setText(dial.selectedFiles()[0])
         self.settings.set("io.batch_directory", str(dial.selectedFiles()[0]))
示例#14
0
 def __select_dir(self):
     dialog = QFileDialog(parent=self)
     dialog.setFileMode(QFileDialog.DirectoryOnly)
     dialog.setWindowTitle('Select Directory')
     if dialog.exec():
         selected = dialog.selectedFiles()
         if len(selected) > 0:
             return selected[0]
     return ''
示例#15
0
 def showBeqDirectoryPicker(self):
     ''' selects an output directory for the beq files '''
     dialog = QFileDialog(parent=self)
     dialog.setFileMode(QFileDialog.DirectoryOnly)
     dialog.setWindowTitle(f"Select BEQ Files Download Directory")
     if dialog.exec():
         selected = dialog.selectedFiles()
         if len(selected) > 0:
             self.beqFiltersDir.setText(selected[0])
             self.__count_beq_files()
示例#16
0
 def __get_directory(self, name):
     dialog = QFileDialog(parent=self)
     dialog.setFileMode(QFileDialog.ExistingFile)
     dialog.setNameFilter(f"{name} ({name}.exe {name})")
     dialog.setWindowTitle(f"Select {name}")
     if dialog.exec():
         selected = dialog.selectedFiles()
         if len(selected) > 0:
             return selected[0]
     return None
示例#17
0
 def choose_result_prefix(self):
     dial = QFileDialog()
     dial.setOption(QFileDialog.DontUseNativeDialog, True)
     dial.setAcceptMode(QFileDialog.AcceptOpen)
     dial.setFileMode(QFileDialog.Directory)
     dial.setDirectory(self.result_prefix.text())
     dial.setHistory(dial.history() + self.settings.get_path_history())
     if dial.exec_():
         dir_path = str(dial.selectedFiles()[0])
         self.result_prefix.setText(dir_path)
示例#18
0
 def selectFile(self):
     self.__reinit_fields()
     dialog = QFileDialog(parent=self)
     dialog.setFileMode(QFileDialog.ExistingFile)
     dialog.setWindowTitle('Select Audio or Video File')
     if dialog.exec():
         selected = dialog.selectedFiles()
         if len(selected) > 0:
             self.inputFile.setText(selected[0])
             self.__probe_file()
示例#19
0
    def open_save_records_dialog(self):
        from functools import partial
        logger, _ = self.current_logger_and_index()
        if not logger:
            return

        d = QFileDialog(self)
        d.selectFile(logger.name + '.log')
        d.setFileMode(QFileDialog.AnyFile)
        d.fileSelected.connect(partial(self.save_records, logger))
        d.setWindowTitle('Save records of "{}" tab to...'.format(logger.name))
        d.open()
示例#20
0
 def mapping_dialog():
     dial = QFileDialog(self, "Select file")
     dial.setHistory(dial.history() + self.settings.get_path_history())
     base_path = str(self.base_prefix.text()).strip()
     if base_path != "":
         dial.setDirectory(base_path)
     dial.setFileMode(QFileDialog.ExistingFile)
     if dial.exec_():
         path = str(dial.selectedFiles())
         self.mask_path_list[i].setText(path)
         file_mapper: MaskFile = self.mask_mapper_list[pos]
         file_mapper.set_map_path(path)
示例#21
0
def open_a_file_dialog(parent=None,  default_suffix=None, directory=None, file_filter=None, accept_mode=None,
                       file_mode=None):
    """
    Open a dialog asking for a file location and name to and return it
    :param parent: QWidget; The parent QWidget of the created dialog
    :param default_suffix: String; The default suffix to be passed
    :param directory: String; Directory to which the dialog will open
    :param file_filter: String; The filter name and file type e.g. "Python files (*.py)"
    :param accept_mode: enum AcceptMode; Defines the AcceptMode of the dialog, check QFileDialog Class for details
    :param file_mode: enum FileMode; Defines the FileMode of the dialog, check QFileDialog Class for details
    :return: String; The filename that was selected, it is possible to return a directory so look out for that
    """
    global _LAST_SAVE_DIRECTORY
    dialog = QFileDialog(parent)

    # It is the intention to only save the user's last used directory until workbench is restarted similar to other
    # applications (VSCode, Gedit etc)
    if _LAST_SAVE_DIRECTORY is not None and directory is None:
        dialog.setDirectory(_LAST_SAVE_DIRECTORY)
    elif directory is not None:
        dialog.setDirectory(directory)
    else:
        dialog.setDirectory(os.path.expanduser("~"))

    if file_filter is not None:
        dialog.setFilter(QDir.Files)
        dialog.setNameFilter(file_filter)

    if default_suffix is not None:
        dialog.setDefaultSuffix(default_suffix)

    if file_mode is not None:
        dialog.setFileMode(file_mode)

    if accept_mode is not None:
        dialog.setAcceptMode(accept_mode)

    # Connect the actual filename setter
    dialog.fileSelected.connect(_set_last_save)

    # Wait for dialog to finish before allowing continuation of code
    if dialog.exec_() == QDialog.Rejected:
        return None

    filename = _LAST_SAVE_DIRECTORY

    # Make sure that the _LAST_SAVE_DIRECTORY is set as a directory
    if _LAST_SAVE_DIRECTORY is not None and not os.path.isdir(_LAST_SAVE_DIRECTORY):
        # Remove the file for last directory
        _LAST_SAVE_DIRECTORY = os.path.dirname(os.path.abspath(_LAST_SAVE_DIRECTORY))

    return filename
示例#22
0
 def select_files(self):
     dial = QFileDialog(self, "Select files")
     dial.setDirectory(
         self.settings.get("io.batch_directory", self.settings.get("io.load_image_directory", str(Path.home())))
     )
     dial.setFileMode(QFileDialog.ExistingFiles)
     if dial.exec_():
         self.settings.set("io.batch_directory", os.path.dirname(str(dial.selectedFiles()[0])))
         new_paths = sorted(set(map(str, dial.selectedFiles())) - self.files_to_proceed)
         for path in new_paths:
             self.selected_files.addItem(FileListItem(path))
         self.files_to_proceed.update(new_paths)
         self.file_list_changed.emit(self.files_to_proceed)
示例#23
0
 def showExtractCompleteSoundPicker(self):
     dialog = QFileDialog(parent=self)
     dialog.setFileMode(QFileDialog.ExistingFile)
     dialog.setNameFilter("Audio (*.wav)")
     dialog.setWindowTitle(f"Select Notification Sound")
     if dialog.exec():
         selected = dialog.selectedFiles()
         if len(selected) > 0:
             self.extractCompleteAudioFile.setText(selected[0])
         else:
             self.extractCompleteAudioFile.setText('')
     else:
         self.extractCompleteAudioFile.setText('')
示例#24
0
    def choose_cna_path(self):
        dialog = QFileDialog(self, directory=self.cna_path.text())
        dialog.setFileMode(QFileDialog.DirectoryOnly)
        directory: str = dialog.getExistingDirectory()
        if not directory or len(
                directory) == 0 or not os.path.exists(directory):
            return

        self.cna_path.setText(directory)
        self.update()
        self.reset_engine()
        self.check_cna()
        self.update()
示例#25
0
 def setTargetDirectory(self):
     '''
     Sets the target directory based on the user selection.
     '''
     dialog = QFileDialog(parent=self)
     dialog.setFileMode(QFileDialog.DirectoryOnly)
     dialog.setWindowTitle(f"Select Output Directory")
     if dialog.exec():
         selected = dialog.selectedFiles()
         if len(selected) > 0:
             self.targetDir.setText(selected[0])
             if self.__executor is not None:
                 self.__executor.target_dir = selected[0]
                 self.__display_command_info()
示例#26
0
    def choose_ml_path(self):
        dialog = QFileDialog(self, directory=self.matlab_path.text())
        dialog.setFileMode(QFileDialog.DirectoryOnly)
        directory: str = dialog.getExistingDirectory()
        if not directory or len(
                directory) == 0 or not os.path.exists(directory):
            return

        self.choose_ml_path_btn.setEnabled(False)
        self.matlab_path.setText(directory)
        self.try_install_matlab_engine(directory)
        self.check_matlab()
        self.choose_ml_path_btn.setEnabled(True)
        self.update()
示例#27
0
def showSelectProjectDialog(parent: QWidget = None) -> Optional[Path]:
    dialog = QFileDialog(parent, Qt.Dialog)
    dialog.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.Dialog)
    dialog.setAcceptMode(QFileDialog.AcceptSave)
    dialog.setLabelText(QFileDialog.LookIn, "Select project folder")
    dialog.setFileMode(QFileDialog.Directory)
    dialog.setOption(QFileDialog.ShowDirsOnly, True)
    dialog.setViewMode(QFileDialog.Detail)
    dialog.setDirectory(QDir.homePath())

    if dialog.exec_():
        paths = dialog.selectedFiles()
        assert len(paths) == 1
        path = Path(paths[0])
        return path
示例#28
0
 def file_dialog(self, *args, **kwargs):
     dialog = QFileDialog(self)
     if not self._is_file_dialog_opened:
         # set the initial directory to HOME
         dialog.setDirectory(os.path.expanduser("~"))
         self._is_file_dialog_opened = True
     dialog.setWindowTitle('Open .edi Files...')
     dialog.setNameFilter('.edi files (*.edi)')
     dialog.setFileMode(QFileDialog.ExistingFiles)
     if dialog.exec_() == QDialog.Accepted:
         file_list = dialog.selectedFiles()
         self._progress_bar.setMaximumValue(len(file_list))
         self._progress_bar.onStart()
         self._add_files(file_list, DEFAULT_GROUP_NAME)
         self._update_tree_view()
         self._progress_bar.onFinished()
示例#29
0
def parse_file(filter, title, parsers):
    '''
    Presents a file dialog to the user so they can choose something to load.
    :return: a 2 entry tuple with the file name and loaded thing (if anything was loaded)
    '''
    dialog = QFileDialog()
    dialog.setFileMode(QFileDialog.ExistingFile)
    dialog.setNameFilter(filter)
    dialog.setWindowTitle(title)
    if dialog.exec():
        selected = dialog.selectedFiles()
        if len(selected) > 0:
            file_name = selected[0]
            for k, v in parsers.items():
                if file_name.endswith(k):
                    return v(file_name)
    return None, None
示例#30
0
def open_exe_name_dialog(parent, appname):
    options = QFileDialog.Options()
    options |= QDir.AllEntries
    options |= QDir.Hidden

    file_dialog = QFileDialog()
    file_dialog.setFilter(QDir.AllEntries | QDir.Hidden)
    file_dialog.setFileMode(QFileDialog.ExistingFile)
    file_dialog.setWindowTitle(
        f"{appname} could not be found. Please locate in"
        "manually")
    if file_dialog.exec():
        file_name = file_dialog.selectedFiles()
        print(file_name[0])
        return file_name[0]
    else:
        print("No file is selected. guiscrcpy is likely to fail")
示例#31
0
 def pick_user_source_dir(self):
     '''
     Sets the user source directory.
     '''
     dialog = QFileDialog(parent=self)
     dialog.setFileMode(QFileDialog.DirectoryOnly)
     dialog.setOption(QFileDialog.ShowDirsOnly)
     dialog.setWindowTitle('Choose a directory which holds your own BEQ files')
     if dialog.exec():
         selected = dialog.selectedFiles()
         if len(selected) > 0:
             if os.path.abspath(selected[0]) == os.path.abspath(self.__beq_dir):
                 QMessageBox.critical(self, '',
                                      f"User directory cannot be inside the input directory, choose a different folder",
                                      QMessageBox.Ok)
             else:
                 self.userSourceDir.setText(selected[0])
                 self.update_beq_count()
示例#32
0
 def openDirDialog(self):
     dialog = QFileDialog(self)
     dialog.setFileMode(QFileDialog.DirectoryOnly)
     if dialog.exec_():
         directory = dialog.selectedFiles()[0]
         self.openDir(directory)