Ejemplo n.º 1
0
    def _on_import_preset(self):
        path = common_qt_lib.prompt_user_for_preset_file(self._window_manager,
                                                         new_file=False)
        if path is None:
            return

        preset = VersionedPreset.from_file_sync(path)
        try:
            preset.get_preset()
        except (ValueError, KeyError):
            QMessageBox.critical(
                self._window_manager, "Error loading preset",
                "The file at '{}' contains an invalid preset.".format(path))
            return

        if self._window_manager.preset_manager.preset_for_name(
                preset.name) is not None:
            user_response = QMessageBox.warning(
                self._window_manager, "Preset name conflict",
                "A preset named '{}' already exists. Do you want to overwrite it?"
                .format(preset.name), QMessageBox.Yes | QMessageBox.No,
                QMessageBox.No)
            if user_response == QMessageBox.No:
                return

        self._add_new_preset(preset)
Ejemplo n.º 2
0
    def import_preset_file(self, path: Path):
        preset = VersionedPreset.from_file_sync(path)
        try:
            preset.get_preset()
        except InvalidPreset:
            QtWidgets.QMessageBox.critical(
                self._window_manager, "Error loading preset",
                "The file at '{}' contains an invalid preset.".format(path))
            return

        existing_preset = self._window_manager.preset_manager.preset_for_uuid(
            preset.uuid)
        if existing_preset is not None:
            user_response = QtWidgets.QMessageBox.warning(
                self._window_manager, "Preset ID conflict",
                "The new preset '{}' has the same ID as existing '{}'. Do you want to overwrite it?"
                .format(
                    preset.name,
                    existing_preset.name,
                ), QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No
                | QtWidgets.QMessageBox.Cancel, QtWidgets.QMessageBox.Cancel)
            if user_response == QtWidgets.QMessageBox.Cancel:
                return
            elif user_response == QtWidgets.QMessageBox.No:
                preset = VersionedPreset.with_preset(
                    dataclasses.replace(preset.get_preset(),
                                        uuid=uuid.uuid4()))

        self._add_new_preset(preset)
Ejemplo n.º 3
0
    def __init__(self, data_dir: Optional[Path]):
        self.included_presets = [VersionedPreset.from_file_sync(f) for f in read_preset_list()]

        self.custom_presets = {}
        if data_dir is not None:
            self._data_dir = data_dir.joinpath("presets")
        else:
            self._data_dir = None
Ejemplo n.º 4
0
def refresh_presets_command_logic(args):
    base_path = get_data_path().joinpath("presets")

    with base_path.joinpath("presets.json").open() as presets_file:
        preset_list = json.load(presets_file)["presets"]

    for preset_relative_path in preset_list:
        preset_path = base_path.joinpath(preset_relative_path["path"])
        preset = VersionedPreset.from_file_sync(preset_path)
        preset.ensure_converted()
        preset.save_to_file(preset_path)
Ejemplo n.º 5
0
    def __init__(self, data_dir: Optional[Path]):
        self.included_presets = {
            preset.uuid: preset
            for preset in [VersionedPreset.from_file_sync(f) for f in read_preset_list()]
        }

        self.custom_presets = {}
        if data_dir is not None:
            self._data_dir = data_dir
        else:
            self._data_dir = None
Ejemplo n.º 6
0
def test_included_presets_are_valid(f):
    VersionedPreset.from_file_sync(f).get_preset()