Example #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)
Example #2
0
def test_remove_recent_world(clean_config):
    new_world = Path("test_world")
    new_time = Config.dt_to_str(datetime.datetime.now())
    conf = {
        "recent_worlds": [{
            "name": str(new_world),
            "last_accessed": new_time
        }]
    }
    Config.save_config(conf)

    Config.remove_recent_world(new_world)

    with open(Config.get_config_file()) as f:
        contents = yaml.safe_load(f)

    assert len(contents["recent_worlds"]) == 0