diff --git a/README.rst b/README.rst index 60a1602..cb7a5ae 100644 --- a/README.rst +++ b/README.rst @@ -361,9 +361,13 @@ CLI Usage [--page-size ] [--a4] [--letter] [--margin ] [--show-header | --no-show-header] + [--header-first-page | --no-header-first-page] + [--different-odd-even-header | --no-different-odd-even-header] [--header
] [--header-odd-even ] [--show-footer | --no-show-footer] + [--footer-first-page | --no-footer-first-page] + [--different-odd-even-footer | --no-different-odd-even-footer] [--footer
] [--footer-odd-even ] [--reset-small-staffs] @@ -747,13 +751,25 @@ CLI Usage --margin Set the top, right, bottom and left margins to the same value. --show-header, --no-show-header - Show or hide the header + Show or hide the header. + --header-first-page, --no-header-first-page + Show the header on the first page. + --different-odd-even-header, --no-different-odd-even-header + Use different header for odd and even pages. --header
+ Set the header for all pages. --header-odd-even + Set different headers for odd and even pages. --show-footer, --no-show-footer Show or hide the footer. + --footer-first-page, --no-footer-first-page + Show the footer on the first page. + --different-odd-even-footer, --no-different-odd-even-footer + Use different footers for odd and even pages. --footer
+ Set the footer for all pages. --footer-odd-even + Set different footers for odd and even pages. --reset-small-staffs Reset all small staffs to normal size. Configuration file diff --git a/autocomplete.bash b/autocomplete.bash index e962e9d..7d6dca6 100644 --- a/autocomplete.bash +++ b/autocomplete.bash @@ -2,7 +2,7 @@ -_shtab_musescore_manager_option_strings=('-h' '--help' '--print-completion' '-V' '--version' '-b' '--backup' '--bail' '--catch-errors' '-k' '--colorize' '-C' '--config-file' '-d' '--dry-run' '-m' '--mscore' '--save-in-mscore' '--diff' '-e' '--executable' '-v' '--verbose' '-E' '--export' '--compress' '-c' '--clean-meta' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--title' '--subtitle' '--composer' '--lyricist' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-t' '--target' '--only-filename' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '--clean' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--a4' '--din-a4' '--letter' '--margin' '--show-header' '--no-show-header' '--header' '--header-odd-even' '--show-footer' '--no-show-footer' '--footer' '--footer-odd-even' '--reset-small-staffs') +_shtab_musescore_manager_option_strings=('-h' '--help' '--print-completion' '-V' '--version' '-b' '--backup' '--bail' '--catch-errors' '-k' '--colorize' '-C' '--config-file' '-d' '--dry-run' '-m' '--mscore' '--save-in-mscore' '--diff' '-e' '--executable' '-v' '--verbose' '-E' '--export' '--compress' '-c' '--clean-meta' '-D' '--delete-duplicates' '-i' '--distribute-fields' '-j' '--json' '-l' '--log' '-y' '--synchronize' '-S' '--set-field' '--metatag' '--metatag-meta' '--vbox' '--vbox-meta' '--title' '--subtitle' '--composer' '--lyricist' '-x' '--extract' '--extract-lyrics' '-r' '--remap' '--remap-lyrics' '-F' '--fix' '--fix-lyrics' '--rename' '-t' '--target' '--only-filename' '-A' '--alphanum' '-a' '--ascii' '-n' '--no-whitespace' '-K' '--skip-if-empty' '-L' '--list-files' '-g' '--glob' '--mscz' '--mscx' '-s' '--style' '--clean' '-Y' '--style-file' '--s3' '--styles-v3' '--s4' '--styles-v4' '--list-fonts' '--text-font' '--title-font' '--musical-symbol-font' '--musical-text-font' '--staff-space' '--page-size' '--a4' '--din-a4' '--letter' '--margin' '--show-header' '--no-show-header' '--header-first-page' '--no-header-first-page' '--different-odd-even-header' '--no-different-odd-even-header' '--header' '--header-odd-even' '--show-footer' '--no-show-footer' '--footer-first-page' '--no-footer-first-page' '--different-odd-even-footer' '--no-different-odd-even-footer' '--footer' '--footer-odd-even' '--reset-small-staffs') _shtab_musescore_manager_pos_0_COMPGEN=_shtab_compgen_files _shtab_musescore_manager__C_COMPGEN=_shtab_compgen_files @@ -82,10 +82,18 @@ _shtab_musescore_manager___din_a4_nargs=0 _shtab_musescore_manager___letter_nargs=0 _shtab_musescore_manager___show_header_nargs=0 _shtab_musescore_manager___no_show_header_nargs=0 +_shtab_musescore_manager___header_first_page_nargs=0 +_shtab_musescore_manager___no_header_first_page_nargs=0 +_shtab_musescore_manager___different_odd_even_header_nargs=0 +_shtab_musescore_manager___no_different_odd_even_header_nargs=0 _shtab_musescore_manager___header_nargs=3 _shtab_musescore_manager___header_odd_even_nargs=6 _shtab_musescore_manager___show_footer_nargs=0 _shtab_musescore_manager___no_show_footer_nargs=0 +_shtab_musescore_manager___footer_first_page_nargs=0 +_shtab_musescore_manager___no_footer_first_page_nargs=0 +_shtab_musescore_manager___different_odd_even_footer_nargs=0 +_shtab_musescore_manager___no_different_odd_even_footer_nargs=0 _shtab_musescore_manager___footer_nargs=3 _shtab_musescore_manager___footer_odd_even_nargs=6 _shtab_musescore_manager___reset_small_staffs_nargs=0 diff --git a/autocomplete.tcsh b/autocomplete.tcsh index 64d57ca..ec624a4 100644 --- a/autocomplete.tcsh +++ b/autocomplete.tcsh @@ -3,7 +3,7 @@ complete musescore-manager \ - 'c/--/(a4 alphanum ascii backup bail catch-errors clean clean-meta colorize composer compress config-file delete-duplicates diff din-a4 distribute-fields dry-run executable export extract extract-lyrics fix fix-lyrics footer footer-odd-even glob header header-odd-even help json letter list-files list-fonts log lyricist margin metatag metatag-meta mscore mscx mscz musical-symbol-font musical-text-font no-show-footer no-show-header no-whitespace only-filename page-size print-completion remap remap-lyrics rename reset-small-staffs s3 s4 save-in-mscore set-field show-footer show-header skip-if-empty staff-space style style-file styles-v3 styles-v4 subtitle synchronize target text-font title title-font vbox vbox-meta verbose version)/' \ + 'c/--/(a4 alphanum ascii backup bail catch-errors clean clean-meta colorize composer compress config-file delete-duplicates diff different-odd-even-footer different-odd-even-header din-a4 distribute-fields dry-run executable export extract extract-lyrics fix fix-lyrics footer footer-first-page footer-odd-even glob header header-first-page header-odd-even help json letter list-files list-fonts log lyricist margin metatag metatag-meta mscore mscx mscz musical-symbol-font musical-text-font no-different-odd-even-footer no-different-odd-even-header no-footer-first-page no-header-first-page no-show-footer no-show-header no-whitespace only-filename page-size print-completion remap remap-lyrics rename reset-small-staffs s3 s4 save-in-mscore set-field show-footer show-header skip-if-empty staff-space style style-file styles-v3 styles-v4 subtitle synchronize target text-font title title-font vbox vbox-meta verbose version)/' \ 'c/-/(- A C D E F K L S V Y a b c d e g h i j k l m n r s t v x y)/' \ 'n/--print-completion/(bash zsh tcsh)/' \ 'n/-C/f/' \ diff --git a/autocomplete.zsh b/autocomplete.zsh index b199007..dec6eb8 100644 --- a/autocomplete.zsh +++ b/autocomplete.zsh @@ -68,12 +68,16 @@ _shtab_musescore_manager_options=( {--a4,--din-a4}"[Set the paper size to DIN A4 (210 by 297 mm).]" "--letter[Set the paper size to Letter (8.5 by 11 in).]" "--margin[Set the top, right, bottom and left margins to the same value.]:style_margin:" - {--show-header,--no-show-header}"[Show or hide the header]:style_show_header:" - "--header[]:style_header_all:" - "--header-odd-even[]:style_header_odd_even:" + {--show-header,--no-show-header}"[Show or hide the header.]:style_show_header:" + {--header-first-page,--no-header-first-page}"[Show the header on the first page.]:style_header_first_page:" + {--different-odd-even-header,--no-different-odd-even-header}"[Use different header for odd and even pages.]:style_different_odd_even_header:" + "--header[Set the header for all pages.]:style_header_all:" + "--header-odd-even[Set different headers for odd and even pages.]:style_header_odd_even:" {--show-footer,--no-show-footer}"[Show or hide the footer.]:style_show_footer:" - "--footer[]:style_footer_all:" - "--footer-odd-even[]:style_footer_odd_even:" + {--footer-first-page,--no-footer-first-page}"[Show the footer on the first page.]:style_footer_first_page:" + {--different-odd-even-footer,--no-different-odd-even-footer}"[Use different footers for odd and even pages.]:style_different_odd_even_footer:" + "--footer[Set the footer for all pages.]:style_footer_all:" + "--footer-odd-even[Set different footers for odd and even pages.]:style_footer_odd_even:" "--reset-small-staffs[Reset all small staffs to normal size.]" "(*)::Path to a \"\*.msc\[zx\]\" file or a folder containing \"\*.msc\[zx\]\" files. can be specified several times.:_files" ) diff --git a/docs/cli.rst b/docs/cli.rst index 65420f9..9c2e78f 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -28,9 +28,13 @@ Comande line interface [--page-size ] [--a4] [--letter] [--margin ] [--show-header | --no-show-header] + [--header-first-page | --no-header-first-page] + [--different-odd-even-header | --no-different-odd-even-header] [--header
] [--header-odd-even ] [--show-footer | --no-show-footer] + [--footer-first-page | --no-footer-first-page] + [--different-odd-even-footer | --no-different-odd-even-footer] [--footer
] [--footer-odd-even ] [--reset-small-staffs] @@ -414,12 +418,24 @@ Comande line interface --margin Set the top, right, bottom and left margins to the same value. --show-header, --no-show-header - Show or hide the header + Show or hide the header. + --header-first-page, --no-header-first-page + Show the header on the first page. + --different-odd-even-header, --no-different-odd-even-header + Use different header for odd and even pages. --header
+ Set the header for all pages. --header-odd-even + Set different headers for odd and even pages. --show-footer, --no-show-footer Show or hide the footer. + --footer-first-page, --no-footer-first-page + Show the footer on the first page. + --different-odd-even-footer, --no-different-odd-even-footer + Use different footers for odd and even pages. --footer
+ Set the footer for all pages. --footer-odd-even + Set different footers for odd and even pages. --reset-small-staffs Reset all small staffs to normal size. diff --git a/mscxyz/cli.py b/mscxyz/cli.py index 3d6b1a6..caaf441 100644 --- a/mscxyz/cli.py +++ b/mscxyz/cli.py @@ -656,11 +656,27 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]: help="Set the top, right, bottom and left margins to the same value.", ) +# header + style_group.add_argument( "--show-header", dest="style_show_header", action=argparse.BooleanOptionalAction, - help="Show or hide the header", + help="Show or hide the header.", +) + +style_group.add_argument( + "--header-first-page", + dest="style_header_first_page", + action=argparse.BooleanOptionalAction, + help="Show the header on the first page.", +) + +style_group.add_argument( + "--different-odd-even-header", + dest="style_different_odd_even_header", + action=argparse.BooleanOptionalAction, + help="Use different header for odd and even pages.", ) style_group.add_argument( @@ -668,6 +684,7 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]: nargs=3, dest="style_header_all", metavar=("", "
", ""), + help="Set the header for all pages.", ) style_group.add_argument( @@ -682,8 +699,11 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]: "", "", ), + help="Set different headers for odd and even pages.", ) +# footer + style_group.add_argument( "--show-footer", dest="style_show_footer", @@ -691,11 +711,26 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]: help="Show or hide the footer.", ) +style_group.add_argument( + "--footer-first-page", + dest="style_footer_first_page", + action=argparse.BooleanOptionalAction, + help="Show the footer on the first page.", +) + +style_group.add_argument( + "--different-odd-even-footer", + dest="style_different_odd_even_footer", + action=argparse.BooleanOptionalAction, + help="Use different footers for odd and even pages.", +) + style_group.add_argument( "--footer", nargs=3, dest="style_footer_all", metavar=("", "
", ""), + help="Set the footer for all pages.", ) style_group.add_argument( @@ -710,9 +745,9 @@ def _split_lines(self, text: typing.Text, width: int) -> typing.List[str]: "", "", ), + help="Set different footers for odd and even pages.", ) - style_group.add_argument( "--reset-small-staffs", dest="style_reset_small_staffs", @@ -837,24 +872,42 @@ def list_styles(version: int) -> None: if args.style_margin is not None: score.style.margin = inch(args.style_margin) + # header + if args.style_show_header is not None: score.style.show_header = args.style_show_header + if args.style_header_first_page is not None: + score.style.header_first_page = args.style_header_first_page + + if args.style_different_odd_even_header is not None: + score.style.header_odd_even = args.style_different_odd_even_header + if args.style_header_all: score.style.set_header_all(*args.style_header_all) if args.style_header_odd_even: score.style.set_header_odd_even(*args.style_header_odd_even) + # footer + if args.style_show_footer is not None: score.style.show_footer = args.style_show_footer + if args.style_footer_first_page is not None: + score.style.footer_first_page = args.style_footer_first_page + + if args.style_different_odd_even_footer is not None: + score.style.footer_odd_even = args.style_different_odd_even_footer + if args.style_footer_all: score.style.set_footer_all(*args.style_footer_all) if args.style_footer_odd_even: score.style.set_footer_odd_even(*args.style_footer_odd_even) + # small staffs + if args.style_reset_small_staffs: score.style.reset_small_staffs() diff --git a/mscxyz/settings.py b/mscxyz/settings.py index d3d66ab..2b2e759 100644 --- a/mscxyz/settings.py +++ b/mscxyz/settings.py @@ -88,9 +88,13 @@ class DefaultArguments: style_page_size_letter: bool = False style_margin: Optional[str] = None style_show_header: Optional[bool] = None + style_header_first_page: Optional[bool] = None + style_different_odd_even_header: Optional[bool] = None style_header_all: Optional[tuple[str, str, str]] = None style_header_odd_even: Optional[tuple[str, str, str, str, str, str]] = None + style_different_odd_even_footer: Optional[bool] = None style_show_footer: Optional[bool] = None + style_footer_first_page: Optional[bool] = None style_footer_all: Optional[tuple[str, str, str]] = None style_footer_odd_even: Optional[tuple[str, str, str, str, str, str]] = None style_reset_small_staffs: bool = False diff --git a/mscxyz/style.py b/mscxyz/style.py index 0221b34..5249b6e 100644 --- a/mscxyz/style.py +++ b/mscxyz/style.py @@ -946,6 +946,8 @@ def max_system_distance(self) -> float: def max_system_distance(self, value: float) -> None: self.set("maxSystemDistance", value) + # header ################################################################### + @property def show_header(self) -> bool: """ @@ -995,7 +997,7 @@ def header_odd_even(self) -> bool: @header_odd_even.setter def header_odd_even(self, value: bool) -> None: - self.set("headerFirstPage", int(value)) + self.set("headerOddEven", int(value)) # even/odd header l/c/r #################################################### @@ -1123,7 +1125,7 @@ def set_header_odd_even( even_right: str, ) -> None: """ - Set the header for odd and even pages. + Set different headers for odd and even pages. :see: :attr:`even_header_left` :see: :attr:`even_header_center` @@ -1180,7 +1182,7 @@ def footer_first_page(self, value: bool) -> None: @property def footer_odd_even(self) -> bool: """ - Show the footer on the first page. + Use different footers for odd and even pages. .. code :: XML diff --git a/tests/test_style.py b/tests/test_style.py index 173d6fe..1005c40 100644 --- a/tests/test_style.py +++ b/tests/test_style.py @@ -413,6 +413,8 @@ def test_option_margin(self) -> None: assert s.page_even_left_margin == 1.1811 assert s.page_odd_left_margin == 1.1811 + # header + def test_option_show_header(self) -> None: c = Cli("--show-header").execute() assert not c.pre.style.show_header @@ -422,6 +424,46 @@ def test_option_show_header(self) -> None: assert c.pre.style.show_header assert not c.post.style.show_header + def test_option_header_first_page(self) -> None: + c = Cli("--header-first-page").execute() + assert not c.pre.style.header_first_page + assert c.post.style.header_first_page + + c = Cli("--no-header-first-page", c.score()).execute() + assert c.pre.style.header_first_page + assert not c.post.style.header_first_page + + def test_option_different_odd_even_header(self) -> None: + c = Cli("--different-odd-even-header").execute() + assert c.pre.style.header_odd_even + assert c.post.style.header_odd_even + + c = Cli("--no-different-odd-even-header", c.score()).execute() + assert c.pre.style.header_odd_even + assert not c.post.style.header_odd_even + + def test_option_header(self) -> None: + s = Cli("--header", "l", "c", "r").score() + assert s.style.show_header + assert s.style.odd_header_left == "l" + assert s.style.even_header_left == "l" + assert s.style.odd_header_center == "c" + assert s.style.even_header_center == "c" + assert s.style.odd_header_right == "r" + assert s.style.even_header_right == "r" + + def test_option_header_odd_even(self) -> None: + s = Cli("--header-odd-even", "ol", "el", "oc", "ec", "or", "er").score() + assert s.style.show_header + assert s.style.odd_header_left == "ol" + assert s.style.even_header_left == "el" + assert s.style.odd_header_center == "oc" + assert s.style.even_header_center == "ec" + assert s.style.odd_header_right == "or" + assert s.style.even_header_right == "er" + + # footer + def test_option_show_footer(self) -> None: c = Cli("--show-footer").execute() assert c.pre.style.show_footer @@ -431,6 +473,44 @@ def test_option_show_footer(self) -> None: assert c.pre.style.show_footer assert not c.post.style.show_footer + def test_option_footer_first_page(self) -> None: + c = Cli("--footer-first-page").execute() + assert c.pre.style.footer_first_page + assert c.post.style.footer_first_page + + c = Cli("--no-footer-first-page", c.score()).execute() + assert c.pre.style.footer_first_page + assert not c.post.style.footer_first_page + + def test_option_different_odd_even_footer(self) -> None: + c = Cli("--different-odd-even-footer").execute() + assert c.pre.style.footer_odd_even + assert c.post.style.footer_odd_even + + c = Cli("--no-different-odd-even-footer", c.score()).execute() + assert c.pre.style.footer_odd_even + assert not c.post.style.footer_odd_even + + def test_option_footer(self) -> None: + s = Cli("--footer", "l", "c", "r").score() + assert s.style.show_footer + assert s.style.odd_footer_left == "l" + assert s.style.even_footer_left == "l" + assert s.style.odd_footer_center == "c" + assert s.style.even_footer_center == "c" + assert s.style.odd_footer_right == "r" + assert s.style.even_footer_right == "r" + + def test_option_footer_odd_even(self) -> None: + s = Cli("--footer-odd-even", "ol", "el", "oc", "ec", "or", "er").score() + assert s.style.show_footer + assert s.style.odd_footer_left == "ol" + assert s.style.even_footer_left == "el" + assert s.style.odd_footer_center == "oc" + assert s.style.even_footer_center == "ec" + assert s.style.odd_footer_right == "or" + assert s.style.even_footer_right == "er" + class TestProperties: def test_measure_number_offset(self, score: Score) -> None: