utils

The openlp.core.utils module provides the utility libraries for OpenLP.

class openlp.core.utils.ActionList

Bases: builtins.object

The ActionList class contains a list of menu actions and categories associated with those actions. Each category also has a weight by which it is sorted when iterating through the list of actions or categories.

add_action(action, category=None, weight=None)

Add an action to the list of actions.

Note: The action’s objectName must be set when you want to add it!

Parameters:
  • action – The action to add (QAction). Note, the action must not have an empty objectName.
  • category – The category this action belongs to. The category has to be a python string. . Note, if the category is None, the category and its actions are being hidden in the shortcut dialog. However, if they are added, it is possible to avoid assigning shortcuts twice, which is important.
  • weight – The weight specifies how important a category is. However, this only has an impact on the order the categories are displayed.
add_category(name, weight)

Add an empty category to the list of categories. This is only convenient for categories with a given weight.

Parameters:
  • name – The category’s name.
  • weight – The category’s weight (int).
get_all_child_objects(qobject)

Goes recursively through the children of qobject and returns a list of all child objects.

static get_instance()

Get the instance of this class.

instance = None
remove_action(action, category=None)

This removes an action from its category. Empty categories are automatically removed.

Parameters:
  • action – The QAction object to be removed.
  • category – The name (unicode string) of the category, which contains the action. Defaults to None.
shortcut_map = {}
update_shortcut_map(action, old_shortcuts)

Remove the action for the given old_shortcuts from the shortcut_map to ensure its up-to-dateness. Note: The new action’s shortcuts must be assigned to the given action before calling this method.

Parameters:
  • action – The action whose shortcuts are supposed to be updated in the shortcut_map.
  • old_shortcuts – A list of unicode key sequences.
class openlp.core.utils.LanguageManager

Bases: builtins.object

Helper for Language selection

auto_language = False
static find_qm_files()

Find all available language files in this OpenLP install

static get_language()

Retrieve a saved language to use from settings

static get_qm_list()

Return the list of available translations

static get_translator(language)

Set up a translator to use in this instance of OpenLP

Parameters:language – The language to load into the translator
static init_qm_list()

Initialise the list of available translations

static language_name(qm_file)

Load the language name from a language file

Parameters:qm_file – The file to obtain the name from
static set_language(action, message=True)

Set the language to translate OpenLP into

Parameters:
  • action – The language menu option
  • message – Display the message option
openlp.core.utils.get_application_version()[source]

Returns the application version of the running instance of OpenLP:

{'full': '1.9.4-bzr1249', 'version': '1.9.4', 'build': 'bzr1249'}
openlp.core.utils.check_latest_version(current_version)[source]

Check the latest version of OpenLP against the version file on the OpenLP site.

Rules around versions and version files:

  • If a version number has a build (i.e. -bzr1234), then it is a nightly.
  • If a version number’s minor version is an odd number, it is a development release.
  • If a version number’s minor version is an even number, it is a stable release.
Parameters:current_version – The current version of OpenLP.
openlp.core.utils.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.utils.get_filesystem_encoding()[source]

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

openlp.core.utils.get_web_page(url, header=None, update_openlp=False)[source]

Attempts to download the webpage at url and returns that page or None.

Parameters:
  • url – The URL to be downloaded.
  • header – An optional HTTP header to pass in the request to the web server.
  • update_openlp – Tells OpenLP to update itself if the page is successfully downloaded. Defaults to False.
openlp.core.utils.get_uno_command(connection_type='pipe')[source]

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

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

Returns a running openoffice.org instance.

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

Deletes a file from the system.

Parameters:file_path_name – The file, including path, to delete.
openlp.core.utils.clean_filename(filename)[source]

Removes invalid characters from the given filename.

Parameters:filename – The “dirty” file name to clean.
openlp.core.utils.format_time(text, local_time)[source]

Workaround for Python built-in time formatting function time.strftime().

time.strftime() accepts only ascii characters. This function accepts unicode string and passes individual % placeholders to time.strftime(). This ensures only ascii characters are passed to time.strftime().

Parameters:
  • text – The text to be processed.
  • local_time – The time to be used to add to the string. This is a time object
openlp.core.utils.get_locale_key(string)[source]

Creates a key for case insensitive, locale aware string sorting.

Parameters:string – The corresponding string.
openlp.core.utils.get_natural_key(string)[source]

Generate a key for locale aware natural string sorting. Returns a list of string compare keys and integers.