Ejemplo n.º 1
0
    def open_world(self, event, world_path: Path = None):
        """User has requested opening a world, so find fh_setting.yaml"""
        # Ignore filter used to select file
        if not world_path:
            world_file, _ = QtWidgets.QFileDialog.getOpenFileName(
                self, "Open World (fh_setting.yaml)", ".",
                "World Files (*.yaml)")
            if not world_file:
                # User cancelled selection
                return
            world_path = Path(world_file)

        # Close all open windows before load
        self.centralwidget.clear()

        # Check world file is a fh_setting.yaml file
        if not self.load(world_path):
            # Give user an error dialog and return
            self.world_open_error.showMessage(
                f"The file selected was not a valid world file: {world_path}. "
                "Valid world files must be named \"fh_setting.yaml\" and contain a particular "
                "directory structure.")
            Config.remove_recent_world(world_path)
            self.update_recent_worlds_menu()
            return

        # Save world to recent worlds list
        Config.add_recent_world(world_path)
        self.update_recent_worlds_menu()

        # Save world to last opened
        Config.set_last_opened(world_path)
Ejemplo n.º 2
0
def test_set_last_opened_is_saved(clean_config):
    test_path = "test_path"
    Config.set_last_opened(test_path)
    assert str(Config.last_opened()) == test_path