diff --git a/mscxyz/score.py b/mscxyz/score.py index 731005b..4c0e890 100644 --- a/mscxyz/score.py +++ b/mscxyz/score.py @@ -126,9 +126,14 @@ def is_uncompressed(self) -> bool: return self.extension != "mscz" def change_path( - self, suffix: Optional[Any] = None, extension: Optional[str] = None + self, + suffix: Optional[Any] = None, + extension: Optional[str] = None, + filename: Optional[str] = None, ) -> Path: - return utils.PathChanger(self.path).change(suffix=suffix, extension=extension) + return utils.PathChanger(self.path).change( + suffix=suffix, extension=extension, filename=filename + ) @property def export(self) -> Export: @@ -163,8 +168,21 @@ def style(self) -> Style: def make_snapshot(self) -> None: self.__xml_string_initial = self.xml_string - def new(self) -> Score: - return Score(self.path) + def new( + self, + suffix: Optional[Any] = None, + extension: Optional[str] = None, + filename: Optional[str] = None, + ) -> Score: + return Score( + self.change_path(suffix=suffix, extension=extension, filename=filename) + ) + + def __str__(self) -> str: + return str(self.path) + + def exists(self) -> bool: + return self.path.exists() def backup(self) -> None: """Make a copy of the MuseScore file.""" @@ -279,4 +297,4 @@ def reload(self, save: bool = False) -> Score: """ if save: self.save() - return Score(self.path) + return self.new() diff --git a/mscxyz/utils.py b/mscxyz/utils.py index 3cde3db..1e83001 100644 --- a/mscxyz/utils.py +++ b/mscxyz/utils.py @@ -250,8 +250,13 @@ def add_suffix(self, suffix: Any) -> Path: ) def change( - self, suffix: Optional[Any] = None, extension: Optional[str] = None + self, + suffix: Optional[Any] = None, + extension: Optional[str] = None, + filename: Optional[str] = None, ) -> Path: + if filename is not None: + return self.path.parent / filename path_changer: PathChanger = self.new() if suffix: path_changer = PathChanger(path_changer.add_suffix(suffix)) diff --git a/tests/helper.py b/tests/helper.py index 98cfb8e..312999c 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -244,7 +244,7 @@ def open_in_mscore(self) -> None: open_in_gui(self.score().path) -def open_in_gui(file: str | Path) -> None: +def open_in_gui(file: str | Path | Score) -> None: """Open a file wiht xdg-open in the background""" subprocess.Popen(("/usr/local/bin/mscore", str(file)), close_fds=True) diff --git a/tests/test_gui.py b/tests/test_gui.py index c4664c3..ce905e3 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -22,11 +22,8 @@ def test_din_a4_compress_rename() -> None: .append_score("Im-Fruehtau-zu-Berge.mscz") .score() ) - - dest = score.path.parent / "_Piano_A4.mscz" - + dest = score.new(filename="_Piano_A4.mscz") assert dest.exists() - open_in_gui(dest)