Submodule style

mscxyz.style.mm(value: str | float) float[source]
mscxyz.style.inch(value: str | float) float[source]
mscxyz.style.musical_symbol_font_faces

Musical symbol font faces

See:

MuseScore C++ source code: engravingmodule.cpp lines 120-127

mscxyz.style.musical_text_font_faces

Musical text font faces

See:

MuseScore C++ source code: editstyle.cpp lines 1966-1973

class mscxyz.style.Offset

Bases: dict

x: float | str
y: float | str
class mscxyz.style.Margin(even_top: 'float', odd_top: 'float', even_right: 'float', odd_right: 'float', even_bottom: 'float', odd_bottom: 'float', even_left: 'float', odd_left: 'float')[source]

Bases: object

even_top: float
odd_top: float
even_right: float
odd_right: float
even_bottom: float
odd_bottom: float
even_left: float
odd_left: float
class mscxyz.style.Style(score: Score)[source]

Bases: object

Interface specialized for the style manipulation.

Parameters:

relpath – The relative (or absolute) path of a MuseScore file.

v3: https://github.com/musescore/MuseScore/blob/4566605d92467b0f5a36b3731b64150500e48583/libmscore/style.cpp

v4: https://github.com/musescore/MuseScore/blob/e0f941733ac2c0959203a5e99252eb4c58f67606/src/engraving/style/styledef.cpp

property xml: XmlManipulator
score: Score
parent_element: _Element

The parent /museScore/Score/Style element that contains all style tags.

property styles: list[_Element]

Return all style elements (all XML elements inside the <Style>) as a list.

Returns:

A list of all style elements.

get_element(element_path: str) _Element[source]

Determines an lxml element that is a child to the Style tag

Parameters:

Example code:

# Set attributes on a maybe non-existent style tag.
# <measureNumberOffset x="0.5" y="-2"/>
test = Style('text.mscx')
element = test.get_element('measureNumberOffset')
element.attrib['x'] = '0.5'
element.attrib['y'] = '-2'
test.save()
clean() None[source]

Remove the style, the layout breaks, the stem directions and the font, b, i, pos, offset tags

get(style_name: str, raise_exception: bool = True) str | None[source]

Get a style value by its style name (element path) of a style tag.

Parameters:

style_name – see http://lxml.de/tutorial.html#elementpath

set_attributes(style_name: str, attributes: dict[str, str | int | float]) _Element[source]

Set attributes on a style child tag.

Parameters:

element_path – see http://lxml.de/tutorial.html#elementpath

set(style_name: str | Sequence[str], value: str | int | float | dict[str, str | int | float] | None) list[tuple[str, str | int | float | dict[str, str | int | float] | None, str | int | float | dict[str, str | int | float] | None]][source]

Sets the value of an XML element identified by the given element path.

Parameters:
  • style_name – A style name or multiple style names as a list or a element path expression. For more information, refer to http://lxml.de/tutorial.html#elementpath

  • value – The value to be set for the XML element. It can be a string, integer, or float.

get_text_style(name: str) dict[str, str][source]

Get text styles as a dictonary. Only MuseScore2!

<Style>
    <TextStyle>
        <halign>center</halign>
        <valign>top</valign>
        <offsetType>absolute</offsetType>
        <name>Title</name>
        <family>MuseJazz</family>
        <size>28</size>
        <bold>1</bold>
    </TextStyle>
</Style>
{
    "halign": "center",
    "size": "28",
    "family": "MuseJazz",
    "bold": "1",
    "valign": "top",
    "name": "Title",
    "offsetType": "absolute",
}
Parameters:

name – The name of the text style, for example Title, Subtitle, Lyricist, Fingering, String Number, Dynamics etc.

set_text_style(name: str, values: dict[str, str | int | float]) None[source]

Set text styles. Only MuseScore2!

Parameters:
  • name – The name of the text style, for example Title, Subtitle, Lyricist, Fingering, String Number, Dynamics etc.

  • values – A dictionary. The keys are the tag names, values are the text values of the child tags, for example {size: 14, bold: 1}.

get_all_fonts() list[tuple[str, str]][source]

Returns a list of tuples containing the tag name and the font face.

print_all_font_faces() None[source]
set_text_fonts(new_font_face: str) list[tuple[str, str | int | float | dict[str, str | int | float] | None, str | int | float | dict[str, str | int | float] | None]][source]

Set the font face for nearly all font face related styles except for romanNumeralFontFace, figuredBassFontFace, dynamicsFontFace, musicalSymbolFont and musicalTextFont.

Default values in v3 and v4:

  • lyricsOddFontFace: Edwin

  • lyricsEvenFontFace: Edwin

  • hairpinFontFace: Edwin

  • pedalFontFace: Edwin

  • chordSymbolAFontFace: Edwin

  • chordSymbolBFontFace: Edwin

  • romanNumeralFontFace: Campania

  • nashvilleNumberFontFace: Edwin

  • voltaFontFace: Edwin

  • ottavaFontFace: Edwin

  • tupletFontFace: Edwin

  • defaultFontFace: Edwin

  • titleFontFace: Edwin

  • subTitleFontFace: Edwin

  • composerFontFace: Edwin

  • lyricistFontFace: Edwin

  • fingeringFontFace: Edwin

  • lhGuitarFingeringFontFace: Edwin

  • rhGuitarFingeringFontFace: Edwin

  • stringNumberFontFace: Edwin

  • harpPedalDiagramFontFace: Edwin

  • harpPedalTextDiagramFontFace: Edwin

  • longInstrumentFontFace: Edwin

  • shortInstrumentFontFace: Edwin

  • partInstrumentFontFace: Edwin

  • dynamicsFontFace: Edwin

  • expressionFontFace: Edwin

  • tempoFontFace: Edwin

  • tempoChangeFontFace: Edwin

  • metronomeFontFace: Edwin

  • measureNumberFontFace: Edwin

  • mmRestRangeFontFace: Edwin

  • translatorFontFace: Edwin

  • systemFontFace: Edwin

  • staffFontFace: Edwin

  • rehearsalMarkFontFace: Edwin

  • repeatLeftFontFace: Edwin

  • repeatRightFontFace: Edwin

  • frameFontFace: Edwin

  • textLineFontFace: Edwin

  • systemTextLineFontFace: Edwin

  • glissandoFontFace: Edwin

  • bendFontFace: Edwin

  • headerFontFace: Edwin

  • footerFontFace: Edwin

  • instrumentChangeFontFace: Edwin

  • stickingFontFace: Edwin

  • figuredBassFontFace: MScoreBC

  • user1FontFace: Edwin

  • user2FontFace: Edwin

  • user3FontFace: Edwin

  • user4FontFace: Edwin

  • user5FontFace: Edwin

  • user6FontFace: Edwin

  • user7FontFace: Edwin

  • user8FontFace: Edwin

  • user9FontFace: Edwin

  • user10FontFace: Edwin

  • user11FontFace: Edwin

  • user12FontFace: Edwin

  • letRingFontFace: Edwin

  • palmMuteFontFace: Edwin

Parameters:

font_face – The new font face to be set.

Returns:

A list of tuples representing the changes made. Each tuple contains the tag name, the old font face, and the new font face.

set_title_fonts(font_face: str) list[tuple[str, str | int | float | dict[str, str | int | float] | None, str | int | float | dict[str, str | int | float] | None]][source]
property musical_symbol_font: str | None

v3

<musicalSymbolFont>Leland</musicalSymbolFont>
<dynamicsFontFace>Leland</dynamicsFontFace>

v4 // OBSOLETE after version 4.1. Dynamic text now takes its setting from expression.

<musicalSymbolFont>Leland</musicalSymbolFont>
<dynamicsFont>Leland</dynamicsFont>
property musical_text_font: str | None
<musicalTextFont>Leland Text</musicalTextFont>
load_styles_as_string(styles: str) None[source]

Load styles into the XML tree and replace the old styles.

Parameters:

styles – A string containing the XML style markup.

For example this inputs are valid:

Without declaration:

<pageWidth>8.27</pageWidth>

With declaration:

<?xml version="1.0"?>
<museScore version="2.06">
    <Style>
        <pageWidth>8.27</pageWidth>
load_style_file(file: str | Path | TextIOWrapper) None[source]
reload(save: bool = False) Style[source]

Reload the MuseScore file.

Parameters:

save – Whether to save the changes before reloading. Default is False.

Returns:

The reloaded Style object.

See:

mscxyz.score.Score.reload()

property page_width: float

The page width in inch.

<pageWidth>8.5</pageWidth>
See:

MuseScore C++ source code: styledef.cpp line 43

property page_height: float

The page height in inch.

<pageHeight>11.69</pageHeight>
See:

MuseScore C++ source code: styledef.cpp line 44

set_page_size(width: float | str, height: float | str) None[source]

Set the page size in inch. At the same time, the page_printable_width attribute is set so that the margins do not change.

Parameters:
  • width – The page width in inch as a float or a dimension string in mm or in.

  • height – The page height in inch as a float or a dimension string in mm or in.

See:

page_width

See:

page_height

See:

page_printable_width

Example

score.style.set_page_size("210mm", "297mm")
# or:
score.style.set_page_size(8.2677165354 , 11.6929133858)
set_page_size_a4() None[source]

Set the page size to A4 (210mm x 297mm).

set_page_size_letter() None[source]

Set the page size to Letter (8.5in x 11in).

property page_even_top_margin: float

The top margin of the even pages in inch.

<pageEvenTopMargin>0.393701</pageEvenTopMargin>
See:

MuseScore C++ source code: styledef.cpp line 48

property page_odd_top_margin: float

The top margin of the odd pages in inch.

<pageOddTopMargin>0.393701</pageOddTopMargin>
See:

MuseScore C++ source code: styledef.cpp line 50

property page_even_right_margin: float

The top right of the even pages in inch.

<pageWidth>8.5</pageWidth>
<pagePrintableWidth>7.7126</pagePrintableWidth>
<pageEvenLeftMargin>0.393701</pageEvenLeftMargin>
See:

MuseScore C++ source code: styledef.cpp line 45

property page_odd_right_margin: float

The right margin of the odd pages in inch.

<pageWidth>8.5</pageWidth>
<pagePrintableWidth>7.7126</pagePrintableWidth>
<pageOddLeftMargin>0.393701</pageOddLeftMargin>
See:

MuseScore C++ source code: styledef.cpp line 45

property page_even_bottom_margin: float

The bottom margin of the even pages in inch.

<pageEvenBottomMargin>0.787403</pageEvenBottomMargin>
See:

MuseScore C++ source code: styledef.cpp line 49

property page_odd_bottom_margin: float

The bottom margin of the odd pages in inch.

<pageOddBottomMargin>0.787403</pageOddBottomMargin>
See:

MuseScore C++ source code: styledef.cpp line 51

property page_even_left_margin: float

The left margin of the even pages in inch.

<pageEvenLeftMargin>0.393701</pageEvenLeftMargin>
See:

MuseScore C++ source code: styledef.cpp line 46

property page_odd_left_margin: float

The left margin of the odd pages in inch.

<pageOddLeftMargin>0.393701</pageOddLeftMargin>
See:

MuseScore C++ source code: styledef.cpp line 47

property page_printable_width: float

The printable width of the page in inch. This property is used to calculate the right margin.

<pagePrintableWidth>7.7126</pagePrintableWidth>
See:

MuseScore C++ source code: styledef.cpp line 45

property margin: Margin | float

The margin of a page in inch.

<pagePrintableWidth>7.7126</pagePrintableWidth>
<pageEvenLeftMargin>0.393701</pageEvenLeftMargin>
<pageOddLeftMargin>0.393701</pageOddLeftMargin>
<pageEvenTopMargin>0.393701</pageEvenTopMargin>
<pageEvenBottomMargin>0.787403</pageEvenBottomMargin>
<pageOddTopMargin>0.393701</pageOddTopMargin>
<pageOddBottomMargin>0.787403</pageOddBottomMargin>
See:

MuseScore C++ source code: styledef.cpp lines 46-51

property max_system_distance: float

The maximum system distance in sp (staff space).

<maxSystemDistance>15</maxSystemDistance>
See:

MuseScore C++ source code: styledef.cpp line 61

property show_header: bool

Show the header on the page.

<showHeader>1</showHeader>
See:

MuseScore C++ source code: styledef.cpp line 494

property header_first_page: bool

Show the header on the first page.

<headerFirstPage>1</headerFirstPage>
See:

MuseScore C++ source code: styledef.cpp line 495

property header_odd_even: bool

Use different headers for odd and even pages.

<headerOddEven>1</headerOddEven>
See:

MuseScore C++ source code: styledef.cpp line 496

property even_header_left: str
<evenHeaderL>$p</evenHeaderL>
See:

MuseScore C++ source code: styledef.cpp line 497

property even_header_center: str
<evenHeaderC></evenHeaderC>
See:

MuseScore C++ source code: styledef.cpp line 498

property even_header_right: str
<evenHeaderR></evenHeaderR>
See:

MuseScore C++ source code: styledef.cpp line 499

property odd_header_left: str
<oddHeaderL></oddHeaderL>
See:

MuseScore C++ source code: styledef.cpp line 500

property odd_header_center: str
<oddHeaderC></oddHeaderC>
See:

MuseScore C++ source code: styledef.cpp line 501

property odd_header_right: str
<oddHeaderR>$p</oddHeaderR>
See:

MuseScore C++ source code: styledef.cpp line 502

set_header_all(left: str, center: str, right: str) None[source]

Set the header for all pages.

Parameters:
  • left – The left part of the header.

  • center – The center part of the header.

  • right – The right part of the header.

See:

even_header_left

See:

even_header_center

See:

even_header_right

See:

odd_header_left

See:

odd_header_center

See:

odd_header_right

set_header_odd_even(odd_left: str, even_left: str, odd_center: str, even_center: str, odd_right: str, even_right: str) None[source]

Set different headers for odd and even pages.

See:

even_header_left

See:

even_header_center

See:

even_header_right

See:

odd_header_left

See:

odd_header_center

See:

odd_header_right

Show the footer on the page.

<showFooter>1</showFooter>
See:

MuseScore C++ source code: styledef.cpp line 503

property footer_first_page: bool

Show the footer on the first page.

<footerFirstPage>1</footerFirstPage>
See:

MuseScore C++ source code: styledef.cpp line 505

property footer_odd_even: bool

Use different footers for odd and even pages.

<footerOddEven>1</footerOddEven>
See:

MuseScore C++ source code: styledef.cpp line 506

<evenFooterL></evenFooterL>
See:

MuseScore C++ source code: styledef.cpp line 507

<evenFooterC>$C</evenFooterC>
See:

MuseScore C++ source code: styledef.cpp line 508

<evenFooterR></evenFooterR>
See:

MuseScore C++ source code: styledef.cpp line 509

<oddFooterL></oddFooterL>
See:

MuseScore C++ source code: styledef.cpp line 510

<oddFooterC>$C</oddFooterC>
See:

MuseScore C++ source code: styledef.cpp line 511

<oddFooterR></oddFooterR>
See:

MuseScore C++ source code: styledef.cpp line 512

Set the footer for all pages.

Parameters:
  • left – The left part of the footer.

  • center – The center part of the footer.

  • right – The right part of the footer.

See:

even_footer_left

See:

even_footer_center

See:

even_footer_right

See:

odd_footer_left

See:

odd_footer_center

See:

odd_footer_right

Set the footer for odd and even pages.

See:

even_footer_left

See:

even_footer_center

See:

even_footer_right

See:

odd_footer_left

See:

odd_footer_center

See:

odd_footer_right

property staff_space: float | None

The staff space in mm, default values are 1.750mm = 0.069in

<Spatium>1.74978</Spatium>

styledef.cpp#L640 default 24.8 ???

See:

MuseScore C++ source code: styledef.cpp line 640

property measure_number_offset: Offset
<measureNumberOffset x="0" y="-2"/>
See:

MuseScore C++ source code: styledef.cpp line 1008

reset_small_staffs() None[source]

Reset all small staffs to normal size.

<Part id="1">
    <Staff id="1">
        <StaffType group="pitched">
        <name>stdNormal</name>
        <small>1</small>
        </StaffType>
        </Staff>
    <trackName>Voice</trackName>
    <Instrument id="voice">
        <trackName>Voice</trackName>
        <minPitchP>36</minPitchP>
        <maxPitchP>94</maxPitchP>