Beispiel #1
0
def test_last_opened_gives_path(clean_config):
    test_path = "test_path"
    conf = {"last_opened": test_path}
    Config.save_config(conf)

    last_opened = Config.last_opened()
    assert last_opened is not None
    assert str(last_opened) == test_path
Beispiel #2
0
def test_add_recent_world(clean_config):
    new_world = Path("test_world")
    Config.add_recent_world(new_world)
    with open(Config.get_config_file()) as f:
        contents = yaml.safe_load(f)

    assert len(contents["recent_worlds"]) == 1
    world = contents["recent_worlds"][0]
    assert world["name"] == new_world.name
Beispiel #3
0
 def update_recent_worlds_menu(self):
     self.recent_worlds_menu.clear()
     for world in Config.get_recent_worlds():
         if world.parent == self.world_dir:
             continue
         act = self.recent_worlds_menu.addAction(str(world))
         act.triggered.connect(
             partial(self.open_world, event=None, world_path=world))
Beispiel #4
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)
Beispiel #5
0
def test_get_recent_worlds(clean_config):
    # Generate worlds
    conf = {"recent_worlds": []}
    world_names = []
    for idx in range(6):
        name = "world_{}".format(idx)
        time = datetime.datetime.now() - datetime.timedelta(minutes=idx)
        time_str = Config.dt_to_str(time)
        world = {"name": name, "last_accessed": time_str}
        conf["recent_worlds"] += [world]

        if idx < 5:
            world_names += [name]

    # Ensure config is not just returning first five files read
    conf["recent_worlds"].reverse()
    Config.save_config(conf)

    recent_worlds = Config.get_recent_worlds()
    assert len(recent_worlds) == 5
    for world in recent_worlds:
        assert str(world) in world_names
Beispiel #6
0
    def __init__(self):
        super().__init__()

        # Basic window construction
        self.setObjectName("MainWindow")
        self.resize(800, 600)

        self.mdi_areas = []
        self.centralwidget = WorkspaceTabWidget(self)
        self.centralwidget.setObjectName("centralwidget")

        # Create and set icon
        if getattr(sys, "frozen", False):
            icon_path = Path(sys.executable).parent / "resources" / "icon.png"
        else:
            icon_path = Path(__file__).parent / "resources" / "icon.png"
        self.setWindowIcon(QtGui.QIcon(str(icon_path)))

        # Root layout creation
        self.root_layout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.root_layout.setObjectName("root_layout")

        # Populate with starting panes
        self.create_location_pane(area=Qt.LeftDockWidgetArea)
        self.create_note_pane(area=Qt.LeftDockWidgetArea)
        self.create_party_pane(area=Qt.RightDockWidgetArea)
        self.create_npc_pane(area=Qt.RightDockWidgetArea)
        self.create_monsters_pane(area=Qt.RightDockWidgetArea)

        # Create actions, then menu bar using those actions
        self.create_actions()
        self.create_menu_bar()

        # Create errors to live permanently, so user can hide them from
        # appearing if desired
        self.create_error_boxes()

        # Final window setup
        self.setCentralWidget(self.centralwidget)
        self.setWindowState(Qt.WindowMaximized)

        # Check if there's a world to open already
        last_opened = Config.last_opened()
        if last_opened is not None:
            self.open_world(event=None, world_path=last_opened)
Beispiel #7
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
Beispiel #8
0
def test_dt_round_trip():
    now = datetime.datetime.now()
    assert Config.str_to_dt(Config.dt_to_str(now)) == now
Beispiel #9
0
def test_validate_recent_worlds():
    conf = {}
    Config._validate_recent_worlds(conf)
    assert "recent_worlds" in conf
Beispiel #10
0
def test_save_config(clean_config):
    conf = {"test": "test"}
    Config.save_config(conf)
    with open(Config.get_config_file()) as f:
        contents = yaml.safe_load(f)
    assert contents == conf
Beispiel #11
0
def test_config_path_is_yaml():
    p = Config.get_config_file()
    assert p.suffix == ".yaml"
Beispiel #12
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
Beispiel #13
0
def test_no_last_opened_gives_none(clean_config):
    assert Config.last_opened() is None