lib

The lib module contains a number of library functions and classes used in the Songs plugin.

class openlp.plugins.songs.lib.VerseType[source]

Bases: object

VerseType provides an enumeration for the tags that may be associated with verses in songs.

Bridge = 2
Chorus = 1
Ending = 5
Intro = 4
Other = 6
PreChorus = 3
Verse = 0
static from_loose_input(verse_name, default=6)[source]

Return the VerseType for a given string

Parameters:
  • verse_name – The string to return a VerseType for
  • default – Default return value if no matching tag is found
Returns:

A VerseType

static from_string(verse_name, default=6)[source]

Return the VerseType for a given string

Parameters:
  • verse_name – The string to return a VerseType for
  • default – Default return value if no matching tag is found
Returns:

The VerseType determined from the string

static from_tag(verse_tag, default=6)[source]

Return the VerseType for a given tag

Parameters:
  • verse_tag – The string to return a VerseType for
  • default – Default return value if no matching tag is found (a valid VerseType or None)
Returns:

A VerseType of the tag

static from_translated_string(verse_name)[source]

Return the VerseType for a given string

Parameters:verse_name – The string to return a VerseType for
Returns:A VerseType
static from_translated_tag(verse_tag, default=6)[source]

Return the VerseType for a given tag

Parameters:
  • verse_tag – The string to return a VerseType for
  • default – Default return value if no matching tag is found
Returns:

The VerseType of a translated tag

names = ['Verse', 'Chorus', 'Bridge', 'Pre-Chorus', 'Intro', 'Ending', 'Other']
tags = ['v', 'c', 'b', 'p', 'i', 'e', 'o']
static translated_name(verse_tag, default=6)[source]

Return the translated name for a given tag

Parameters:
  • verse_tag – The string to return a VerseType for
  • default – Default return value if no matching tag is found
Returns:

Translated name for the given tag

translated_names = ['Verse', 'Chorus', 'Bridge', 'Pre-Chorus', 'Intro', 'Ending', 'Other']
static translated_tag(verse_tag, default=6)[source]

Return the translated UPPERCASE tag for a given tag, used to show translated verse tags in UI

Parameters:
  • verse_tag – The string to return a VerseType for
  • default – Default return value if no matching tag is found
Returns:

A translated UPPERCASE tag

translated_tags = ['v', 'c', 'b', 'p', 'i', 'e', 'o']
openlp.plugins.songs.lib.clean_song(manager, song)[source]

Cleans the search title, rebuilds the search lyrics, adds a default author if the song does not have one and other clean ups. This should always called when a new song is added or changed.

Parameters:
  • manager – The song database manager object.
  • song – The song object.
openlp.plugins.songs.lib.clean_string(string)[source]

Strips punctuation from the passed string to assist searching.

Parameters:string – The string to clean
Returns:A clean string
openlp.plugins.songs.lib.clean_title(title)[source]

Cleans the song title by removing Unicode control chars groups C0 & C1, as well as any trailing spaces.

Parameters:title – The song title to clean
Returns:A clean title
openlp.plugins.songs.lib.delete_song(song_id, song_plugin)[source]

Deletes a song from the database. Media files associated to the song are removed prior to the deletion of the song.

Parameters:
  • song_id – The ID of the song to delete.
  • song_plugin – The song plugin instance.
openlp.plugins.songs.lib.get_encoding(font, font_table, default_encoding, failed=False)[source]

Finds an encoding to use. Asks user, if necessary.

Parameters:
  • font – The number of currently active font.
  • font_table – Dictionary of fonts and respective encodings.
  • default_encoding – The default encoding to use when font_table is empty or no font is used.
  • failed – A boolean indicating whether the previous encoding didn’t work.
openlp.plugins.songs.lib.retrieve_windows_encoding(recommendation=None)[source]

Determines which encoding to use on an information source. The process uses both automated detection, which is passed to this method as a recommendation, and user confirmation to return an encoding.

Parameters:recommendation – A recommended encoding discovered programmatically for the user to confirm.
Returns:A list of recommended encodings, or None
openlp.plugins.songs.lib.strip_rtf(text, default_encoding=None)[source]

This function strips RTF control structures and returns an unicode string.

Thanks to Markus Jarderot (MizardX) for this code, used by permission. http://stackoverflow.com/questions/188545

Parameters:
  • text – RTF-encoded text, a string.
  • default_encoding – Default encoding to use when no encoding is specified.
Returns:

A tuple (text, encoding) where text is the clean text and encoding is the detected encoding

openlp.plugins.songs.lib.transpose_chord(chord, transpose_value, notation)[source]

Transpose chord according to the notation used. NOTE: This function has a javascript equivalent in chords.js - make sure to update both!

Parameters:
  • chord – The chord to transpose.
  • transpose_value – The value the chord should be transposed.
  • notation – The notation to use when transposing.
Returns:

The transposed chord.

openlp.plugins.songs.lib.transpose_lyrics(lyrics, transepose_value)[source]

Transepose lyrics

Parameters:
  • lyrcs – The lyrics to be transposed
  • transepose_value – The value to transpose the lyrics with
Returns:

The transposed lyrics

openlp.plugins.songs.lib.transpose_verse(verse_text, transepose_value, notation)[source]

Transepose lyrics

Parameters:
  • lyrcs – The lyrics to be transposed
  • transepose_value – The value to transpose the lyrics with
Returns:

The transposed lyrics