2010-12-23 17:42:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-04-13 13:00:22 +00:00
|
|
|
##########################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# ---------------------------------------------------------------------- #
|
2020-12-30 21:42:49 +00:00
|
|
|
# Copyright (c) 2008-2021 OpenLP Developers #
|
2019-04-13 13:00:22 +00:00
|
|
|
# ---------------------------------------------------------------------- #
|
|
|
|
# This program is free software: you can redistribute it and/or modify #
|
|
|
|
# it under the terms of the GNU General Public License as published by #
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or #
|
|
|
|
# (at your option) any later version. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, #
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
|
|
|
# GNU General Public License for more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License #
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
|
|
|
|
##########################################################################
|
2010-12-23 17:42:28 +00:00
|
|
|
"""
|
2011-07-30 07:19:16 +00:00
|
|
|
Provide HTML Tag management and Formatting Tag access class
|
2010-12-23 17:42:28 +00:00
|
|
|
"""
|
2013-06-24 16:21:46 +00:00
|
|
|
import json
|
2011-08-27 14:00:24 +00:00
|
|
|
|
2017-10-07 07:05:07 +00:00
|
|
|
from openlp.core.common.i18n import translate
|
2020-02-01 21:12:07 +00:00
|
|
|
from openlp.core.common.registry import Registry
|
2010-12-23 17:42:28 +00:00
|
|
|
|
2013-02-01 19:58:18 +00:00
|
|
|
|
2011-07-30 07:34:37 +00:00
|
|
|
class FormattingTags(object):
|
2010-12-23 17:42:28 +00:00
|
|
|
"""
|
2013-08-31 17:20:43 +00:00
|
|
|
Static Class for HTML Tags to be access around the code the list is managed by the Options Tab.
|
2010-12-23 17:42:28 +00:00
|
|
|
"""
|
2011-01-09 08:17:17 +00:00
|
|
|
html_expands = []
|
2010-12-23 17:42:28 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_html_tags():
|
|
|
|
"""
|
2010-12-31 08:34:53 +00:00
|
|
|
Provide access to the html_expands list.
|
2010-12-23 17:42:28 +00:00
|
|
|
"""
|
2011-07-30 07:34:37 +00:00
|
|
|
return FormattingTags.html_expands
|
2010-12-31 08:34:53 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2013-09-01 20:43:22 +00:00
|
|
|
def save_html_tags(new_tags):
|
2010-12-31 08:34:53 +00:00
|
|
|
"""
|
2013-09-11 19:00:30 +00:00
|
|
|
Saves all formatting tags except protected ones
|
|
|
|
|
|
|
|
`new_tags`
|
|
|
|
The tags to be saved..
|
2012-05-05 16:03:40 +00:00
|
|
|
"""
|
|
|
|
# Formatting Tags were also known as display tags.
|
2020-02-01 21:12:07 +00:00
|
|
|
Registry().get('settings').setValue('formattingTags/html_tags', json.dumps(new_tags) if new_tags else '')
|
2012-05-05 16:03:40 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def load_tags():
|
|
|
|
"""
|
2013-02-14 14:54:45 +00:00
|
|
|
Load the Tags from store so can be used in the system or used to update the display.
|
2010-12-31 08:34:53 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
temporary_tags = [tag for tag in FormattingTags.html_expands if tag.get('temporary')]
|
2011-07-30 07:34:37 +00:00
|
|
|
FormattingTags.html_expands = []
|
2019-07-03 13:23:23 +00:00
|
|
|
base_tags = [
|
|
|
|
{
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Red'),
|
|
|
|
'start tag': '{r}',
|
|
|
|
'start html': '<span style="-webkit-text-fill-color:red">',
|
|
|
|
'end tag': '{/r}', 'end html': '</span>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Black'),
|
|
|
|
'start tag': '{b}',
|
|
|
|
'start html': '<span style="-webkit-text-fill-color:black">',
|
|
|
|
'end tag': '{/b}', 'end html': '</span>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Blue'),
|
|
|
|
'start tag': '{bl}',
|
|
|
|
'start html': '<span style="-webkit-text-fill-color:blue">',
|
|
|
|
'end tag': '{/bl}', 'end html': '</span>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Yellow'),
|
|
|
|
'start tag': '{y}',
|
|
|
|
'start html': '<span style="-webkit-text-fill-color:yellow">',
|
|
|
|
'end tag': '{/y}', 'end html': '</span>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Green'),
|
|
|
|
'start tag': '{g}',
|
|
|
|
'start html': '<span style="-webkit-text-fill-color:green">',
|
|
|
|
'end tag': '{/g}', 'end html': '</span>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Pink'),
|
|
|
|
'start tag': '{pk}',
|
|
|
|
'start html': '<span style="-webkit-text-fill-color:#FFC0CB">',
|
|
|
|
'end tag': '{/pk}', 'end html': '</span>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Orange'),
|
|
|
|
'start tag': '{o}',
|
|
|
|
'start html': '<span style="-webkit-text-fill-color:#FFA500">',
|
|
|
|
'end tag': '{/o}', 'end html': '</span>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Purple'),
|
|
|
|
'start tag': '{pp}',
|
|
|
|
'start html': '<span style="-webkit-text-fill-color:#800080">',
|
|
|
|
'end tag': '{/pp}', 'end html': '</span>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'White'),
|
|
|
|
'start tag': '{w}',
|
|
|
|
'start html': '<span style="-webkit-text-fill-color:white">',
|
|
|
|
'end tag': '{/w}', 'end html': '</span>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Superscript'),
|
|
|
|
'start tag': '{su}', 'start html': '<sup>',
|
|
|
|
'end tag': '{/su}', 'end html': '</sup>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Subscript'),
|
|
|
|
'start tag': '{sb}', 'start html': '<sub>',
|
|
|
|
'end tag': '{/sb}', 'end html': '</sub>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Paragraph'),
|
|
|
|
'start tag': '{p}', 'start html': '<p>', 'end tag': '{/p}',
|
|
|
|
'end html': '</p>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Bold'),
|
|
|
|
'start tag': '{st}', 'start html': '<strong>',
|
|
|
|
'end tag': '{/st}', 'end html': '</strong>',
|
|
|
|
'protected': True, 'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Italics'),
|
|
|
|
'start tag': '{it}', 'start html': '<em>', 'end tag': '{/it}',
|
|
|
|
'end html': '</em>', 'protected': True, 'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Underline'),
|
|
|
|
'start tag': '{u}',
|
|
|
|
'start html': '<span style="text-decoration: underline;">',
|
|
|
|
'end tag': '{/u}', 'end html': '</span>', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}, {
|
|
|
|
'desc': translate('OpenLP.FormattingTags', 'Break'),
|
|
|
|
'start tag': '{br}', 'start html': '<br>', 'end tag': '',
|
|
|
|
'end html': '', 'protected': True,
|
|
|
|
'temporary': False
|
|
|
|
}]
|
2011-05-26 06:45:22 +00:00
|
|
|
# Append the base tags.
|
2011-07-30 07:34:37 +00:00
|
|
|
FormattingTags.add_html_tags(base_tags)
|
2011-08-26 15:06:22 +00:00
|
|
|
FormattingTags.add_html_tags(temporary_tags)
|
2020-02-01 21:12:07 +00:00
|
|
|
user_expands_string = str(Registry().get('settings').value('formattingTags/html_tags'))
|
2013-07-03 17:10:37 +00:00
|
|
|
# If we have some user ones added them as well
|
2011-09-22 14:23:51 +00:00
|
|
|
if user_expands_string:
|
2013-06-30 05:30:42 +00:00
|
|
|
user_tags = json.loads(user_expands_string)
|
2011-09-22 14:23:51 +00:00
|
|
|
FormattingTags.add_html_tags(user_tags)
|
|
|
|
|
2011-08-27 14:00:24 +00:00
|
|
|
@staticmethod
|
2012-05-05 16:03:40 +00:00
|
|
|
def add_html_tags(tags):
|
2010-12-31 08:34:53 +00:00
|
|
|
"""
|
2011-08-26 14:27:53 +00:00
|
|
|
Add a list of tags to the list.
|
|
|
|
|
2014-03-17 19:05:55 +00:00
|
|
|
:param tags: The list with tags to add.
|
2015-09-08 19:13:59 +00:00
|
|
|
Each **tag** has to be a ``dict`` and should have the following keys:
|
2011-08-26 14:27:53 +00:00
|
|
|
|
2015-09-08 19:13:59 +00:00
|
|
|
* desc
|
|
|
|
The formatting tag's description, e. g. **Red**
|
2011-08-26 14:27:53 +00:00
|
|
|
|
2015-09-08 19:13:59 +00:00
|
|
|
* start tag
|
|
|
|
The start tag, e. g. ``{r}``
|
2011-08-26 14:27:53 +00:00
|
|
|
|
2015-09-08 19:13:59 +00:00
|
|
|
* end tag
|
|
|
|
The end tag, e. g. ``{/r}``
|
2011-08-26 14:27:53 +00:00
|
|
|
|
2015-09-08 19:13:59 +00:00
|
|
|
* start html
|
|
|
|
The start html tag. For instance ``<span style="-webkit-text-fill-color:red">``
|
2011-08-26 14:27:53 +00:00
|
|
|
|
2015-09-08 19:13:59 +00:00
|
|
|
* end html
|
|
|
|
The end html tag. For example ``</span>``
|
2011-08-26 14:27:53 +00:00
|
|
|
|
2015-09-08 19:13:59 +00:00
|
|
|
* protected
|
|
|
|
A boolean stating whether this is a build-in tag or not. Should be ``True`` in most cases.
|
2011-08-26 14:27:53 +00:00
|
|
|
|
2015-09-08 19:13:59 +00:00
|
|
|
* temporary
|
2015-09-10 20:35:14 +00:00
|
|
|
A temporary tag will not be saved, but is also considered when displaying text containing the tag. It
|
|
|
|
has to be a ``boolean``.
|
2010-12-31 08:34:53 +00:00
|
|
|
"""
|
2011-07-30 07:34:37 +00:00
|
|
|
FormattingTags.html_expands.extend(tags)
|
2010-12-31 08:34:53 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2011-02-07 22:07:48 +00:00
|
|
|
def remove_html_tag(tag_id):
|
2010-12-31 08:34:53 +00:00
|
|
|
"""
|
2011-02-07 22:07:48 +00:00
|
|
|
Removes an individual html_expands tag.
|
2010-12-31 08:34:53 +00:00
|
|
|
"""
|
2011-07-30 07:34:37 +00:00
|
|
|
FormattingTags.html_expands.pop(tag_id)
|