lib

The lib module contains most of the components and libraries that make OpenLP work.

class openlp.core.lib.ImageSource[source]

Bases: object

This enumeration class represents different image sources. An image sources states where an image is used. This enumeration class is need in the context of the :class:~openlp.core.lib.imagemanager`.

ImagePlugin
This states that an image is being used by the image plugin.
Theme
This says, that the image is used by a theme.
CommandPlugins
This states that an image is being used by a command plugin.
CommandPlugins = 3
ImagePlugin = 1
Theme = 2
class openlp.core.lib.MediaType[source]

Bases: object

An enumeration class for types of media.

Audio = 1
Video = 2
class openlp.core.lib.ServiceItemAction[source]

Bases: object

Provides an enumeration for the required action moving between service items by left/right arrow keys

Next = 3
Previous = 1
PreviousLastSlide = 2
class openlp.core.lib.ServiceItemContext[source]

Bases: object

The context in which a Service Item is being generated

Live = 1
Preview = 0
Service = 2
openlp.core.lib.build_icon(icon)[source]

Build a QIcon instance from an existing QIcon, a resource location, or a physical file location. If the icon is a QIcon instance, that icon is simply returned. If not, it builds a QIcon instance from the resource or file name.

Parameters:icon – The icon to build. This can be a QIcon, a resource string in the form :/resource/file.png, or a file location like /path/to/file.png. However, the recommended way is to specify a resource string.
Returns:The build icon.
openlp.core.lib.check_item_selected(list_widget, message)[source]

Check if a list item is selected so an action may be performed on it

Parameters:
  • list_widget – The list to check for selected items
  • message – The message to give the user if no item is selected
openlp.core.lib.clean_tags(text, remove_chords=False)[source]

Remove Tags from text for display

Parameters:
  • text – Text to be cleaned
  • remove_chords – Clean ChordPro tags
openlp.core.lib.compare_chord_lyric(chord, lyric)[source]

Compare the width of chord and lyrics. If chord width is greater than the lyric width the diff is returned.

Parameters:
  • chord
  • lyric
Returns:

openlp.core.lib.create_separated_list(string_list)[source]

Returns a string that represents a join of a list of strings with a localized separator. Localized separation will be done via the translate() function by the translators.

Parameters:string_list – List of unicode strings
Returns:Formatted string
openlp.core.lib.create_thumb(image_path, thumb_path, return_icon=True, size=None)[source]

Create a thumbnail from the given image path and depending on return_icon it returns an icon from this thumb.

Parameters:
  • image_path – The image file to create the icon from.
  • thumb_path – The filename to save the thumbnail to.
  • return_icon – States if an icon should be build and returned from the thumb. Defaults to True.
  • size – Allows to state a own size (QtCore.QSize) to use. Defaults to None, which means that a default height of 88 is used.
Returns:

The final icon.

openlp.core.lib.expand_and_align_chords_in_line(match)[source]

Expand the chords in the line and align them using whitespaces. NOTE: There is equivalent javascript code in chords.js, in the updateSlide function. Make sure to update both!

Parameters:match
Returns:The line with expanded html-chords
openlp.core.lib.expand_chords(text)[source]

Expand ChordPro tags

Parameters:text
openlp.core.lib.expand_chords_for_printing(text, line_split)[source]

Expand ChordPro tags

Parameters:
  • text
  • line_split
openlp.core.lib.expand_tags(text, expand_chord_tags=False, for_printing=False)[source]

Expand tags HTML for display

Parameters:text – The text to be expanded.
openlp.core.lib.find_formatting_tags(text, active_formatting_tags)[source]

Look for formatting tags in lyrics and adds/removes them to/from the given list. Returns the update list.

Parameters:
  • text
  • active_formatting_tags
Returns:

openlp.core.lib.get_text_file_string(text_file)[source]

Open a file and return its content as unicode string. If the supplied file name is not a file then the function returns False. If there is an error loading the file or the content can’t be decoded then the function will return None.

Parameters:text_file – The name of the file.
Returns:The file as a single string
openlp.core.lib.image_to_byte(image, base_64=True)[source]

Resize an image to fit on the current screen for the web and returns it as a byte stream.

Parameters:
  • image – The image to converted.
  • base_64 – If True returns the image as Base64 bytes, otherwise the image is returned as a byte array. To preserve original intention, this defaults to True
openlp.core.lib.resize_image(image_path, width, height, background='#000000')[source]

Resize an image to fit on the current screen.

DO NOT REMOVE THE DEFAULT BACKGROUND VALUE!

Parameters:
  • image_path – The path to the image to resize.
  • width – The new image width.
  • height – The new image height.
  • background – The background colour. Defaults to black.
openlp.core.lib.str_to_bool(string_value)[source]

Convert a string version of a boolean into a real boolean.

Parameters:string_value – The string value to examine and convert to a boolean type.
Returns:The correct boolean value
openlp.core.lib.validate_thumb(file_path, thumb_path)[source]

Validates whether an file’s thumb still exists and if is up to date. Note, you must not call this function, before checking the existence of the file.

Parameters:
  • file_path – The path to the file. The file must exist!
  • thumb_path – The path to the thumb.
Returns:

True, False if the image has changed since the thumb was created.