common

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

class openlp.core.common.SlideLimits[source]

Bases: object

Provides an enumeration for behaviour of OpenLP at the end limits of each service item when pressing the up/down arrow keys

End = 1
Next = 3
Wrap = 2
class openlp.core.common.ThemeLevel[source]

Bases: object

Provides an enumeration for the level a theme applies to

Global = 1
Service = 2
Song = 3
openlp.core.common.add_actions(target, actions)[source]

Adds multiple actions to a menu or toolbar in one command.

Parameters:
  • target – The menu or toolbar to add actions to
  • actions – The actions to be added. An action consisting of the keyword None will result in a separator being inserted into the target.
openlp.core.common.check_binary_exists(program_path)[source]

Function that checks whether a binary exists.

Parameters:program_path – The full path to the binary to check.
Returns:program output to be parsed
openlp.core.common.check_directory_exists(directory, do_not_log=False)[source]

Check a theme directory exists and if not create it

Parameters:
  • directory – The directory to make sure exists
  • do_not_log – To not log anything. This is need for the start up, when the log isn’t ready.
openlp.core.common.clean_button_text(button_text)[source]

Clean the & and other characters out of button text

Parameters:button_text – The text to clean
openlp.core.common.clean_filename(filename)[source]

Removes invalid characters from the given filename.

Parameters:filename – The “dirty” file name to clean.
openlp.core.common.de_hump(name)[source]

Change any Camel Case string to python string

openlp.core.common.delete_file(file_path_name)[source]

Deletes a file from the system.

Parameters:file_path_name – The file, including path, to delete.
openlp.core.common.extension_loader(glob_pattern, excluded_files=[])[source]

A utility function to find and load OpenLP extensions, such as plugins, presentation and media controllers and importers.

Parameters:
  • glob_pattern (str) – A glob pattern used to find the extension(s) to be imported. Should be relative to the application directory. i.e. openlp/plugins/*/*plugin.py
  • excluded_files (list of strings) – A list of file names to exclude that the glob pattern may find.
Returns:

None

Return type:

None

openlp.core.common.get_file_encoding(filename)[source]

Utility function to incrementally detect the file encoding.

Parameters:filename – Filename for the file to determine the encoding for. Str
Returns:A dict with the keys ‘encoding’ and ‘confidence’
openlp.core.common.get_filesystem_encoding()[source]

Returns the name of the encoding used to convert Unicode filenames into system file names.

openlp.core.common.get_frozen_path(frozen_option, non_frozen_option)[source]

Return a path based on the system status.

Parameters:
  • frozen_option
  • non_frozen_option
openlp.core.common.get_images_filter()[source]

Returns a filter string for a file dialog containing all the supported image formats.

openlp.core.common.get_uno_command(connection_type='pipe')[source]

Returns the UNO command to launch an libreoffice.org instance.

openlp.core.common.get_uno_instance(resolver, connection_type='pipe')[source]

Returns a running libreoffice.org instance.

Parameters:resolver – The UNO resolver to use to find a running instance.
openlp.core.common.is_linux()[source]

Returns true if running on a system with a linux kernel e.g. Ubuntu, Debian, etc

Returns:True if system is running a linux kernel false otherwise
openlp.core.common.is_macosx()[source]

Returns true if running on a system with a darwin kernel e.g. Mac OS X

Returns:True if system is running a darwin kernel false otherwise
openlp.core.common.is_not_image_file(file_name)[source]

Validate that the file is not an image file.

Parameters:file_name – File name to be checked.
openlp.core.common.is_win()[source]

Returns true if running on a system with a nt kernel e.g. Windows, Wine

Returns:True if system is running a nt kernel false otherwise
openlp.core.common.md5_hash(salt=None, data=None)[source]

Returns the hashed output of md5sum on salt,data using Python3 hashlib

Parameters:
  • salt – Initial salt
  • data – OPTIONAL Data to hash
Returns:

str

openlp.core.common.path_to_module(path)[source]

Convert a path to a module name (i.e openlp.core.common)

Parameters:path (Path) – The path to convert to a module name.
Returns:The module name.
Return type:str
openlp.core.common.qmd5_hash(salt=None, data=None)[source]

Returns the hashed output of MD5Sum on salt, data using PyQt5.QCryptographicHash. Function returns a QByteArray instead of a text string. If you need a string instead, call with

result = str(qmd5_hash(salt=..., data=...), encoding=’ascii’)
Parameters:
  • salt – Initial salt
  • data – OPTIONAL Data to hash
Returns:

QByteArray

openlp.core.common.split_filename(path)[source]

Return a list of the parts in a given path.

openlp.core.common.trace_error_handler(logger)[source]

Log the calling path of an exception

Parameters:logger – logger to use so traceback is logged to correct class
openlp.core.common.translate(context, text, comment=None, qt_translate=<built-in function translate>)[source]

A special shortcut method to wrap around the Qt5 translation functions. This abstracts the translation procedure so that we can change it if at a later date if necessary, without having to redo the whole of OpenLP.

Parameters:
  • context – The translation context, used to give each string a context or a namespace.
  • text – The text to put into the translation tables for translation.
  • comment – An identifying string for when the same text is used in different roles within the same context.
  • qt_translate
openlp.core.common.verify_ip_address(addr)[source]

Validate an IP address as either IPv4 or IPv6

Parameters:addr – Address to validate
Returns:bool
openlp.core.common.verify_ipv4(addr)[source]

Validate an IPv4 address

Parameters:addr – Address to validate
Returns:bool
openlp.core.common.verify_ipv6(addr)[source]

Validate an IPv6 address

Parameters:addr – Address to validate
Returns:bool